In order to try to improve options algo backtest performance when using the Options Universe method, as I require the options Greeks for selection, I created a test algo that dynamically adjusts the options universe filter.

I would like to also trade options for multiple underlyings and so this is the first step towards that, as the subscription needs to be managed to keep within the data lines limits.

The following sequence shows an issue that an updated minimised option universe filter is only applied by LEAN after the next monthly options expiration has occurred, instead of being applied immediately from the next Slice event.
   
   Tested the following sequence:
     1.  Add option universe using underlying symbol
     2.  Set universe filter to required strike range and expiration
     3.  Select option from the Slice OptionChain (eg. by Expiration, Delta)
     4.  Reduce the option universe using SetFilter to the minimum subscribed set
     5.  Add the selected option to the subscription
     6.  For next trade:
     7.  Close the current option position and unsubscribe the selected option
     8.  Repeat process from step 2
    
   Is this an issue with this test sequence, or is this an issue with LEAN?
   Any info or ideas much appreciated.
   Test algo added.
  
   Extracts from the log with added comments for clarification:
   ----------------------
   => option universe SetFilter 'normal' filter is used to filter the required strike range and expiration
   2017-06-01 15:45:00 :     6/1/2017 3:45:00 PM: chain.Contracts.Count=7
   
   => contract is selected
   2017-06-01 15:45:00 :     6/1/2017 3:45:00 PM: INFO: Closest to 50 DTE selection found DTE=49.08:15:00 symbol=SPY 170721C00242000
   2017-06-01 15:45:00 :     6/1/2017 3:45:00 PM: INFO: Valid Option selection found DTE=49.08:15:00 Symbol=SPY 170721C00242000 Delta=0.58
   
   => **** SetFilter is called here to minimise the option universe once the contract has been selected BUT why is it not applied by LEAN until after next option expiration?
   2017-06-01 15:45:00 :     6/1/2017 3:45:00 PM: MinimiseFilterOptionUniverse
   
   => selected contract is added to the subscription
   2017-06-01 15:46:00 :     AddOptionContract:SPY 170721C00242000
   => contract is bought
   2017-06-01 15:47:00 :     6/1/2017 3:47:00 PM: Buy: optionContractSymbol=SPY 170721C00242000
   

   => Q. Why isn't the updated filter being applied by LEAN immediately instead of after next monthly option Expiration day?
   2017-06-02 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-05 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-06 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-07 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-08 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-09 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-12 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-13 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-14 15:45:00 :     chain.Contracts.Count=7    (no change)
   2017-06-15 15:45:00 :     chain.Contracts.Count=7    (no change)
   
   => Option Expiration Day on 2017-06-16
   2017-06-16 15:45:00 :     chain.Contracts.Count=4
   
   => **** updated filter is now only applied by LEAN after option expiration day - why?
   2017-06-19 15:45:00 :     chain.Contracts.Count=1    (filter now applied)
   2017-06-20 15:45:00 :     chain.Contracts.Count=1    (filter now applied)
   2017-06-21 15:45:00 :     chain.Contracts.Count=1    (filter now applied)
   2017-06-22 15:45:00 :     chain.Contracts.Count=1    (filter now applied)
   2017-06-23 15:45:00 :     chain.Contracts.Count=1    (filter now applied)
   .
   .
   .
   => option roll (sell option, reapply universe filter to be able to select next option to buy)
   2017-07-17 09:31:00 :     7/17/2017 9:31:00 AM: OnData: INFO: Sell : rollover as DTE < 5
   2017-07-17 09:31:00 :     RemoveSecurity:SPY 170721C00242000
   2017-07-17 09:32:00 :     7/17/2017 9:32:00 AM: OnData: slice.Count=1
   
   => reapply universe filter to required strike range and expiration
   2017-07-17 09:32:00 :     7/17/2017 9:32:00 AM: AddOptionUniverseForUnderlying: SetFilter
   
   => **** updated filter is applied correctly immediately to the chain
   2017-07-17 09:50:00 :     7/17/2017 9:50:00 AM: OnData: slice.Count=6  (ok)
   2017-07-17 15:45:00 :     7/17/2017 3:45:00 PM: chain.Contracts.Count=5 (ok)
   
   => next option series contract is selected for trade   
   2017-07-17 15:45:00 :     7/17/2017 3:45:00 PM: INFO: Closest to 50 DTE selection found DTE=31.08:15:00 symbol=SPY 170818C00245000
   2017-07-17 15:45:00 :     7/17/2017 3:45:00 PM: INFO: Valid Option selection found DTE=31.08:15:00 Symbol=SPY 170818C00245000 Delta=0.58
   
   => **** SetFilter is called here to minimise the option universe once the contract has been selected BUT why is it not applied by LEAN until after next option expiration?
   2017-07-17 15:45:00 :     7/17/2017 3:45:00 PM: MinimiseFilterOptionUniverse

   => Q. Why isn't the updated filter being applied by LEAN immediately instead of after option Expiration day?
   2017-07-18 15:45:00 :     chain.Contracts.Count=5    (no change)
   2017-07-19 15:45:00 :     chain.Contracts.Count=5    (no change)   
   2017-07-20 15:45:00 :     chain.Contracts.Count=5    (no change)
   
   => Option Expiration Day on 2017-07-21
   2017-07-21 15:45:00 :     chain.Contracts.Count=5    (no change)
   
   => **** updated filter is now only applied by LEAN after option expiration day - why?
   2017-07-24 15:45:00 :     chain.Contracts.Count=1    (filter now applied)
   2017-07-25 15:45:00 :     chain.Contracts.Count=1    (filter now applied) 
   ----------------------
  
Thanks,
ES.