Back

Adding data to rolling windows for a list of stocks, and making sure rolling windows are ready

Hello all,

I was wondering if someone could help me with this:

Below is a simplified code to create 22, 11, and 2 day rolling windows for each stock in a list of stocks. It contains a SymbolData class to create objects for each of the symbols in a list of stocks. In this example, an arbitrary list is chosen, say: ["SPY", "TLT", "BND"].

Given as you can see in the code that I have added the OnDailyData function to add daily bars to the rolling windows, would the code below suffice in adding data to the rolling windows or do I still need to write something of this sort in OnData in this case?  ---> something like this: window.Add(data[symbol])

Also, how do we make sure it is ready in OnData in this case ? (e.g. if not window.IsReady: return)

More importantly, can any of the tasks above be added to the SymbolData class instead of OnData ?

Thanks for your help and patience.

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.


You can use some list comprehension with your dictionary of symbolData to create a boolean which returns true if all the Rolling Windows are ready. Adding a cumulative IsReady field in SymbolData which returns true if all the rolling windows for that symbol data object are ready will make things easier.

One thing to point to out is OnDailyData looks like an event handler for a consolidator but you haven't defined any consolidators. Also, you're already subscribing to daily resolution data; so there is no need for OnDailyData. You can update the rolling windows in OnData with daily data.

The current structure of the code is good. But if let's say, you were to add indicators for each of the symbols, they should go in SymbolData.

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.


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