Hi everyone,
I was trying to use rolling window to perform some comparison and i saw the official example demonstrating such possibility to comparing slice by slice. However, when i try to set the rolling window to 5 days long period and try to iterate all of them but failed. I have some confusion around rolling window, hope i could get some advise from you and help me to understand this object more. Thank you
self.window = RollingWindow[TradeBar](5) #setting up the 5days long rolling window
The first confusion is that I am not sure RollingWindow is an array, because when i try to use len(self.window), the error return and said it is not a type has len() function. In other words, it is not an array?
Runtime Error: TypeError : object of type '0, Culture=neutral, PublicKeyToken=null]]' has no len() at OnData in main.py:line 85 :: len(self.window) TypeError : object of type '0, Culture=neutral, PublicKeyToken=null]]' has no len()
The second confusion is, if rolling window is not an array then how can we able to access self.window[0] and works perfectly just ike the doc shown:
https://www.quantconnect.com/docs/algorithm-reference/rolling-window#Rolling-Window-Combining-with-Indicators
The thrid confusion follow with the #2 is if it is an array then why can't i access self.window[:]? It will return error:
Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the arguments method. Please checkout the API documentation. at OnData in main.py:line 85 :: self.Log(self.window[:]) TypeError : No method matches given arguments
I'm apologize for I dont have any project/research code could share. All I'm doing is just within Initialize() and OnData().
Aaron Janeiro Stone
Given that Lean is primarily written in C# while Python interactivity is achieved via wrapping around the C# implementations, quite a few objects in Lean will not behave exactly like a typical python object. A good previous discussion on RollingWindows → arrays can be found at
https://www.quantconnect.com/forum/discussion/5077/from-rollingwindow-to-numpy-array/p1As to why indexing works as you described, the source code provides an answer --
https://github.com/QuantConnect/Lean/blob/6ab40c102b91404ac3561aae72c41619f0db908a/Common/Indicators/RollingWindow.cs#L127GURU GURU
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!