Algorithm Reference

Consolidating Data

Introduction

TradeBars vs QuoteBars

The specific consolidator you should use depends on the data and assets you're requesting. TradeBars should be consolidated with a TradeBarConsolidator; QuoteBars with a QuoteBarConsolidator and Ticks with a TickConsolidator. Quote tick data must be consolidated by the TickQuoteBarConsolidator.

For each asset class and the data we provide please see the data library. It is a little confusing but here is the summary of QuantConnect provided data:

  • Equities - trade data only. For Resolution.Tick use the TickConsolidator, for all other resolutions use the TradeBarConsolidator.
  • Forex and CFD - quote data only. For Resolution.Tick use the TickQuoteBarConsolidator, for all other resolutions use the QuoteBarConsolidators.
  • Options- trade and quote data, at Resolution.Minute only. For consolidating options data use the TradeBarConsolidator or the QuoteBarConsolidator (depending on if you're consolidating trades or quotes).
  • Futures - trade and quote data, at tick, second and minute resolutions.

Consolidators Indicators

If you'd like to have an indicator updated using a specific resolution of data; e.g. 30-period, 15-minute EMA; then you should ideally use the helper methods which come with the indicators. Most indicators handle setting up these resolution periods for you. See Indicators for more information.

You may have a custom indicator which doesn't have this helper. In this case you should register your indicator with the RegisterIndicator function which will automatically create a consolidator and pipe the data into your Indicator class.

In very rare cases you may want to update your indicator manually. You can do this by passing each data point into your indicator.Update() method from your consolidator DataConsolidated event handler.

// Consolidating minute SPY into Daily SMA/EMA.
var ema = EMA("SPY", 14, Resolution.Daily);
var sma = SMA("SPY", 14, Resolution.Daily);
// Register for daily bars from minutely data.
AddEquity("SPY", Resolution.Minute);
var myTradeBarIndicator = new MyTradeBarIndicator(120);
RegisterIndicator("SPY", myTradeBarIndicator, Resolution.Daily);
# Consolidating minute SPY into Daily SMA/EMA.
ema = self.EMA("SPY", 14, Resolution.Daily)
sma = self.SMA("SPY", 14, Resolution.Daily)
# Register for daily bars from minutely data.
self.AddEquity("SPY", Resolution.Minute)
myTradeBarIndicator = MyTradeBarIndicator(120)
self.RegisterIndicator("SPY", myTradeBarIndicator, Resolution.Daily)
// Create, initialize a consolidator and add an indicator
private SimpleMovingAverage _sma;

public override void Initialize()
{
	//...other initialization...
	AddEquity("SPY", Resolution.Minute);
	var consolidator = new TradeBarConsolidator(30);
	_sma = new SimpleMovingAverage(10);
	RegisterIndicator("SPY", _sma, consolidator);
	SubscriptionManager.AddConsolidator("SPY", consolidator);
}
# Create, initialize a consolidator and add an indicator
def Initialize(self):
    # ...other initialization...
    self.AddEquity("SPY", Resolution.Minute)
    consolidator = TradeBarConsolidator(30)
    self._sma = SimpleMovingAverage(10)
    self.RegisterIndicator("SPY", self._sma, consolidator)
    self.SubscriptionManager.AddConsolidator("SPY", consolidator)

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page Helpful ?