Options Models



If you exercise a long Option position or are assigned on your short Option position, LEAN processes an Option exercise order. The Option exercise model converts the Option exercise order into an OrderEvent.

Set Models

To set the exercise model of an Option, set the OptionExerciseModel property on the Option object.

// In Initialize
var option = AddOption("SPY");
option.OptionExerciseModel = new DefaultExerciseModel();
# In Initialize
option = AddOption("SPY")
option.OptionExerciseModel = DefaultExerciseModel()

Default Behavior

The default Option exercise model is the DefaultExerciseModel. The DefaultExerciseModel fills exercise orders to the full quantity with zero fees and applies an order tag to represent if the order is an exercise or assignment. To view the implementation of this model, see the LEAN GitHub repository.

Model Structure

Option exercise models should extend the DefaultExerciseModel class. Extensions of the DefaultExerciseModel class must implement the OptionExercise method, which receives Option and OptionExerciseOrder objects and then returns a list of OrderEvent objects that contain the order fill information.

public class MyExerciseModel : IOptionExerciseModel
    public IEnumerable<OrderEvent> OptionExercise(Option option, OptionExerciseOrder order)
        var inTheMoney = option.IsAutoExercised(option.Underlying.Close);
        var isAssignment = inTheMoney && option.Holdings.IsShort;

        yield return new OrderEvent(
        ) { IsAssignment = isAssignment }

LEAN doesn't currently support custom Option exercise models in Python. To track the feature progress, subscribe to GitHub Issue #6390.

OptionExerciseOrder objects have the following properties:

The following table describes the arguments of the OrderEvent constructor:

Argument Details

Argument: orderId

Id of the parent order

Data Type: int | Default Value: -

Argument: symbol

Asset Symbol

Data Type: Symbol | Default Value: -

Argument: utcTime

Date/time of this event

Data Type: DateTimedatetime | Default Value: -

Argument: direction

The direction of the order. The OrderDirection enumeration has the following members:

Data Type: OrderDirection | Default Value: Hold

Argument: fillPrice

Fill price information if applicable

Data Type: decimalfloat | Default Value: 0

Argument: fillQuantity

Fill quantity

Data Type: decimalfloat | Default Value: 0

Argument: orderFee

The order fee. You can use OrderFee.Zero or create an OrderFee object with a custom fee.

new OrderFee(new CashAmount(0.5m, "USD"));OrderFee(CashAmount(0.5, 'USD'))

Data Type: OrderFee | Default Value: -

Argument: message

Message from the exchange

Data Type: stringstr | Default Value: ""

OrderEvent objects have the following attributes:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: