Fading the Gap for different stocks

Back

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])

 

Update Backtest







 
0

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.


Hey Wawes23,

Right now you only have one variable, self.volatility, to hold the StandardDeviation indicator. This is not sufficient for multiple symbols. You need to create a dictionary to hold the StandardDeviation indicator for each symbol. You also need to create a dictionary to hold the RollingWindows for each symbol.

 

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed