I am trying to do some basic lookback on equities price but for some reaason my loop is throwing an out of range error. The rollingwindows has worked fine before with indicators.
import numpy as np
import decimal as d
from datetime import timedelta
### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2015, 1, 1) #Set Start Date
self.SetEndDate(2017,1,1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.osymbol = "XOM"
equity = self.AddEquity("XOM", Resolution.Daily)
self.stock = equity.Symbol
self._sma = RollingWindow[d.Decimal](14)
self.window = RollingWindow[TradeBar](14)
self._sma12 = self.SMA(self.osymbol, 12, Resolution.Daily)
def OnData(self, data):
#'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
#self._macdHistogram.Add(self._macd.Histogram.Current.Value)
#self._RSI.Add(self._rsi.Current.Value)
self._sma.Add(self._sma12.Current.Value)
self.window.Add(data["XOM"])
# Wait for windows to be ready.
if not self.window.IsReady: return
if not self.Portfolio.Invested:
for num in range(0,4):
self.Log(self.window[num])
The error i get is " Runtime Error: ArgumentOutOfRangeException : Must be between 0 and 0
"
Parameter name: i
Actual value was 1.
at QuantConnect.Indicators.RollingWindow`1[T].get_Item (System.Int32 i) [0x0004c] in <76d49b5d5c8545899040d54812d7ccc1>: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 74
ArgumentOutOfRangeException : Must be between 0 and 0
Parameter name: i
Actual value was 1.
at QuantConnect.Indicators.RollingWindow`1[T].get_Item (System.Int32 i) [0x0004c] in <76d49b5d5c8545899040d54812d7ccc1>: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)
Michael Manus
For me it says it is has maybe one value -- to access this you can use indexed with 0 to get it
Or the array is empty. I'm not sure know.
But what you did: using index 1 which won't work because nothing is there :)
Paul Park
I don't understand why the windows array doesnt't contain tradebar price in each index. I was able to print out all the values in index 0. It seems as if all the values where placed in index 0.. How would I fix this so that the values are distributed into each index?
Paul Park
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!