My very first algo on QuantConnect. The error that I am getting is: "object has no attributable securities". Any help with debugging would be very much appreciated.
On a separate note, when making my very first step in Quantopian I liked priniting everything, so that I could see what is actually happening to the data. In this case, if I would like to print SPY daily Close prices and the moving average daily, how would I use the "debug" function?
Lastly, in the context below, if there any difference between self.securities["SPY"].Price and self.securities["SPY"].Close?
Many thanks in advance for all your help!
class EnergeticOrangeBuffalo(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2008, 1, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.spy = self.AddEquity("SPY", Resolution.Daily)
self.sma = self.SMA("SPY", 30, Resolution.Daily)
def OnData(self, data):
if not self.sma.IsReady:
return
if self.securities["SPY"].Price>self.sma.Current.Value:
self.SetHoldings("SPY", 1)
else:
self.SetHoldings("SPY", -1)
Mitch Carrara
# based on what's shown, i didnt backtest this class EnergeticOrangeBuffalo(QCAlgorithm): def Initialize(self): self.SetStartDate(2015, 1, 1) # Set Start Date self.SetEndDate(2016, 1, 1) # Set End Date self.SetCash(100000) # Set Strategy Cash self.spy = self.AddEquity("SPY", Resolution.Daily) self.sma = self.SMA("SPY", 30, Resolution.Daily) def OnData(self, data): if not self.sma.IsReady: return Close = data["SPY"].Close SMA = self.sma.Current.Value self.Debug("SPY Closing Price: " + str(Close) + ", 30 period SMA Value: " + str(SMA)) # if self.securities["SPY"].Price>self.sma.Current.Value: # you could capitalize the S, i think that was the error if Close > SMA: self.SetHoldings("SPY", 1) else: self.SetHoldings("SPY", -1)
Mitch Carrara
nevermind i did backtest this lol. ignore that note
Alexey Dremov
Fantastic, thank you so much! Really do appreciate your help!
Alexey Dremov
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!