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 -6.166 Tracking Error 0.091 Treynor Ratio 0 Total Fees $0.00 |
class DynamicOptimizedContainmentField(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 11, 20) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.UniverseSettings.Resolution = Resolution.Daily self.AddUniverse(self.SelectCoarse) self.symbols = {} def SelectCoarse(self, coarse): sortedCoarse = sorted(coarse, key=lambda c:c.DollarVolume, reverse=True) return [c.Symbol for c in sortedCoarse][:10] def OnSecuritiesChanged(self, changes): for security in changes.AddedSecurities: symbol = security.Symbol if symbol not in self.symbols: self.symbols[symbol] = SymbolData(self, symbol) for security in changes.RemovedSecurities: symbol = security.Symbol if symbol in self.symbols: symbolData = self.symbols.pop(symbol, None) self.SubscriptionManager.RemoveConsolidator(symbol, symbolData.consolidator) def OnData(self,data): d = self.Time.date() symbol = list(self.symbols.keys())[0] symbolData=self.symbols[symbol] if symbolData.IsReady : self.Debug(symbolData.Time) self.Debug(symbolData.Close) self.Debug(symbolData.RSI.Current.Value) class SymbolData: def __init__(self, algorithm, symbol): self.algorithm = algorithm self.symbol = symbol self.consolidator = TradeBarConsolidator(timedelta(days=7)) self.consolidator.DataConsolidated += self.OnDataConsolidated algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator) self.Time=None self.Close=0 self.RSI=SimpleMovingAverage(2) self.IsReady=False history = algorithm.History(symbol,14, Resolution.Daily) for idx, bar in history.iterrows(): tradeBar = TradeBar(idx, symbol, bar.open, bar.high, bar.low, bar.close, bar.volume, timedelta(days=7)) # self.consolidator.Update(tradeBar) def OnDataConsolidated(self, sender, bar): self.algorithm.Debug(f"Data Consolidatoed for {self.symbol} at {bar.EndTime} with bar: {bar}") self.Close=bar.Close self.Time=bar.Time self.RSI.Update(bar.Time, bar.Close) self.IsReady = self.RSI.IsReady