I am trying to initialize a list that contains the low price for SPY for the past 4 days at the initialization stage. However, it is giving me an error saying that the history object has no attribute ‘itertuples’ when I try to append to my list. And it seems like self.History is not return a dataframe object. Did I miss a step somewhere?
Code:
class CryingAsparagusKoala(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 2, 16) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Daily)
self.low = []
history = self.History("SPY", 4, Resolution.Daily)
self.Log("history is type:".format(type(history)))
for bar in history.itertuples():
self.low.append(bar.close)
def OnData(self, data):
if not self.Portfolio.Invested:
self.SetHoldings("SPY", 1)
Error:
During the algorithm initialization, the following exception has occurred: AttributeError : '0, Culture=neutral, PublicKeyToken=null]]' object has no attribute 'itertuples'
at Initialize
for bar at history.itertuples():
===
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 11
AttributeError : '0, Culture=neutral, PublicKeyToken=null]]' object has no attribute 'itertuples'
Varad Kabade
Hi Jluo,To fix the issue, we recommend following the above code snippet:
Refer to the attached backtest.Best,Varad Kabade
Jluo
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!