self.SetStartDate(2021, 1, 1)
# self.SetEndDate(2021, 4, 3)
self.cap = 10000
self.SetCash(self.cap)
self.STOCKS = [self.AddEquity(ticker, Resolution.Daily).Symbol for ticker in STOCKS]
self.mom_lookback = 10
self.stock_selection = None
self.ret_reb_month = 0
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen('SPY', 60),
self.daily_check)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen('SPY', 120),
self.trade)
def trade(self):
if self.ret_reb_month!=self.Time.moth:
self.stock_selection = self.calc_return(self.STOCKS, 1)
self.ret_reb_month = self.Time.month
for sec in self.STOCKS:
self.wt[sec] = LEV/len(self.stock_selection) if self.bull and (sec in self.stock_selection) else 0;
for sec in self.BONDS:
self.wt[sec] = 0 if self.bull else LEV/len(self.BONDS);
for sec, weight in self.wt.items():
if weight == 0 and self.Portfolio[sec].IsLong:
self.Liquidate(sec)
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!