Lean  $LEAN_TAG$
OptionExerciseOrder.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
20 
21 namespace QuantConnect.Orders
22 {
23  /// <summary>
24  /// Option exercise order type definition
25  /// </summary>
26  public class OptionExerciseOrder : Order
27  {
28  /// <summary>
29  /// Added a default constructor for JSON Deserialization:
30  /// </summary>
32  {
33  }
34 
35  /// <summary>
36  /// New option exercise order constructor. We model option exercising as an underlying asset long/short order with strike equal to limit price.
37  /// This means that by exercising a call we get into long asset position, by exercising a put we get into short asset position.
38  /// </summary>
39  /// <param name="symbol">Option symbol we're seeking to exercise</param>
40  /// <param name="quantity">Quantity of the option we're seeking to exercise. Must be a positive value.</param>
41  /// <param name="time">Time the order was placed</param>
42  /// <param name="tag">User defined data tag for this order</param>
43  /// <param name="properties">The order properties for this order</param>
44  public OptionExerciseOrder(Symbol symbol, decimal quantity, DateTime time, string tag = "", IOrderProperties properties = null)
45  : base(symbol, quantity, time, tag, properties)
46  {
47  }
48 
49  /// <summary>
50  /// Option Exercise Order Type
51  /// </summary>
52  public override OrderType Type
53  {
54  get { return OrderType.OptionExercise; }
55  }
56 
57  /// <summary>
58  /// Gets the order value in option contracts quoted in options's currency
59  /// </summary>
60  /// <param name="security">The security matching this order's symbol</param>
61  protected override decimal GetValueImpl(Security security)
62  {
63  var option = (Option)security;
64 
65  return option.GetExerciseQuantity(Quantity) * Price / option.SymbolProperties.ContractMultiplier;
66  }
67 
68  /// <summary>
69  /// Creates a deep-copy clone of this order
70  /// </summary>
71  /// <returns>A copy of this order</returns>
72  public override Order Clone()
73  {
74  var order = new OptionExerciseOrder();
75  CopyTo(order);
76  return order;
77  }
78  }
79 }