Example #1
0
        /// <summary>
        /// Sets the <see cref="ContractFilter"/> to a new universe selection function
        /// </summary>
        /// <param name="universeFunc">new universe selection function</param>
        public void SetFilter(PyObject universeFunc)
        {
            ContractFilter = new FuncSecurityDerivativeFilter(universe =>
            {
                var optionUniverse = universe as OptionFilterUniverse;
                using (Py.GIL())
                {
                    PyObject result = (universeFunc as dynamic)(optionUniverse);

                    //Try to convert it to the possible outcomes and process it
                    //Must try filter first, if it is a filter and you try and convert it to
                    //list, TryConvert() with catch an exception. Later Python algo will break on
                    //this exception because we are using Py.GIL() and it will see the error set
                    OptionFilterUniverse filter;
                    List <Symbol> list;

                    if ((result).TryConvert(out filter))
                    {
                        optionUniverse = filter;
                    }
                    else if ((result).TryConvert(out list))
                    {
                        optionUniverse = optionUniverse.WhereContains(list);
                    }
                    else
                    {
                        throw new ArgumentException($"QCAlgorithm.SetFilter: result type {result.GetPythonType()} from " +
                                                    $"filter function is not a valid argument, please return either a OptionFilterUniverse or a list of symbols");
                    }
                }
                return(optionUniverse.ApplyTypesFilter());
            });
        }
Example #2
0
 /// <summary>
 /// Sets the <see cref="ContractFilter"/> to a new universe selection function
 /// </summary>
 /// <param name="universeFunc">new universe selection function</param>
 public void SetFilter(Func <OptionFilterUniverse, OptionFilterUniverse> universeFunc)
 {
     ContractFilter = new FuncSecurityDerivativeFilter(universe =>
     {
         var optionUniverse = universe as OptionFilterUniverse;
         var result         = universeFunc(optionUniverse);
         return(result.ApplyOptionTypesFilter());
     });
 }
Example #3
0
        /// <summary>
        /// Sets the <see cref="ContractFilter"/> to a new universe selection function
        /// </summary>
        /// <param name="universeFunc">new universe selection function</param>
        public void SetFilter(Func <FutureFilterUniverse, FutureFilterUniverse> universeFunc)
        {
            Func <IDerivativeSecurityFilterUniverse, IDerivativeSecurityFilterUniverse> func = universe =>
            {
                var futureUniverse = universe as FutureFilterUniverse;
                return(universeFunc(futureUniverse));
            };

            ContractFilter = new FuncSecurityDerivativeFilter(func);
        }
Example #4
0
        /// <summary>
        /// Sets the <see cref="ContractFilter"/> to a new universe selection function
        /// </summary>
        /// <param name="universeFunc">new universe selection function</param>
        public void SetFilter(Func <FutureFilterUniverse, FutureFilterUniverse> universeFunc)
        {
            Func <IDerivativeSecurityFilterUniverse, IDerivativeSecurityFilterUniverse> func = universe =>
            {
                var futureUniverse = universe as FutureFilterUniverse;
                var result         = universeFunc(futureUniverse);
                return(result.ApplyTypesFilter());
            };

            ContractFilter = new FuncSecurityDerivativeFilter(func);
        }
Example #5
0
 /// <summary>
 /// Sets the <see cref="ContractFilter"/> to a new instance of the <see cref="StrikeExpiryOptionFilter"/>
 /// using the specified min and max strike and expiration range alues
 /// </summary>
 /// <param name="minStrike">The min strike rank relative to market price, for example, -1 would put
 /// a lower bound of one strike under market price, where a +1 would put a lower bound of one strike
 /// over market price</param>
 /// <param name="maxStrike">The max strike rank relative to market place, for example, -1 would put
 /// an upper bound of on strike under market price, where a +1 would be an upper bound of one strike
 /// over market price</param>
 /// <param name="minExpiry">The minimum time until expiry to include, for example, TimeSpan.FromDays(10)
 /// would exclude contracts expiring in less than 10 days</param>
 /// <param name="maxExpiry">The maxmium time until expiry to include, for example, TimeSpan.FromDays(10)
 /// would exclude contracts expiring in more than 10 days</param>
 public void SetFilter(int minStrike, int maxStrike, TimeSpan minExpiry, TimeSpan maxExpiry)
 {
     ContractFilter = new StrikeExpiryOptionFilter(minStrike, maxStrike, minExpiry, maxExpiry);
 }
Example #6
0
 /// <summary>
 /// Sets the <see cref="ContractFilter"/> to a new instance of the <see cref="StrikeExpiryOptionFilter"/>
 /// using the specified min and max strike and expiration range alues
 /// </summary>
 /// <param name="minStrike">The min strike rank relative to market price, for example, -1 would put
 /// a lower bound of one strike under market price, where a +1 would put a lower bound of one strike
 /// over market price</param>
 /// <param name="maxStrike">The max strike rank relative to market place, for example, -1 would put
 /// an upper bound of on strike under market price, where a +1 would be an upper bound of one strike
 /// over market price</param>
 /// <param name="minExpiry">The minimum time until expiry to include, for example, TimeSpan.FromDays(10)
 /// would exclude contracts expiring in less than 10 days</param>
 /// <param name="maxExpiry">The maxmium time until expiry to include, for example, TimeSpan.FromDays(10)
 /// would exclude contracts expiring in more than 10 days</param>
 public void SetFilter(int minStrike, int maxStrike, TimeSpan minExpiry, TimeSpan maxExpiry)
 {
     ContractFilter = new StrikeExpiryOptionFilter(minStrike, maxStrike, minExpiry, maxExpiry);
 }