Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -1.245 Tracking Error 0.179 Treynor Ratio 0 Total Fees $0.00 |
class SMAUniverse(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 9, 18) self.SetEndDate(2020, 10, 4) self.SetCash(100000) self.UniverseSettings.Resolution = Resolution.Daily self.AddUniverse(self.CoarseSelectionFunction) #1. Create our dictionary and save it to self.averages self.averages = {} def CoarseSelectionFunction(self, universe): selected = [] universe = sorted(universe, key=lambda c: c.DollarVolume, reverse=True) universe = [c for c in universe if c.Price > 10 and c.HasFundamentalData][:100] # Create loop to use all the coarse data for coarse in universe: symbol = coarse.Symbol self.Debug("CoarseSelectionFunction {0}".format(symbol) ) #2. Check if we've created an instance of SelectionData for this symbol if symbol not in self.averages: #3. Create a new instance of SelectionData and save to averages[symbol] self.averages[symbol] = SelectionData() #4. Update the symbol with the latest coarse.AdjustedPrice data self.averages[symbol].update(self.Time, coarse.AdjustedPrice) #5. Check if 150-SMA > 200-SMA and if so append the symbol to selected list. if self.averages[symbol].fast > self.averages[symbol].slow: if self.averages[symbol].is_ready(): selected.append(symbol) return selected[:10] def OnData(self, data): # self.Debug("no. of symbols held in this slice {0}".format( len(self.ActiveSecurities) )) symbols = [x.Symbol for x in self.ActiveSecurities.Values] for symbol in symbols: self.Debug(symbol) # def OnSecuritiesChanged(self, changes): # for security in changes.RemovedSecurities: # self.Liquidate(security.Symbol) # for security in changes.AddedSecurities: # self.SetHoldings(security.Symbol, 0.10) class SelectionData(object): def __init__(self): self.slow = SimpleMovingAverage(200) self.fast = SimpleMovingAverage(150) def is_ready(self): return self.slow.IsReady and self.fast.IsReady def update(self, time, price): self.fast.Update(time, price) self.slow.Update(time, price)