Conslidate data to 30 minutes

Back

I have read the docs on consolidators, saw github examples and tried to find examples on communnity but I still dont' understand consolidators. I have build the strategy for the backtest with minute resolution, I want to move noe from minute to 30 minute resolution.

I don't understand what's really happening, but I copy paste following code to my initialize part (don't understand what dataConsolidated property contains, what are other methods/properties, why we need to add handler, and what updates it needs to receive from engine....):

# consolidators
# define our 30 minute trade bar consolidator. we can access the 30 minute bar from the DataConsolidated events
thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30))
# attach our event handler. the event handler is a function that will be called each time we produce a new consolidated piece of data.
thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler
# this call adds our 30 minute consolidator to the manager to receive updates from the engine
self.SubscriptionManager.AddConsolidator(self.symbol, thirtyMinuteConsolidator)

If I just run the script with this change nothing happens. It seems I have to remove OnData part (just pass) and put everything I develope so far into the handler? But I don't have `data` arguments in handler as in OnData part anymore. 

In nutshell, I am really confused about consolidators. What is the simplest way to consolidate data to 30 minutes? Do OnData part to handlers? Whay we have to do that?

I didn't attached the backtest since I don't want to make it visible, but it can be any backtest with simple trading rules (SMA crossover for example).

Update Backtest







 
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Mislav,

When consolidating data, OnData is still called regularly, the consolidated data is passed to the consolidation handler that we set.  In the consolidation handler, we can access the consolidated bar through the `consolidated` parameter.

def ThirtyMinuteBarHandler(self, sender, consolidated):
self.Log(f"{consolidated.Close} at {consolidated.EndTime}")

See the attached backtest for reference.

To access the latest slice object that will appear in OnData, we can use `self.CurrentSlice`.

Best,
Derek Melchin

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed