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 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
class DynamicModulatedRegulators(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 9, 4) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.UniverseSettings.Resolution = Resolution.Minute self.AddUniverse(self.CoarseSelection) self.SetAlpha(MyAlpha()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetRiskManagement(TrailingStopRiskManagementModel()) self.SetExecution(ImmediateExecutionModel()) def CoarseSelection(self, coarse): sortedCoarse = sorted(coarse, key=lambda c:c.DollarVolume, reverse=True) return [c.Symbol for c in sortedCoarse][:50] class MyAlpha(AlphaModel): def __init__(self): self.symbolDict = {} def Update(self, algorithm, data): insights = [] for symbol in self.symbolDict: # Generate Insights pass return insights def OnSecuritiesChanged(self, algorithm, changes): # Add new symbols to symbolDict for security in changes.AddedSecurities: symbol = security.Symbol if symbol not in self.symbolDict: self.symbolDict[symbol] = SymbolData(algorithm, symbol) # Remove consolidators for removed symbols and also remove symbol from symbolDict for security in changes.RemovedSecurities: symbol = security.Symbol if symbol in self.symbolDict: algorithm.SubscriptionManager.RemoveConsolidator(symbol, self.symbolDict[symbol].consolidator) self.symbolDict.pop(symbol, None) class SymbolData: def __init__(self, algorithm, symbol): self.algorithm = algorithm self.symbol = symbol self.period = 10 self.resolution = timedelta(minutes = 5) self.bars = RollingWindow[TradeBar](self.period) self.AWindow = RollingWindow[float](self.period) self.B1Window = RollingWindow[float](self.period) self.B2Window = RollingWindow[float](self.period) self.CWindow = RollingWindow[float](self.period) # Creates and subscribes consolidator to data self.consolidator = TradeBarConsolidator(self.resolution) algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator) # Set DataConsolidated event handler for consolidator self.consolidator.DataConsolidated += self.OnDataConsolidated # Updates bars window with each new bar of our desired resolution def OnDataConsolidated(self, sender, bar): self.bars.Add(bar) # If we are ready to calculate A if self.bars.IsReady: self.UpdateA() def UpdateA(self): # Calculate A based on bars # current_A = ..... # Add current A to rolling window # self.AWindow.Add(current_A) # If we are ready to calculate B if self.AWindow.IsReady: self.UpdateB() def UpdateB(self): # Calculate B1 and B2 based on AWindow # current_B1 = .... # current_B2 = .... # Add to windows # self.B1Window.Add(current_B1) # self.B2Window.Add(current_B2) # If we are ready to calculate C if self.B1Window.IsReady and self.B2Window.IsReady: self.UpdateC() def UpdateC(self): # Calculate C based on B1Window and B2Window and AWindow # current_C = .... # Add to window # self.CWindow.Add(current_C) pass # Returns most recent value def GetAValue(self): if self.AWindow.Count > 0: return self.AWindow[0] def GetB1Value(self): if self.B1Window.Count > 0: return self.B1Window[0] def GetB2Value(self): if self.B2Window.Count > 0: return self.B2Window[0] def GetCValue(self): if self.CWindow.Count > 0: return self.CWindow[0]