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.974 Tracking Error 0.123 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
class SwimmingYellowGreenDogfish(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 1, 21) self.SetCash(100000) self.dataBySymbol = {} self.AddUniverse(self.MyCoarseFilterFunction) self.UniverseSettings.Resolution = Resolution.Daily def MyCoarseFilterFunction(self, coarse): sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) filtered = [ x.Symbol for x in sortedByDollarVolume if x.Price > 10 and x.DollarVolume > 10000000 ] return filtered[:10] def OnData(self, data): for symbol in self.dataBySymbol: if self.dataBySymbol[symbol].IsReady: self.Debug("sharpe ratio of "+str(symbol)+" is "+str(self.dataBySymbol[symbol].sharpe.Current.Value)) def OnSecuritiesChanged(self, changes): for x in changes.AddedSecurities: if x.Symbol not in self.dataBySymbol: self.dataBySymbol[x.Symbol] = SymbolData(self,x.Symbol) for x in changes.RemovedSecurities: data = self.dataBySymbol.get(x.Symbol,None) if data: data.dispose() class SymbolData: def __init__(self,algo,symbol): self.algo = algo self.symbol = symbol self.sharpe = SharpeRatio(7,0.1) history = self.algo.History(self.symbol,7,Resolution.Daily) if not history.empty and 'close' in history.columns: for bar in history.loc[symbol, :].itertuples(): self.sharpe.Update(bar.Index,bar.close) self.consolidator = TradeBarConsolidator(timedelta(days = 1)) self.consolidator.DataConsolidated += self.OnDataConsolidated algo.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator) @property def IsReady(self): return self.sharpe.IsReady def OnDataConsolidated(self,sender,bar): self.sharpe.Update(bar.Time,bar.Close) def dispose(self): self.algo.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)