How to take SMACrossAlphaModel and make the model give off insights in Resolution.Minute sensitivity but to continue to use lookback period of up to 20hours.  How to manage rolling windows, consolidators, scheduled functions, etc. to accomplish this?

 

So instead of checking say a 10h and 20h crossover eachother on a Resolution.Hour, how can we run the same strategy in minute domain:

 

We want to check every Resolution.Minute, if there was  10h crossover the 20h SMA.  But we want to add more sensitivy such that if there is a crossover between say 9:35am -9:36am crossover, we can send our signals immediately without needing to wait for the 10:00am close.

 

 

Current strategy –→ UniverseModel, AlphaModel, PortfolioModel  - Resolution.Hour

 

Our Goal: Change of base resolution of AlphaModel from Hour → Minute while maintaining same integrity of trading strategy with longer indicator lookbacks of 10h, but operating on each minute to check for new crossovers.  

 

We want to make our strategy more reactive.  To not have to wait until 10:00am, 11:00am, 12:00pm, 1:00pm… but being able to trigger new alpha every 15 minutes 10:15am, 10:30am, 10:45am… or 10:01am, 10:02am (while still maintaining 10h indicator lookback to the EXACT MINUTE – not** 10:00am, 11:00am as intervals but say 10:01am, 11:01am, 12:01pm…)

--------

Resolution.Hour -> Resolution.Minute

 

Implementation Ideas


Consolidators, TradeBarConsolidator

RollingWindow

Due to data consolidation events and timing, on an hourly resolution, consolidators seem like they will only be allowed to be triggered on times that end in “:00” like 10:00am or 11:00am.

So let's say we have two simple moving averages of 10h and 20h.  Right now we have a crossover that happens between 10:00am - 11:00am and so at 11:00am our logic runs and our strategy executes.

 

Our Goal:

We would like to make our strategy more sensitive.  If the crossover happens between 10:10 and 10:15, we want our strategy to send a Insight.Up alpha signaling a bullish crossover.

Idea: Change base resolution to minute but maintain hourly indicator.

Upon Implementation, nuances arrived....

Let's look at examples.  Let's forget that our portfolio construction adjusts itself when there are changes of insight or on an hourly bases for now and just consider alpha signal generation timing and what the EMA is looking at.

 

Let's take for example the time is NYC time and the market has just opened…

9:31am 

-------------------

Using a consolidator with Resolution.Hour

1 - hourly consolidator - SMA(close, 10) - Simple moving average, close prices, 10 hours

------

9:00am  

10:00am

11:00am

12:00pm

1:00pm

2:00pm

3:00pm

4:00pm

9:00am 

9:31am -> I could grab the current price and average with each previous hour on the hour... but this doesn't quite seem right in the spirit of it

2 - hourly consolidator (only when market is not open for EMA 10h/20h calculations)

When using a standard out of the box ExponentialMovingAverage(Resolution.Hour) --> this in the background auto updates on the hour every hour and so might look a bit like below

-------

9:00am   -- not triggered, market not open

10:00am

11:00am

12:00pm

1:00pm

2:00pm

3:00pm

4:00pm

9:00am -- not triggered, market not open

9:31am -> On the minute, every minute, I could grab current price and add that to our EMA 

 

3 - hourly, but kept up to the minute.  Not using an hourly consolidator which would force :00 timing.  This could be more up to date...

-------

1:31pm

2:31pm

3:31pm

9:31am   -- prev day

10:31am

11:31am

12:31pm

1:31pm

2:31pm

3:31pm

9:31am -> I could grab current and each previous hour on the hour...

PROBLEM

-- But here is the problem with that...  on the next minute, instead of appending 9:32am like......

1:31pm

2:31pm

3:31pm

9:31am   -- prev day

10:31am

11:31am

12:31pm

1:31pm

2:31pm

3:31pm

9:32am 

NEW PROBLEM WITHIN SOLUTION

-- Would instead need to update all the previous values which then kinda of breaks the idea of a Rolling Window and adding a single value to a queue -- because we would need to update every value in the single Rolling Window to do our next calculation which would be a self.History call which is slow to do every minute

1:32pm

2:32pm

3:32pm

9:32am   -- prev day

10:32am

11:32am

12:32pm

1:32pm

2:32pm

3:32pm

9:32am -> I could grab current and each previous hour on the hour...

 

 

KEEP MINUTES BUT JUST SCALE SMACrossAlphaModel periods BY MULT. * 60 TO CONVERT TO MINUTES FROM HOURS

-- What if we just are on a minute resolution but then scale our indicators by multiplying by 60?

let's think about it, 

20h * 60 = the amount of data needed to calculate a single EMA using Resolution.Minute but operating with hourly indicators = 1200 data points to be used in EMA calculation * 20 stocks = 24000 data points per minute

24000 data points * every minute the market is open and runs (390minutes) = 468,000 per day with a ~5 year backtest with ~255days in a trade year -- 596,700,000 ---> this is making it hard to backtest cause the backtests move like a snail pace so its hard to quickly check logic.

 

So to improve on our time/data complexity, perhaps we adjust our space complexity by adding more Rolling Windows…

 

 

MULTIPLE ROLLING WINDOWS

Idea - Use 4 scheduled Functions and 4 rolling windows -- Once every 15 minutes** - starting with this one

Idea - Use 12 scheduled Functions and 4 rolling windows -- Once every 5 minutes

-----

[9:00am, 10:00am, 11:00am, 12:00pm, 1:00pm, 2:00pm, 3:00pm, 4:00pm, 9:00am...]

[9:15am, 10:15am, 11:15am, 12:15pm, 1:15pm, 2:15pm, 3:15pm, 4:15pm, 9:15am...]

[9:30am, 10:30am, 11:30am, 12:30pm, 1:30pm, 2:30pm, 3:30pm, 4:30pm, 9:30am...]

[9:45am, 10:45am, 11:45am, 12:45pm, 1:45pm, 2:45pm, 3:45pm, 4:45pm, 9:45am...]

So .... because we can't select a 15m timeframe resolution... We must change our resolution from Hour -> Resolution.Minute.  So even though we check every minute what our signals are ... we have to importantly ask – WHEN do THOSE signals get updated?  Do we keep checking signals that are not getting changed and are only changed on the hour every hour?

 

 

Rolling Window Method

By keeping:

every 15 minutes -- 4 rolling windows of 20 data points each -- 80 data points per stock * 20 stocks = 1600 data points which is definitely an improvement

every 5 minutes   -- 12 rolling windows of 20 data points each

every 1 minute    -- 60 rolling windows of 20 data points each

 

 

 

So would I need 60 rolling windows of 20 data points each for each stock ( for each minute between 0 and 60, we have a depth of lookback window of 20 data points (20h simple moving average) – we do this for each stock in our universe ~20 stocks)?

Is this the most optimal way to solve this problem?