QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.58k stars 3.23k forks source link

The Option SetFilter() method throws "out of range" error for "GOOG" #1875

Closed jingwu74 closed 6 years ago

jingwu74 commented 6 years ago

For GOOG options from 04/06/2016 to 04/08/2016, the SetFilter(minStrike, maxStrike) method with negative maxStrike input would throw error Runtime Error: Index was out of range. Must be non-negative and less than the size of the collection. The error occurs at 2016-04-07 19:57:00 and 2016-04-08 09:30:00 which is not trading hours for options.

Expected Behavior

SetFilter(minStrike, maxStrike) method should allow negative maxStrike input.

Actual Behavior

Negative maxStrike input in SetFilter() would throw errors of index out of range.

Reproducing the Problem

namespace QuantConnect.Algorithm.CSharp
{
    public class BasicTemplateOptionsAlgorithm : QCAlgorithm
    {
        public override void Initialize()
        {
            SetStartDate(2016, 4, 6);
            SetEndDate(2016, 4, 8);
            SetCash(100000);
            var equity = AddEquity("GOOG", Resolution.Minute);
            var option = AddOption("GOOG");
            option.SetFilter(-5, -1, TimeSpan.FromDays(14), TimeSpan.FromDays(50));
        }
        public override void OnData(Slice slice)
        {
        }
    }
}

System Information

Checklist

mchandschuh commented 6 years ago

Here's the stack trace from the log file:

2018-04-18T07:19:59.5254710Z ERROR:: <GetEnumerator>d__30.MoveNext():  System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00029] in <2e7c1c96edae44d496118948ca617c11>:0 
  at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <2e7c1c96edae44d496118948ca617c11>:0 
  at QuantConnect.Securities.OptionFilterUniverse.Strikes (System.Int32 minStrike, System.Int32 maxStrike) [0x00210] in <73bbe055aaca4ed2b65d2a6c066be466>:0 
  at QuantConnect.Securities.Option.Option+<>c__DisplayClass48_0.<SetFilter>b__0 (QuantConnect.Securities.OptionFilterUniverse universe) [0x00000] in <73bbe055aaca4ed2b65d2a6c066be466>:0 
  at QuantConnect.Securities.Option.Option+<>c__DisplayClass49_0.<SetFilter>b__0 (QuantConnect.Securities.IDerivativeSecurityFilterUniverse universe) [0x00008] in <73bbe055aaca4ed2b65d2a6c066be466>:0 
  at QuantConnect.Securities.FuncSecurityDerivativeFilter.Filter (QuantConnect.Securities.IDerivativeSecurityFilterUniverse universe) [0x00001] in <73bbe055aaca4ed2b65d2a6c066be466>:0 
  at QuantConnect.Data.UniverseSelection.OptionChainUniverse.SelectSymbols (System.DateTime utcTime, QuantConnect.Data.UniverseSelection.BaseDataCollection data) [0x000f0] in <73bbe055aaca4ed2b65d2a6c066be466>:0 
  at QuantConnect.Data.UniverseSelection.Universe.PerformSelection (System.DateTime utcTime, QuantConnect.Data.UniverseSelection.BaseDataCollection data) [0x00001] in <73bbe055aaca4ed2b65d2a6c066be466>:0 
  at QuantConnect.Lean.Engine.DataFeeds.UniverseSelection.ApplyUniverseSelection (QuantConnect.Data.UniverseSelection.Universe universe, System.DateTime dateTimeUtc, QuantConnect.Data.UniverseSelection.BaseDataCollection universeData) [0x00261] in <c12a76cb719c4a0a966d6175c3e5a213>:0 
  at QuantConnect.Lean.Engine.DataFeeds.SubscriptionSynchronizer.Sync (System.Collections.Generic.IEnumerable`1[T] subscriptions) [0x002be] in <c12a76cb719c4a0a966d6175c3e5a213>:0 
  at QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed+<GetEnumerator>d__30.MoveNext () [0x000c7] in <c12a76cb719c4a0a966d6175c3e5a213>:0