Lean  $LEAN_TAG$
OptionPriceModelResult.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 
17 using System;
18 
20 {
21  /// <summary>
22  /// Result type for <see cref="IOptionPriceModel.Evaluate"/>
23  /// </summary>
25  {
26  /// <summary>
27  /// Represents the zero option price and greeks.
28  /// </summary>
29  public static OptionPriceModelResult None { get; } = new(0, new Greeks());
30 
31  private readonly Lazy<Greeks> _greeks;
32  private readonly Lazy<decimal> _impliedVolatility;
33 
34  /// <summary>
35  /// Gets the theoretical price as computed by the <see cref="IOptionPriceModel"/>
36  /// </summary>
37  public decimal TheoreticalPrice
38  {
39  get; private set;
40  }
41 
42  /// <summary>
43  /// Gets the implied volatility of the option contract
44  /// </summary>
45  public decimal ImpliedVolatility
46  {
47  get
48  {
49  return _impliedVolatility.Value;
50  }
51  }
52 
53  /// <summary>
54  /// Gets the various sensitivities as computed by the <see cref="IOptionPriceModel"/>
55  /// </summary>
56  public Greeks Greeks
57  {
58  get
59  {
60  return _greeks.Value;
61  }
62  }
63 
64  /// <summary>
65  /// Initializes a new instance of the <see cref="OptionPriceModelResult"/> class
66  /// </summary>
67  /// <param name="theoreticalPrice">The theoretical price computed by the price model</param>
68  /// <param name="greeks">The sensitivities (greeks) computed by the price model</param>
69  public OptionPriceModelResult(decimal theoreticalPrice, Greeks greeks)
70  {
71  TheoreticalPrice = theoreticalPrice;
72  _impliedVolatility = new Lazy<decimal>(() => 0m);
73  _greeks = new Lazy<Greeks>(() => greeks);
74  }
75 
76  /// <summary>
77  /// Initializes a new instance of the <see cref="OptionPriceModelResult"/> class with lazy calculations of implied volatility and greeks
78  /// </summary>
79  /// <param name="theoreticalPrice">The theoretical price computed by the price model</param>
80  /// <param name="impliedVolatility">The calculated implied volatility</param>
81  /// <param name="greeks">The sensitivities (greeks) computed by the price model</param>
82  public OptionPriceModelResult(decimal theoreticalPrice, Func<decimal> impliedVolatility, Func<Greeks> greeks)
83  {
84  TheoreticalPrice = theoreticalPrice;
85  _impliedVolatility = new Lazy<decimal>(impliedVolatility);
86  _greeks = new Lazy<Greeks>(greeks);
87  }
88  }
89 }