/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using Python.Runtime; using QuantConnect.Data.Market; using System; namespace QuantConnect.Securities.Option { /// /// Result type for /// public class OptionPriceModelResult { /// /// Represents the zero option price and greeks. /// public static OptionPriceModelResult None { get; } = new(0, NullGreeks.Instance); private Lazy _theoreticalPrice; private Lazy _greeks; private Lazy _impliedVolatility; /// /// Gets the theoretical price as computed by the /// public decimal TheoreticalPrice { get { return _theoreticalPrice.Value; } set { _theoreticalPrice = new Lazy(() => value, isThreadSafe: false); } } /// /// Gets the implied volatility of the option contract /// public decimal ImpliedVolatility { get { return _impliedVolatility.Value; } set { _impliedVolatility = new Lazy(() => value, isThreadSafe: false); } } /// /// Gets the various sensitivities as computed by the /// public Greeks Greeks { get { return _greeks.Value; } set { _greeks = new Lazy(() => value, isThreadSafe: false); } } /// /// Initializes a new instance of the class /// public OptionPriceModelResult() { } /// /// Initializes a new instance of the class /// /// The theoretical price computed by the price model /// The sensitivities (greeks) computed by the price model public OptionPriceModelResult(decimal theoreticalPrice, Greeks greeks) : this(() => theoreticalPrice, () => decimal.Zero, () => greeks) { } /// /// Initializes a new instance of the class /// /// The theoretical price computed by the price model /// The calculated implied volatility /// The sensitivities (greeks) computed by the price model public OptionPriceModelResult(decimal theoreticalPrice, decimal impliedVolatility, Greeks greeks) : this(theoreticalPrice, () => impliedVolatility, () => greeks) { } /// /// Initializes a new instance of the class with lazy calculations of implied volatility and greeks /// /// The theoretical price computed by the price model /// The calculated implied volatility /// The sensitivities (greeks) computed by the price model public OptionPriceModelResult(decimal theoreticalPrice, Func impliedVolatility, Func greeks) : this(() => theoreticalPrice, impliedVolatility, greeks) { } /// /// Initializes a new instance of the class with lazy calculations of implied volatility and greeks /// /// The theoretical price computed by the price model /// The calculated implied volatility /// The sensitivities (greeks) computed by the price model public OptionPriceModelResult(Func theoreticalPrice, Func impliedVolatility, Func greeks) { _theoreticalPrice = new Lazy(theoreticalPrice, isThreadSafe: false); _impliedVolatility = new Lazy(impliedVolatility, isThreadSafe: false); _greeks = new Lazy(greeks, isThreadSafe: false); } /// /// Initializes a new instance of the class with lazy calculations of implied volatility and greeks /// /// The theoretical price computed by the price model /// The calculated implied volatility /// The sensitivities (greeks) computed by the price model public OptionPriceModelResult(decimal theoreticalPrice, PyObject impliedVolatility, PyObject greeks) : this(theoreticalPrice, impliedVolatility.SafeAs>(), greeks.SafeAs>()) { } } }