/// <summary>
 /// Initializes a new instance of the <see cref="UserDefinedUniverse"/> class
 /// </summary>
 /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="interval">The interval at which selection should be performed</param>
 /// <param name="symbols">The initial set of symbols in this universe</param>
 public UserDefinedUniverse(SubscriptionDataConfig configuration, UniverseSettings universeSettings, ISecurityInitializer securityInitializer, TimeSpan interval, IEnumerable<Symbol> symbols)
     : base(configuration, securityInitializer)
 {
     _interval = interval;
     _symbols = symbols.ToHashSet();
     _universeSettings = universeSettings;
     _selector = time => _symbols;
 }
 /// <summary>
 /// Creates a new coarse universe that contains the top count of stocks
 /// by daily dollar volume
 /// </summary>
 /// <param name="count">The number of stock to select</param>
 /// <param name="universeSettings">The settings for stocks added by this universe.
 /// Defaults to <see cref="QCAlgorithm.UniverseSettings"/></param>
 /// <returns>A new coarse universe for the top count of stocks by dollar volume</returns>
 public Universe Top(int count, UniverseSettings universeSettings = null)
 {
     universeSettings = universeSettings ?? _algorithm.UniverseSettings;
     var symbol = CoarseFundamental.CreateUniverseSymbol(Market.USA);
     var config = new SubscriptionDataConfig(typeof(CoarseFundamental), symbol, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, true);
     return new FuncUniverse(config, universeSettings, selectionData => (
         from c in selectionData.OfType<CoarseFundamental>()
         orderby c.DollarVolume descending 
         select c.Symbol).Take(count)
         );
 }
 /// <summary>
 /// Creates a new coarse universe that contains the bottom count of stocks
 /// by daily dollar volume
 /// </summary>
 /// <param name="count">The number of stock to select</param>
 /// <param name="universeSettings">The settings for stocks added by this universe.
 /// Defaults to <see cref="QCAlgorithm.UniverseSettings"/></param>
 /// <returns>A new coarse universe for the bottom count of stocks by dollar volume</returns>
 public Universe Bottom(int count, UniverseSettings universeSettings = null)
 {
     universeSettings = universeSettings ?? _algorithm.UniverseSettings;
     var symbol = Symbol.Create("us-equity-dollar-volume-bottom-" + count, SecurityType.Equity, Market.USA);
     var config = new SubscriptionDataConfig(typeof(CoarseFundamental), symbol, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, true);
     return new FuncUniverse(config, universeSettings, _algorithm.SecurityInitializer, selectionData => (
         from c in selectionData.OfType<CoarseFundamental>()
         orderby c.DollarVolume descending 
         select c.Symbol).Take(count)
         );
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserDefinedUniverse"/> class
 /// </summary>
 /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="interval">The interval at which selection should be performed</param>
 /// <param name="selector">Universe selection function invoked for each time returned via GetTriggerTimes.
 /// The function parameter is a DateTime in the time zone of configuration.ExchangeTimeZone</param>
 public UserDefinedUniverse(SubscriptionDataConfig configuration, UniverseSettings universeSettings, ISecurityInitializer securityInitializer, TimeSpan interval, Func<DateTime,IEnumerable<string>> selector)
     : base(configuration, securityInitializer)
 {
     _interval = interval;
     _universeSettings = universeSettings;
     _selector = time =>
     {
         var selectSymbolsResult = selector(time.ConvertFromUtc(Configuration.ExchangeTimeZone));
         // if we received an unchaged then short circuit the symbol creation and return it directly
         if (ReferenceEquals(selectSymbolsResult, Unchanged)) return Unchanged;
         return selectSymbolsResult.Select(sym => Symbol.Create(sym, Configuration.SecurityType, Configuration.Market));
     };
 }
 /// <summary>
 /// Creates a new universe for the constituents of the ETF provided as <paramref name="symbol"/>
 /// </summary>
 /// <param name="symbol">The ETF to load constituents for</param>
 /// <param name="universeSettings">Universe settings</param>
 /// <param name="constituentsFilter">The filter function used to filter out ETF constituents from the universe</param>
 public ETFConstituentsUniverse(Symbol symbol, UniverseSettings universeSettings, PyObject constituentsFilter = null)
     : this(symbol, universeSettings, constituentsFilter.ConvertPythonUniverseFilterFunction <ETFConstituentData>())
 {
 }
 /// <summary>
 /// Creates a new universe for the constituents of the ETF provided as <paramref name="symbol"/>
 /// </summary>
 /// <param name="symbol">The ETF to load constituents for</param>
 /// <param name="universeSettings">Universe settings</param>
 /// <param name="constituentsFilter">The filter function used to filter out ETF constituents from the universe</param>
 public ETFConstituentsUniverse(Symbol symbol, UniverseSettings universeSettings, Func <IEnumerable <ETFConstituentData>, IEnumerable <Symbol> > constituentsFilter = null)
     : base(CreateConstituentUniverseETFSymbol(symbol), universeSettings, constituentsFilter ?? (constituents => constituents.Select(c => c.Symbol)))
 {
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduledUniverse"/> class
 /// </summary>
 /// <param name="dateRule">Date rule defines what days the universe selection function will be invoked</param>
 /// <param name="timeRule">Time rule defines what times on each day selected by date rule the universe selection function will be invoked</param>
 /// <param name="selector">Selector function accepting the date time firing time and returning the universe selected symbols</param>
 /// <param name="settings">Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings</param>
 /// <param name="securityInitializer">Security initializer for new securities created via this universe, null will default to algorithm's security initializer</param>
 public ScheduledUniverse(IDateRule dateRule, ITimeRule timeRule, PyObject selector, UniverseSettings settings = null, ISecurityInitializer securityInitializer = null)
     : this(TimeZones.NewYork, dateRule, timeRule, selector, settings, securityInitializer)
 {
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoarseFundamentalUniverse"/> class
 /// </summary>
 /// <param name="symbol">Defines the symbol to use for this universe</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public CoarseFundamentalUniverse(Symbol symbol, UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func <IEnumerable <CoarseFundamental>, IEnumerable <Symbol> > selector)
     : base(CreateConfiguration(symbol), securityInitializer)
 {
     _universeSettings = universeSettings;
     _selector         = selector;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FuncUniverse{T}"/> class for a filter function loaded from Python
 /// </summary>
 /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="universeSelector">Function that returns the symbols that should be included in the universe</param>
 public FuncUniverse(SubscriptionDataConfig configuration, UniverseSettings universeSettings, PyObject universeSelector)
     : this(configuration, universeSettings, ConvertPythonUniverseFilterFunction(universeSelector))
 {
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionChainUniverse"/> class
 /// </summary>
 /// <param name="option">The canonical option chain security</param>
 /// <param name="universeSettings">The universe settings to be used for new subscriptions</param>
 /// <param name="securityInitializer">The security initializer to use on newly created securities</param>
 public OptionChainUniverse(Option option, UniverseSettings universeSettings, ISecurityInitializer securityInitializer = null)
     : base(option.SubscriptionDataConfig, securityInitializer)
 {
     _option = option;
     _universeSettings = universeSettings;
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduledUniverse"/> class
 /// </summary>
 /// <param name="timeZone">The time zone the date/time rules are in</param>
 /// <param name="dateRule">Date rule defines what days the universe selection function will be invoked</param>
 /// <param name="timeRule">Time rule defines what times on each day selected by date rule the universe selection function will be invoked</param>
 /// <param name="selector">Selector function accepting the date time firing time and returning the universe selected symbols</param>
 /// <param name="settings">Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings</param>
 public ScheduledUniverse(DateTimeZone timeZone, IDateRule dateRule, ITimeRule timeRule, Func <DateTime, IEnumerable <Symbol> > selector, UniverseSettings settings = null)
     : base(CreateConfiguration(timeZone, dateRule, timeRule))
 {
     _dateRule        = dateRule;
     _timeRule        = timeRule;
     _selector        = selector;
     UniverseSettings = settings;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FineFundamentalUniverse"/> class
 /// </summary>
 /// <param name="symbol">Defines the symbol to use for this universe</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public FineFundamentalUniverse(Symbol symbol, UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func<IEnumerable<FineFundamental>, IEnumerable<Symbol>> selector)
     : base(CreateConfiguration(symbol), securityInitializer)
 {
     _universeSettings = universeSettings;
     _selector = selector;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FineFundamentalUniverse"/> class
 /// </summary>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public FineFundamentalUniverse(UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func<IEnumerable<FineFundamental>, IEnumerable<Symbol>> selector)
     : base(CreateConfiguration(FineFundamental.CreateUniverseSymbol(QuantConnect.Market.USA)), securityInitializer)
 {
     _universeSettings = universeSettings;
     _selector = selector;
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FineFundamentalUniverse"/> class
 /// </summary>
 /// <param name="symbol">Defines the symbol to use for this universe</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public FineFundamentalUniverse(Symbol symbol, UniverseSettings universeSettings, Func <IEnumerable <FineFundamental>, IEnumerable <Symbol> > selector)
     : base(CreateConfiguration(symbol))
 {
     _universeSettings = universeSettings;
     _selector         = selector;
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FineFundamentalUniverse"/> class
 /// </summary>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public FineFundamentalUniverse(UniverseSettings universeSettings, Func <IEnumerable <FineFundamental>, IEnumerable <Symbol> > selector)
     : base(CreateConfiguration(FineFundamental.CreateUniverseSymbol(QuantConnect.Market.USA)))
 {
     _universeSettings = universeSettings;
     _selector         = selector;
 }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScheduledUniverse"/> class
        /// </summary>
        /// <param name="timeZone">The time zone the date/time rules are in</param>
        /// <param name="dateRule">Date rule defines what days the universe selection function will be invoked</param>
        /// <param name="timeRule">Time rule defines what times on each day selected by date rule the universe selection function will be invoked</param>
        /// <param name="selector">Selector function accepting the date time firing time and returning the universe selected symbols</param>
        /// <param name="settings">Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings</param>
        /// <param name="securityInitializer">Security initializer for new securities created via this universe, null will default to algorithm's security initializer</param>
        public ScheduledUniverse(DateTimeZone timeZone, IDateRule dateRule, ITimeRule timeRule, PyObject selector, UniverseSettings settings = null, ISecurityInitializer securityInitializer = null)
            : base(CreateConfiguration(timeZone, dateRule, timeRule))
        {
            Func <DateTime, Symbol[]> func;

            selector.TryConvertToDelegate(out func);
            _dateRule        = dateRule;
            _timeRule        = timeRule;
            _selector        = func;
            UniverseSettings = settings;
        }
        /// <summary>
        /// Creates a new coarse universe that contains stocks in the specified
        /// dollar volume percentile
        /// </summary>
        /// <param name="percentile">The desired dollar volume percentile (0 to 100 inclusive)</param>
        /// <param name="universeSettings">The settings for stocks added by this universe.
        /// Defaults to <see cref="QCAlgorithm.UniverseSettings"/></param>
        /// <returns>A new coarse universe for the bottom count of stocks by dollar volume</returns>
        public Universe Percentile(double percentile, UniverseSettings universeSettings = null)
        {
            universeSettings = universeSettings ?? _algorithm.UniverseSettings;
            var symbol = Symbol.Create("us-equity-dollar-volume-percentile-" + percentile, SecurityType.Equity, Market.USA);
            var config = new SubscriptionDataConfig(typeof(CoarseFundamental), symbol, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, true);
            return new FuncUniverse(config, universeSettings, _algorithm.SecurityInitializer, selectionData =>
            {
                var list = selectionData as IReadOnlyList<CoarseFundamental> ?? selectionData.OfType<CoarseFundamental>().ToList();

                // using quantiles since the Percentile implementation requires integers, so scale into quantile space
                var lowerBound = (decimal)list.Select(x => (double)x.DollarVolume).Quantile(percentile / 100d);

                return from c in list
                       where c.DollarVolume >= lowerBound
                       orderby c.DollarVolume descending
                       select c.Symbol;
            });
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduledUniverse"/> class
 /// </summary>
 /// <param name="dateRule">Date rule defines what days the universe selection function will be invoked</param>
 /// <param name="timeRule">Time rule defines what times on each day selected by date rule the universe selection function will be invoked</param>
 /// <param name="selector">Selector function accepting the date time firing time and returning the universe selected symbols</param>
 /// <param name="settings">Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings</param>
 public ScheduledUniverse(IDateRule dateRule, ITimeRule timeRule, Func <DateTime, IEnumerable <Symbol> > selector, UniverseSettings settings = null)
     : this(TimeZones.NewYork, dateRule, timeRule, selector, settings)
 {
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FuncUniverse{T}"/> class
 /// </summary>
 /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="universeSelector">Returns the symbols that should be included in the universe</param>
 public FuncUniverse(SubscriptionDataConfig configuration, UniverseSettings universeSettings, Func <IEnumerable <T>, IEnumerable <Symbol> > universeSelector)
     : base(configuration)
 {
     _universeSelector = universeSelector;
     _universeSettings = universeSettings;
 }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScheduledUniverse"/> class
        /// </summary>
        /// <param name="timeZone">The time zone the date/time rules are in</param>
        /// <param name="dateRule">Date rule defines what days the universe selection function will be invoked</param>
        /// <param name="timeRule">Time rule defines what times on each day selected by date rule the universe selection function will be invoked</param>
        /// <param name="selector">Selector function accepting the date time firing time and returning the universe selected symbols</param>
        /// <param name="settings">Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings</param>
        public ScheduledUniverse(DateTimeZone timeZone, IDateRule dateRule, ITimeRule timeRule, PyObject selector, UniverseSettings settings = null)
            : base(CreateConfiguration(timeZone, dateRule, timeRule))
        {
            Func <DateTime, object> func;

            selector.TryConvertToDelegate(out func);
            _dateRule        = dateRule;
            _timeRule        = timeRule;
            _selector        = func.ConvertToUniverseSelectionSymbolDelegate();
            UniverseSettings = settings;
        }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoarseFundamentalUniverse"/> class
 /// </summary>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public CoarseFundamentalUniverse(UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func <IEnumerable <CoarseFundamental>, IEnumerable <Symbol> > selector)
     : base(CreateConfiguration(CoarseFundamental.CreateUniverseSymbol(QuantConnect.Market.USA)), securityInitializer)
 {
     _universeSettings = universeSettings;
     _selector         = selector;
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduledUniverse"/> class
 /// </summary>
 /// <param name="dateRule">Date rule defines what days the universe selection function will be invoked</param>
 /// <param name="timeRule">Time rule defines what times on each day selected by date rule the universe selection function will be invoked</param>
 /// <param name="selector">Selector function accepting the date time firing time and returning the universe selected symbols</param>
 /// <param name="settings">Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings</param>
 public ScheduledUniverse(IDateRule dateRule, ITimeRule timeRule, PyObject selector, UniverseSettings settings = null)
     : this(TimeZones.NewYork, dateRule, timeRule, selector, settings)
 {
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionChainUniverse"/> class
 /// </summary>
 /// <param name="option">The canonical option chain security</param>
 /// <param name="universeSettings">The universe settings to be used for new subscriptions</param>
 /// <param name="securityInitializer">The security initializer to use on newly created securities</param>
 public OptionChainUniverse(Option option, UniverseSettings universeSettings, ISecurityInitializer securityInitializer = null)
     : base(option.SubscriptionDataConfig, securityInitializer)
 {
     _option           = option;
     _universeSettings = universeSettings;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CoarseFundamentalUniverse"/> class
 /// </summary>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="selector">Returns the symbols that should be included in the universe</param>
 public CoarseFundamentalUniverse(UniverseSettings universeSettings, ISecurityInitializer securityInitializer, PyObject selector)
     : this(CoarseFundamental.CreateUniverseSymbol(QuantConnect.Market.USA), universeSettings, securityInitializer, selector)
 {
 }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FuncUniverse"/> class
 /// </summary>
 /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="universeSelector">Returns the symbols that should be included in the universe</param>
 public FuncUniverse(SubscriptionDataConfig configuration, UniverseSettings universeSettings, Func<IEnumerable<BaseData>, IEnumerable<Symbol>> universeSelector)
     : base(configuration)
 {
     _universeSelector = universeSelector;
     _universeSettings = universeSettings;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FuncUniverse"/> class
 /// </summary>
 /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
 /// <param name="universeSettings">The settings used for new subscriptions generated by this universe</param>
 /// <param name="securityInitializer">Initializes securities when they're added to the universe</param>
 /// <param name="universeSelector">Returns the symbols that should be included in the universe</param>
 public FuncUniverse(SubscriptionDataConfig configuration, UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func <IEnumerable <BaseData>, IEnumerable <Symbol> > universeSelector)
     : base(configuration, securityInitializer)
 {
     _universeSelector = universeSelector;
     _universeSettings = universeSettings;
 }