Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Option Exercise Consistency

Open AlexCatarino opened this issue 1 year ago • 3 comments

Expected Behavior

Options are exercised with the same underlying price whether we subscribe to extended hours or not.

Actual Behavior

The exercised price is different.

Order Tab

Potential Solution

Do not use prices outside the market hours.

Reproducing the Problem

backtest_1401e01, use extended_market_hours=False for different results.

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

AlexCatarino avatar May 23 '24 18:05 AlexCatarino

Thanks Alex! This is a significant issue, please fix it asap.

MarcellThoth avatar May 24 '24 09:05 MarcellThoth

The option is getting exercised when it's delisted, BacktestingBrokerage->OptionNotificationEventArgs->BTH->HandleOptionNotification. There are a couple of side effects I can see, (A) OptionPortfolioModel if SettlementType.Cash it's using the underlying.Close to calculate cash & DefaultExerciseModel using underlying.Close to determine if ITM or not

Martin-Molinero avatar Jun 07 '24 19:06 Martin-Molinero

Could use https://github.com/QuantConnect/Lean/issues/1608 Maybe

Security.cs
        /// <summary>
        ///
        /// </summary>
        public virtual Session Session => Cache.Session;

SecurityCache.cs
        /// <summary>
        ///
        /// </summary>
        public Session Session { get; private set; }
    - handles the updates

class Session : IBar
	Volume

Martin-Molinero avatar Feb 21 '25 15:02 Martin-Molinero