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 { public class WeeklyOptionDataTest : QCAlgorithm { private int MAX_EXPIRY = 6; private Equity equity; private Symbol equity_symbol; private Symbol option_symbol; private Symbol _optionContract = string.Empty; /// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { SetStartDate(2018, 9, 1); //Set Start Date SetEndDate(2018, 10, 15); //Set End Date SetCash(100000); //Set Strategy Cash equity = AddEquity("SPY", Resolution.Minute); equity.SetDataNormalizationMode(DataNormalizationMode.Raw); // IMPORTANT: default equity_symbol = equity.Symbol; // Add options var option = AddOption("SPY", Resolution.Minute); option_symbol = option.Symbol; // Debug("Options Symbol: " + option.Symbol.ToString()); // set our strike/expiry filter for this option chain option.SetFilter(u => u.IncludeWeeklys() .Strikes(-1, 1) .Expiration(TimeSpan.Zero, TimeSpan.FromDays(6))); option.PriceModel = OptionPriceModels.CrankNicolsonFD(); /** * */ Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", 0), () => { var contracts = OptionChainProvider.GetOptionContractList(this.equity_symbol, Time); var underlyingPrice = Securities[this.equity_symbol].Price; var options = (from symbol in contracts where (symbol.ID.Date - Time).TotalDays < 6 select symbol); if(options.Count() != 0){ var _optionsContract = options.OrderBy(x => x.ID.Date) .ThenBy(x => (x.ID.StrikePrice - underlyingPrice)) .FirstOrDefault(); //Debug("Current time: "+Time.ToLongDateString()+", Symbol:"+_optionsContract +" Last trading date: "+_optionsContract.ID.Date.ToLongDateString()); Log("Current time: "+Time.ToLongDateString()+", Symbol:"+_optionsContract +" Last trading date: "+_optionsContract.ID.Date.ToLongDateString()); } else { //Debug("Current time: "+Time.ToLongDateString()+", No Weekly Found"); Log("Current time: "+Time.ToLongDateString()+", No Weekly Found"); } }); } /// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">Slice object keyed by symbol containing the stock data</param> public override void OnData(Slice data) { } } }