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 Probabilistic 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 -13.383 Tracking Error 0.067 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
using QuantConnect.Securities.Option; namespace QuantConnect { public class DemoAlgorithm : QCAlgorithm { private int _minExpiry = 0; private int _maxExpiry = 40; private int _minStrikePrice = -10; private int _maxStrikePrice = 10; private List<Symbol> _optionList = new List<Symbol>(); private List<Symbol> _stocks = new List<Symbol>(); public override void Initialize() { SetStartDate(2020, 1, 12); SetEndDate(2020, 1, 15); SetCash(100000); SetSecurityInitializer(x => x.SetDataNormalizationMode(DataNormalizationMode.Raw)); AddUniverse(MyCoarseFilterFunction); UniverseSettings.Resolution = Resolution.Minute; Schedule.On(DateRules.EveryDay(), TimeRules.At(9, 0), CustomFilter); } private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) { var stocks = coarse.Where(c => c.HasFundamentalData) .OrderBy(c => c.DollarVolume) .TakeLast(5); _stocks = stocks.Select(x => x.Symbol).ToList(); return _stocks; } private void CustomFilter() { _optionList.Clear(); foreach(var c in _stocks) { var contracts = OptionChainProvider.GetOptionContractList(c, Time); if (contracts.Count() == 0) continue; var atm_strike = contracts.OrderBy(x => Math.Abs(x.ID.StrikePrice - Securities[c].Price)) .Select(x => x.ID.StrikePrice) .ToList()[0]; var strike_list = contracts.OrderBy(x => x.ID.StrikePrice) .Select(x => x.ID.StrikePrice) .ToList(); var atm_strike_rank = strike_list.IndexOf(atm_strike); var filtered_contracts = contracts.Where(i => _minExpiry <= (i.ID.Date - Time).Days && (i.ID.Date - Time).Days <= _maxExpiry && i.ID.StrikePrice - Securities[i.Underlying].Price >= _minStrikePrice && i.ID.StrikePrice - Securities[i.Underlying].Price <= _maxStrikePrice && !OptionSymbol.IsWeekly(i)); foreach(var symbol in filtered_contracts) { var option = AddOptionContract(symbol); option.PriceModel = OptionPriceModels.CrankNicolsonFD(); _optionList.Add(option.Symbol); } } } public override void OnData(Slice data) { foreach(var chain in data.OptionChains) { var contracts = chain.Value; foreach(var contract in contracts) { if (_optionList.Contains(contract.Symbol) && contract.Greeks.Delta > 0.05m) { Log(contract.Symbol.Value); } } } } } }