Lean  $LEAN_TAG$
OptionPayoff.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;
17 using System.Runtime.CompilerServices;
18 
19 namespace QuantConnect.Util
20 {
21  /// <summary>
22  /// Static class containing useful methods related with options payoff
23  /// </summary>
24  public static class OptionPayoff
25  {
26  /// <summary>
27  /// Intrinsic value function of the option
28  /// </summary>
29  /// <param name="underlyingPrice">The price of the underlying</param>
30  /// <param name="strike">The strike price of the option</param>
31  /// <param name="right">The option right of the option, call or put</param>
32  /// <returns>The intrinsic value remains for the option at expiry</returns>
33  [MethodImpl(MethodImplOptions.AggressiveInlining)]
34  public static decimal GetIntrinsicValue(decimal underlyingPrice, decimal strike, OptionRight right)
35  {
36  return Math.Max(0.0m, GetPayOff(underlyingPrice, strike, right));
37  }
38 
39  /// <summary>
40  /// Intrinsic value function of the option
41  /// </summary>
42  /// <param name="underlyingPrice">The price of the underlying</param>
43  /// <param name="strike">The strike price of the option</param>
44  /// <param name="right">The option right of the option, call or put</param>
45  /// <returns>The intrinsic value remains for the option at expiry</returns>
46  [MethodImpl(MethodImplOptions.AggressiveInlining)]
47  public static double GetIntrinsicValue(double underlyingPrice, double strike, OptionRight right)
48  {
49  return Math.Max(0.0, GetPayOff(underlyingPrice, strike, right));
50  }
51 
52  /// <summary>
53  /// Option payoff function at expiration time
54  /// </summary>
55  /// <param name="underlyingPrice">The price of the underlying</param>
56  /// <param name="strike">The strike price of the option</param>
57  /// <param name="right">The option right of the option, call or put</param>
58  /// <returns></returns>
59  [MethodImpl(MethodImplOptions.AggressiveInlining)]
60  public static decimal GetPayOff(decimal underlyingPrice, decimal strike, OptionRight right)
61  {
62  return right == OptionRight.Call ? underlyingPrice - strike : strike - underlyingPrice;
63  }
64 
65  /// <summary>
66  /// Option payoff function at expiration time
67  /// </summary>
68  /// <param name="underlyingPrice">The price of the underlying</param>
69  /// <param name="strike">The strike price of the option</param>
70  /// <param name="right">The option right of the option, call or put</param>
71  /// <returns></returns>
72  [MethodImpl(MethodImplOptions.AggressiveInlining)]
73  public static double GetPayOff(double underlyingPrice, double strike, OptionRight right)
74  {
75  return right == OptionRight.Call ? underlyingPrice - strike : strike - underlyingPrice;
76  }
77  }
78 }