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.
OptionExerciseOrder
objects have the following properties:
The following table describes the arguments of the OrderEvent
constructor:
Argument Details |
---|
Argument: |
Argument: |
Argument: |
Argument: |
Argument: |
Argument: |
Argument: |
Argument: |
OrderEvent
objects have the following attributes: