Back

Multiple symbol rolling window

Hi all - can a rolling window be used to store and recall multiple symbols' histories?

I understand that:

self.window.Add(data['AAPL'])
Bar = self.window[i]

will index the ith previous day, but below, the index references the symbol, not the history:

self.window.Add(data['AAPL'])
self.window.Add(data['IBM'])

IBMBar = self.window[0]
AAPLBar = self.window[1]

I've tried pandas-esque multiple indexing variations of e.g. self.window['IBM'][1] or self.window[0][1] but no luck. 

I'd like to store all ticker histories in a single window if possible.

Thanks in advance!

Update Backtest








Hi Matt,

You could create a class and create the rolling window in the class. Then each symbol is an object. You could store all the objects in a dictionary and update the rolling window with the symbol key. I attached an example for your reference.

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.


Jing Wu   Thank you so much - very kind of you to provide this example, that's exactly what I was looking for.

When I initially asked the question, I wasn't sure if the Add method allowed for multiple symbols' data to be stored in a similar fashion to how AddEquity works with Portfolio. Anyway, thanks again, that's a great help.

0

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