/*
* 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 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 readonly Lazy _greeks;
private readonly Lazy _impliedVolatility;
///
/// Gets the theoretical price as computed by the
///
public decimal TheoreticalPrice
{
get; private set;
}
///
/// Gets the implied volatility of the option contract
///
public decimal ImpliedVolatility
{
get
{
return _impliedVolatility.Value;
}
}
///
/// Gets the various sensitivities as computed by the
///
public Greeks Greeks
{
get
{
return _greeks.Value;
}
}
///
/// 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)
{
TheoreticalPrice = theoreticalPrice;
_impliedVolatility = new Lazy(() => 0m, 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, Func impliedVolatility, Func greeks)
{
TheoreticalPrice = theoreticalPrice;
_impliedVolatility = new Lazy(impliedVolatility, isThreadSafe: false);
_greeks = new Lazy(greeks, isThreadSafe: false);
}
}
}