Options Models

Exercise

Introduction

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(
            order.Id,
            option.Symbol,
            option.LocalTime.ConvertToUtc(option.Exchange.TimeZone),
            OrderStatus.Filled,
            GetOrderDirection(order.Quantity),
            0.0m,
            order.Quantity,
            OrderFee.Zero,
            "Tag"
        ) { IsAssignment = isAssignment }
    }
}

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

The following table describes the arguments of the OrderEvent constructor:

ArgumentData TypeDescriptionDefault Value
orderIdintId of the parent order
symbolSymbolAsset Symbol
utcTimeDateTimedatetimeDate/time of this event
directionOrderDirectionThe direction of the order
fillPricedecimalfloatFill price information if applicable
fillQuantitydecimalfloatFill quantity
orderFeeOrderFeeThe order fee
messagestringstrMessage from the exchange""

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: