/*
* 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 System;
using QuantConnect.Securities.Option;
namespace QuantConnect.Data.Market
{
///
/// Defines a single option contract at a specific expiration and strike price
///
public class OptionContract
{
private Lazy _optionPriceModelResult = new Lazy(() =>
new OptionPriceModelResult(0m, new Greeks()));
///
/// Gets the option contract's symbol
///
public Symbol Symbol
{
get; private set;
}
///
/// Gets the underlying security's symbol
///
public Symbol UnderlyingSymbol
{
get; private set;
}
///
/// Gets the strike price
///
public decimal Strike => Symbol.ID.StrikePrice;
///
/// Gets the expiration date
///
public DateTime Expiry => Symbol.ID.Date;
///
/// Gets the right being purchased (call [right to buy] or put [right to sell])
///
public OptionRight Right => Symbol.ID.OptionRight;
///
/// Gets the option style
///
public OptionStyle Style => Symbol.ID.OptionStyle;
///
/// Gets the theoretical price of this option contract as computed by the
///
public decimal TheoreticalPrice => _optionPriceModelResult.Value.TheoreticalPrice;
///
/// Gets the implied volatility of the option contract as computed by the
///
public decimal ImpliedVolatility => _optionPriceModelResult.Value.ImpliedVolatility;
///
/// Gets the greeks for this contract
///
public Greeks Greeks => _optionPriceModelResult.Value.Greeks;
///
/// Gets the local date time this contract's data was last updated
///
public DateTime Time
{
get; set;
}
///
/// Gets the open interest
///
public decimal OpenInterest
{
get; set;
}
///
/// Gets the last price this contract traded at
///
public decimal LastPrice
{
get; set;
}
///
/// Gets the last volume this contract traded at
///
public long Volume
{
get; set;
}
///
/// Gets the current bid price
///
public decimal BidPrice
{
get; set;
}
///
/// Get the current bid size
///
public long BidSize
{
get; set;
}
///
/// Gets the ask price
///
public decimal AskPrice
{
get; set;
}
///
/// Gets the current ask size
///
public long AskSize
{
get; set;
}
///
/// Gets the last price the underlying security traded at
///
public decimal UnderlyingLastPrice
{
get; set;
}
///
/// Initializes a new instance of the class
///
/// The option contract symbol
/// The symbol of the underlying security
public OptionContract(Symbol symbol, Symbol underlyingSymbol)
{
Symbol = symbol;
UnderlyingSymbol = underlyingSymbol;
}
///
/// Sets the option price model evaluator function to be used for this contract
///
/// Function delegate used to evaluate the option price model
internal void SetOptionPriceModel(Func optionPriceModelEvaluator)
{
_optionPriceModelResult = new Lazy(optionPriceModelEvaluator);
}
///
/// Returns a string that represents the current object.
///
///
/// A string that represents the current object.
///
public override string ToString() => Symbol.Value;
}
}