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 -19.892 Tracking Error 0.071 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
class BasicTemplateFuturesConsolidationAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 3, 10) self.SetEndDate(2021, 3, 15) self.SetCash(1000000) futureSP500 = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Minute) futureSP500.SetFilter(30, 182) # dictionary to save class object containing consolidator and self.consolidator = {} # we set a warmup period for the first bar self.SetWarmUp(timedelta(1)) def OnData(self,slice): pass def OnSecuritiesChanged(self, changes): for security in changes.AddedSecurities: # Custom consolidator self.consolidator[security.Symbol] = CustomDaily(self) self.consolidator[security.Symbol].consolidator = TradeBarConsolidator(self.consolidator[security.Symbol].Consolidator) self.consolidator[security.Symbol].consolidator.DataConsolidated += self.CustomDailyHandler self.SubscriptionManager.AddConsolidator(security.Symbol, self.consolidator[security.Symbol].consolidator) for security in changes.RemovedSecurities: consolidator = self.consolidators.pop(security.Symbol) self.SubscriptionManager.RemoveConsolidator(security.Symbol, consolidator.consolidator) consolidator.DataConsolidated -= self.OnDataConsolidated def CustomDailyHandler(self, sender, bar): self.Debug("Bar starts at " + str(bar.Time) + ", ends at " + str(bar.EndTime)) self.Debug(str(bar)) # marked we've passed the first bar of this symbol self.consolidator[bar.Symbol].start = True class CustomDaily: def __init__(self, algo): self.algo = algo self.start = False self.consolidator = None def Consolidator(self, dt): # after the first bar of all, we concolidate every 1 day if self.start: return CalendarInfo(dt, timedelta(1)) else: # first bar will consolidate at next day's 1700 if self.algo.Time.hour > 17: return CalendarInfo(dt, dt.replace(hour=17, minute=0, second=0) - dt) else: return CalendarInfo(dt, dt.replace(hour=17, minute=0, second=0) - dt + timedelta(1))