Hi, how can we add other stocks to the algorithm taught on bootcamp, i tried to reproduce the algorithme using 2 stocks but it doesn't return me anything.Can someone help me to fix the problem?
Thank you
class FadingTheGap(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 11, 1)
self.SetEndDate(2018, 7, 1)
self.SetCash(100000)
self.tickers=["FB","TSLA"]
for ticker in self.tickers:
self.AddEquity(ticker, Resolution.Minute)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(ticker, 0), self.ClosingBar)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(ticker, 1), self.OpeningBar)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(ticker, 45), self.ClosePositions)
self.volatility = StandardDeviation(ticker, 60)
self.window = RollingWindow[TradeBar](2)
def OnData(self, data):
for ticker in self.tickers:
if data[ticker] is not None:
#2. Update our standard deviation indicator manually with algorithm time and TSLA's close price
self.volatility.Update(self.Time, data[ticker].Close)
def OpeningBar(self):
for ticker in self.tickers:
if self.CurrentSlice[ticker] is not None:
self.window.Add(self.CurrentSlice[ticker])
#3. Use IsReady to check if both volatility and the window are ready, if not ready 'return'
for ticker in self.tickers:
if not self.window.IsReady or not self.volatility.IsReady:
return
for ticker in self.tickers:
delta = self.window[0].Open - self.window[1].Close
#4. Save an approximation of standard deviations to our deviations variable by dividing delta by the current volatility value:
for ticker in self.tickers:
deviations = delta / self.volatility.Current.Value
for ticker in self.tickers:
if deviations < -3:
self.SetHoldings(ticker, 1)
def ClosePositions(self):
for ticker in self.tickers:
self.Liquidate(ticker)
def ClosingBar(self):
for ticker in self.tickers:
self.window.Add(self.CurrentSlice[ticker])