Hi All-
I've built a strategy upon minutely universe resolution. Now that it's mostly stable I want to speed things up a bit, but second data is too computationally intensive. Something like a few seconds (5 or 10 seconds) for the OnData rate seems to be more appropriate for the strategy.
I couldn't find anything in the Documentation or Forum covering this, but I do know that OnData is set by the universe resolution.
Attached is the time and data related code I have currently. Basically just a rollingwindow that consolidates the minutely data into daily bars. I removed the fluff for the sake of readability.
So, is a custom resolution possible to feed into OnData??
PS: This algo only trades Equities (for now)
def Initialize(self):
self.SetStartDate(2022, 8, 1)
self.SetCash(1000000)
self.rebalanceTime = datetime.min
self.AddUniverse(self.CoarseSelectionFilter, self.FineSelectionFilter)
self.UniverseSettings.Resolution = Resolution.Minute
self.AddEquity("SPY")
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 10), self.ExitPositions)
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(9, 31), self.ScanTargets)
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.Midnight, self.ClearFills)
self.Data = {}
self.AddRiskManagement(TrailingStopRiskManagementModel(0.05))
def OnData(self, data):
for symbol in self.Targets.keys():
symbolData = self.Data[symbol]
if not symbolData.IsReady:
continue
open_orders = self.Transactions.GetOpenOrders(symbol)
if not self.Portfolio[symbol].Invested and len(open_orders) == 0 and symbol not in self.filled_today.keys():
# Strategy logic.....
def CoarseSelectionFilter(self, coarse):
# filter logic....
def OnSecuritiesChanged(self, changes):
for security in changes.AddedSecurities:
symbol = security.Symbol
if symbol not in self.Data:
self.Data[symbol] = SymbolData(self, symbol)
for security in changes.RemovedSecurities:
symbol = security.Symbol
if symbol in self.Data:
symbolData = self.Data.pop(symbol, None)
self.SubscriptionManager.RemoveConsolidator(symbol, symbolData.consolidator)
class SymbolData:
def __init__(self, algorithm, symbol):
self.algorithm = algorithm
self.symbol = symbol
self.Bars = RollingWindow[TradeBar](6)
self.consolidator = TradeBarConsolidator(timedelta(days=1))
self.consolidator.DataConsolidated += self.OnDataConsolidated
algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator)
def OnDataConsolidated(self, sender, bar):
self.Bars.Add(bar)
@property
def IsReady(self):
return self.Bars.IsReady