/// <summary>
        /// Initializes a new instance of the <see cref="FineFundamentalFilteredUniverse"/> class
        /// </summary>
        /// <param name="universe">The universe to be filtered</param>
        /// <param name="fineSelector">The fine selection function</param>
        public FineFundamentalFilteredUniverse(Universe universe, PyObject fineSelector)
            : base(universe, universe.SelectSymbols)
        {
            var func = fineSelector.ConvertToDelegate <Func <IEnumerable <FineFundamental>, Symbol[]> >();

            FineFundamentalUniverse = new FineFundamentalUniverse(universe.UniverseSettings, universe.SecurityInitializer, func);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FineFundamentalFilteredUniverse"/> class
        /// </summary>
        /// <param name="universe">The universe to be filtered</param>
        /// <param name="fineSelector">The fine selection function</param>
        public FineFundamentalFilteredUniverse(Universe universe, PyObject fineSelector)
            : base(universe, universe.SelectSymbols)
        {
            var func = fineSelector.ConvertToDelegate <Func <IEnumerable <FineFundamental>, Symbol[]> >();

            FineFundamentalUniverse = new FineFundamentalUniverse(universe.UniverseSettings, func);
            FineFundamentalUniverse.SelectionChanged += (sender, args) => OnSelectionChanged(((SelectionEventArgs)args).CurrentSelection);
        }
Exemple #3
0
        /// <summary>
        /// Gets an enumerable of opened <see cref="OrderTicket"/> matching the specified <paramref name="filter"/>
        /// However, this method can be confused with the override that takes a Symbol as parameter. For this reason
        /// it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it
        /// assumes the parameter is a Python function object and not a Python representation of a Symbol.
        /// </summary>
        /// <param name="filter">The Python function filter used to find the required order tickets</param>
        /// <returns>An enumerable of opened <see cref="OrderTicket"/> matching the specified <paramref name="filter"/></returns>
        public IEnumerable <OrderTicket> GetOpenOrderTickets(PyObject filter)
        {
            Symbol pythonSymbol;

            if (filter.TryConvert(out pythonSymbol))
            {
                return(GetOpenOrderTickets(pythonSymbol));
            }
            return(_orderProcessor.GetOpenOrderTickets(filter.ConvertToDelegate <Func <OrderTicket, bool> >()));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomUniverseSelectionModel"/> class
 /// </summary>
 /// <param name="securityType">The security type of the universe</param>
 /// <param name="name">A unique name for this universe</param>
 /// <param name="market">The market of the universe</param>
 /// <param name="selector">Function delegate that accepts a DateTime and returns a collection of string symbols</param>
 /// <param name="universeSettings">The settings used when adding symbols to the algorithm, specify null to use algorithm.UniverseSettings</param>
 public CustomUniverseSelectionModel(SecurityType securityType, string name, string market, PyObject selector, UniverseSettings universeSettings, TimeSpan interval)
     : this(
         securityType,
         name,
         market,
         selector.ConvertToDelegate <Func <DateTime, object> >().ConvertToUniverseSelectionStringDelegate(),
         universeSettings,
         interval
         )
 {
 }
Exemple #5
0
        /// <summary>
        /// Gets open orders matching the specified filter. However, this method can be confused with the
        /// override that takes a Symbol as parameter. For this reason it first checks if it can convert
        /// the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is
        /// a Python function object and not a Python representation of a Symbol.
        /// </summary>
        /// <param name="filter">Python function object used to filter the orders</param>
        /// <returns>All filtered open orders this order provider currently holds</returns>
        public List <Order> GetOpenOrders(PyObject filter)
        {
            Symbol pythonSymbol;

            if (filter.TryConvert(out pythonSymbol))
            {
                return(GetOpenOrders(pythonSymbol));
            }
            Func <Order, bool> csharpFilter = filter.ConvertToDelegate <Func <Order, bool> >();

            return(_orderProcessor.GetOpenOrders(x => csharpFilter(x)));
        }
Exemple #6
0
        /// <summary>
        /// Creates a new universe and adds it to the algorithm
        /// </summary>
        /// <param name="dataType">The data type</param>
        /// <param name="securityType">The security type the universe produces</param>
        /// <param name="name">A unique name for this universe</param>
        /// <param name="resolution">The epected resolution of the universe data</param>
        /// <param name="market">The market for selected symbols</param>
        /// <param name="universeSettings">The subscription settings to use for newly created subscriptions</param>
        /// <param name="pySelector">Function delegate that performs selection on the universe data</param>
        public void AddUniverse(Type dataType, SecurityType securityType, string name, Resolution resolution, string market, UniverseSettings universeSettings, PyObject pySelector)
        {
            var marketHoursDbEntry = MarketHoursDatabase.GetEntry(market, name, securityType);
            var dataTimeZone       = marketHoursDbEntry.DataTimeZone;
            var exchangeTimeZone   = marketHoursDbEntry.ExchangeHours.TimeZone;
            var symbol             = QuantConnect.Symbol.Create(name, securityType, market);
            var config             = new SubscriptionDataConfig(dataType, symbol, resolution, dataTimeZone, exchangeTimeZone, false, false, true, true, isFilteredSubscription: false);

            var selector = pySelector.ConvertToDelegate <Func <IEnumerable <IBaseData>, object[]> >();

            AddUniverse(new FuncUniverse(config, universeSettings, SecurityInitializer, d => selector(d)
                                         .Select(x => x is Symbol ? (Symbol)x : QuantConnect.Symbol.Create((string)x, securityType, market))));
        }
        /// <summary>
        /// Constructor that takes as a parameter the security used to seed the price
        /// </summary>
        /// <param name="seedFunction">The seed function to use</param>
        public FuncSecuritySeeder(PyObject seedFunction)
        {
            var result = seedFunction.ConvertToDelegate <Func <Security, object> >();

            _seedFunction = security =>
            {
                var dataObject = result(security);
                var dataPoint  = dataObject as BaseData;
                if (dataPoint != null)
                {
                    return(new[] { dataPoint });
                }

                return((IEnumerable <BaseData>)dataObject);
            };
        }
Exemple #8
0
 /// <summary>
 /// Gets all orders matching the specified filter.
 /// </summary>
 /// <param name="filter">Python function object used to filter the orders</param>
 /// <returns>All orders this order provider currently holds by the specified filter</returns>
 public IEnumerable <Order> GetOrders(PyObject filter)
 {
     return(_orderProcessor.GetOrders(filter.ConvertToDelegate <Func <Order, bool> >()));
 }
Exemple #9
0
        /// <summary>
        /// Creates a new user defined universe that will fire on the requested resolution during market hours.
        /// </summary>
        /// <param name="securityType">The security type of the universe</param>
        /// <param name="name">A unique name for this universe</param>
        /// <param name="resolution">The resolution this universe should be triggered on</param>
        /// <param name="market">The market of the universe</param>
        /// <param name="universeSettings">The subscription settings used for securities added from this universe</param>
        /// <param name="pySelector">Function delegate that accepts a DateTime and returns a collection of string symbols</param>
        public void AddUniverse(SecurityType securityType, string name, Resolution resolution, string market, UniverseSettings universeSettings, PyObject pySelector)
        {
            var selector = pySelector.ConvertToDelegate <Func <DateTime, object[]> >();

            AddUniverse(securityType, name, resolution, market, universeSettings, d => selector(d).Select(x => (string)x));
        }
Exemple #10
0
        /// <summary>
        /// Creates a new universe and adds it to the algorithm. This can be used to return a list of string
        /// symbols retrieved from anywhere and will loads those symbols under the US Equity market.
        /// </summary>
        /// <param name="name">A unique name for this universe</param>
        /// <param name="pySelector">Function delegate that accepts a DateTime and returns a collection of string symbols</param>
        public void AddUniverse(string name, PyObject pySelector)
        {
            var selector = pySelector.ConvertToDelegate <Func <DateTime, object[]> >();

            AddUniverse(name, d => selector(d).Select(x => (string)x));
        }
 /// <summary>
 /// Python helper method to set the rebalancing function.
 /// This is required due to a python net limitation being able to use the base type constructor
 /// </summary>
 /// <param name="rebalancingFunc">For a given algorithm UTC DateTime returns the next expected rebalance time</param>
 protected void SetRebalancingFunc(PyObject rebalancingFunc)
 {
     _rebalancingFunc = rebalancingFunc.ConvertToDelegate <Func <DateTime, DateTime?> >();
 }