Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
using QuantConnect.Securities.Option; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// Option chain for a given underlying at a specified date, time. /// </summary> public class BasicTemplateOptionChain : QCAlgorithm { private const string UnderlyingTicker = "SPY"; public readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA); public readonly Symbol OptionSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA); private DateTime selDateTime = DateTime.ParseExact("2017-08-14 16:00", "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); private bool printedInfo = false; public override void Initialize() { SetStartDate(2017, 8, 14); SetEndDate(2017, 8, 14); SetWarmup(TimeSpan.FromDays(7)); SetCash(10000); var equity = AddEquity(UnderlyingTicker); var option = AddOption(UnderlyingTicker); equity.SetDataNormalizationMode(DataNormalizationMode.Raw); //option.PriceModel = OptionPriceModels.BlackScholes(); //option.PriceModel = OptionPriceModels.BinomialJoshi(); option.PriceModel = OptionPriceModels.BinomialJarrowRudd(); option.SetFilter(-10, +10, TimeSpan.FromDays(500), TimeSpan.FromDays(750)); // CAUTION: Match these columns with the Log in OnData! Log("TimeAndContract,Right,Expiry,Strike,Bid,Ask,Last,TheoreticalPrice,OI,Underlying,IV,HV"); } public override void OnData(Slice slice) { if (!printedInfo && Time >= selDateTime) { foreach (var chain in slice.OptionChains) { var underlying = Securities[chain.Key.Underlying]; foreach (var contract in chain.Value) { Log(String.Format(@"{0},{1},{2},{3:0.00},{4:0.000},{5:0.000},{6:0.000},{7:0.000},{8},{9:0.000},{10:0.0000},{11:0.0000}", contract.Symbol.Value, contract.Right, contract.Expiry, contract.Strike, contract.BidPrice, contract.AskPrice, contract.LastPrice, contract.TheoreticalPrice, contract.OpenInterest, contract.UnderlyingLastPrice, underlying.VolatilityModel.Volatility, contract.ImpliedVolatility)); } } printedInfo = true; } } } }