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

This is really a great example, was also helping me.

Somehow i am having difficulties trying to access the RollingWindow. Actually i thought it should be for the smaWin from the example just symbolData.smaWin[3]. But that seems not to work for me. Guess this is just a stupid mistake from me here, but would be really happy if somebody could help me here...


Trying to access "self.Log(symbolData.smaWin[3])" with the cloned algorithm from above, i get this error message:
 

24 | 14:06:55:
Runtime Error: ArgumentOutOfRangeException : Must be between 0 and 0
Parameter name: i
Actual value was 3.
at QuantConnect.Indicators.RollingWindow`1[T].get_Item (System.Int32 i) [0x0004c] in <bad781cfbe0a4d3087700d4fb892d638>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0
at OnData in main.py:line 94
ArgumentOutOfRangeException : Must be between 0 and 0
Parameter name: i
Actual value was 3.
at QuantConnect.Indicators.RollingWindow`1[T].get_Item (System.Int32 i) [0x0004c] in <bad781cfbe0a4d3087700d4fb892d638>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0 (Open Stacktrace)
0

Hi Beaker, it looks like the error lies in the rolling window is not ready. When you try to retrieve the window value with the index, please add a check 

if symbolData.smaWin.IsReady:
self.Log(symbolData.smaWin[3])

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