コード例 #1
0
        public override void Initialize()
        {
            this.SetStartDate(2017, 1, 1);
            this.SetEndDate(2017, 6, 28);
            this.SetCash(25000);
            this.LogCust("PERIOD: 2017");
            // ----------------------------------------------------------------------
            // Algo params
            // ----------------------------------------------------------------------
            this.MAX_EXPIRY = 30;
            this._no_K      = 2;
            this.resol      = Resolution.Minute;
            this.tkr        = SPY;
            // ----------------------------------------------------------------------
            // add underlying Equity
            equity = this.AddEquity(this.tkr, this.resol);
            equity.SetDataNormalizationMode(DataNormalizationMode.Raw);
            this.equity_symbol = equity.Symbol;
            // Add options
            var option = this.AddOption(this.tkr, this.resol);

            this.option_symbol = option.Symbol;
            // set our strike/expiry filter for this option chain
            option.SetFilter(this.UniverseFunc);
            // for greeks and pricer (needs some warmup) - https://github.com/QuantConnect/Lean/blob/21cd972e99f70f007ce689bdaeeafe3cb4ea9c77/Common/Securities/Option/OptionPriceModels.cs#L81
            option.PriceModel = OptionPriceModels.CrankNicolsonFD();
            // this is needed for Greeks calcs
            this.SetWarmUp(TimeSpan.FromDays(3));
            this.call = null;
            this.put  = null;
            Combo straddle;

            OrderTickets.Add(new OrderTicketInfo2 {
                EquityUnderlying = equity
            });
            OrderTickets.Add(new OrderTicketInfo2 {
                EquityUnderlying = equity
            });
            // -----------------------------------------------------------------------------
            // scheduled functions
            // -----------------------------------------------------------------------------
            this.Schedule.On(this.DateRules.EveryDay(this.equity_symbol), this.TimeRules.AfterMarketOpen(this.equity_symbol, 60), new Action(this.CloseOptionsOpen));
            this.Schedule.On(this.DateRules.EveryDay(this.equity_symbol), this.TimeRules.BeforeMarketClose(this.equity_symbol, 10), new Action(this.closeOptionsClose));
        }