def CreateUniverses(self, algorithm):
        '''Creates the universes for this algorithm. Called once after IAlgorithm.Initialize
        Args:
            algorithm: The algorithm instance to create universes for</param>
        Returns:
            The universes to be used by the algorithm'''
        universeSettings = self.universeSettings \
            if self.universeSettings is not None else algorithm.UniverseSettings

        resolution = universeSettings.Resolution
        type = typeof(Tick) if resolution == Resolution.Tick else typeof(
            TradeBar)

        universes = list()

        # universe per security type/market
        self.symbols = sorted(self.symbols,
                              key=lambda s: (s.ID.Market, s.SecurityType))
        for key, grp in groupby(self.symbols, lambda s:
                                (s.ID.Market, s.SecurityType)):

            market = key[0]
            securityType = key[1]
            securityTypeString = Extensions.GetEnumString(
                securityType, SecurityType)
            universeSymbol = Symbol.Create(
                f"manual-universe-selection-model-{securityTypeString}-{market}",
                securityType, market)

            if securityType == SecurityType.Base:
                # add an entry for this custom universe symbol -- we don't really know the time zone for sure,
                # but we set it to TimeZones.NewYork in AddData, also, since this is a manual universe, the time
                # zone doesn't actually matter since this universe specifically doesn't do anything with data.
                symbolString = MarketHoursDatabase.GetDatabaseSymbolKey(
                    universeSymbol)
                alwaysOpen = SecurityExchangeHours.AlwaysOpen(
                    TimeZones.NewYork)
                entry = self.MarketHours.SetEntry(market, symbolString,
                                                  securityType, alwaysOpen,
                                                  TimeZones.NewYork)
            else:
                entry = self.MarketHours.GetEntry(market, None, securityType)

            config = SubscriptionDataConfig(type, universeSymbol, resolution,
                                            entry.DataTimeZone,
                                            entry.ExchangeHours.TimeZone,
                                            False, False, True)
            universes.append(
                ManualUniverse(config, universeSettings, list(grp)))

        return universes
    def CreateOptionChainSecurity(self, algorithm, symbol, settings,
                                  initializer):
        '''Creates the canonical option chain security for a given symbol
        Args:
            algorithm: The algorithm instance to create universes for
            symbol: Symbol of the option
            settings: Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed
            initializer: Performs extra initialization (such as setting models) after we create a new security object
        Returns
            Option for the given symbol'''
        market = symbol.ID.Market
        underlying = symbol.Underlying

        marketHoursEntry = MarketHoursDatabase.FromDataFolder().GetEntry(
            market, underlying, SecurityType.Option)
        symbolProperties = SymbolPropertiesDatabase.FromDataFolder(
        ).GetSymbolProperties(market, underlying, SecurityType.Option,
                              CashBook.AccountCurrency)

        return SecurityManager.CreateSecurity(
            typeof(ZipEntryName), algorithm.Portfolio,
            algorithm.SubscriptionManager, marketHoursEntry.ExchangeHours,
            marketHoursEntry.DataTimeZone, symbolProperties, initializer,
            symbol, settings.Resolution, settings.FillForward,
            settings.Leverage, settings.ExtendedMarketHours, False, False,
            algorithm.LiveMode, False, False)
Ejemplo n.º 3
0
    def CreateFutureChainSecurity(self, algorithm, symbol, settings):
        '''Creates the canonical Future chain security for a given symbol
        Args:
            algorithm: The algorithm instance to create universes for
            symbol: Symbol of the future
            settings: Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed
        Returns
            Future for the given symbol'''
        config = algorithm.SubscriptionManager.SubscriptionDataConfigService.Add(
            typeof(ZipEntryName), symbol, settings.Resolution,
            settings.FillForward, settings.ExtendedMarketHours, False)

        return algorithm.Securities.CreateSecurity(symbol, config,
                                                   settings.Leverage, False)
Ejemplo n.º 4
0
    def CreateOptionChainSecurity(self, algorithm, symbol, settings, initializer):

        algorithm.Log(f"OptionUniverseSelectionModel.CreateOptionChainSecurity({algorithm.UtcTime}, {symbol}): Creating Option Chain Security")

        market = symbol.ID.Market
        underlying = symbol.Underlying

        marketHoursEntry = MarketHoursDatabase.FromDataFolder().GetEntry(market, underlying, SecurityType.Option)
        symbolProperties = SymbolPropertiesDatabase.FromDataFolder().GetSymbolProperties(market, underlying, SecurityType.Option, CashBook.AccountCurrency)

        return SecurityManager.CreateSecurity(typeof(ZipEntryName), algorithm.Portfolio,
                algorithm.SubscriptionManager, marketHoursEntry.ExchangeHours, marketHoursEntry.DataTimeZone, symbolProperties,
                initializer, symbol, settings.Resolution, settings.FillForward, settings.Leverage, settings.ExtendedMarketHours,
                False, False, algorithm.LiveMode, False, False)
Ejemplo n.º 5
0
    def CreateOptionChainSecurity(self, algorithm, symbol, settings,
                                  initializer):
        '''Creates the canonical option chain security for a given symbol
        Args:
            algorithm: The algorithm instance to create universes for
            symbol: Symbol of the option
            settings: Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed
            initializer: [Obsolete, will not be used] Performs extra initialization (such as setting models) after we create a new security object
        Returns
            Option for the given symbol'''
        config = algorithm.SubscriptionManager.SubscriptionDataConfigService.Add(
            typeof(ZipEntryName), symbol, settings.Resolution,
            settings.FillForward, settings.ExtendedMarketHours, False)

        return algorithm.Securities.CreateSecurity(symbol, config,
                                                   settings.Leverage, False)
    def CreateFutureChainSecurity(self, algorithm, symbol, settings, initializer):
        '''Creates the canonical Future chain security for a given symbol
        Args:
            algorithm: The algorithm instance to create universes for
            symbol: Symbol of the future
            settings: Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed
            initializer: [Obsolete, will not be used] Performs extra initialization (such as setting models) after we create a new security object
        Returns
            Future for the given symbol'''
        config = algorithm.SubscriptionManager.SubscriptionDataConfigService.Add(typeof(ZipEntryName),
                                                                                 symbol,
                                                                                 settings.Resolution,
                                                                                 settings.FillForward,
                                                                                 settings.ExtendedMarketHours,
                                                                                 False)

        return algorithm.Securities.CreateSecurity(symbol, config, settings.Leverage, False)
Ejemplo n.º 7
0
    def CreateFutureChainSecurity(self, algorithm, symbol, settings, initializer):
        '''Creates the canonical Future chain security for a given symbol
        Args:
            algorithm: The algorithm instance to create universes for
            symbol: Symbol of the future
            settings: Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed
            initializer: Performs extra initialization (such as setting models) after we create a new security object
        Returns
            Future for the given symbol'''
        market = symbol.ID.Market

        marketHoursEntry = MarketHoursDatabase.FromDataFolder().GetEntry(market, symbol, SecurityType.Future)
        symbolProperties = SymbolPropertiesDatabase.FromDataFolder().GetSymbolProperties(market, symbol, SecurityType.Future, CashBook.AccountCurrency)

        return SecurityManager.CreateSecurity(typeof(ZipEntryName), algorithm.Portfolio,
                algorithm.SubscriptionManager, marketHoursEntry.ExchangeHours, marketHoursEntry.DataTimeZone, symbolProperties,
                initializer, symbol, settings.Resolution, settings.FillForward, settings.Leverage, settings.ExtendedMarketHours,
                False, False, algorithm.LiveMode, False, False)
Ejemplo n.º 8
0
    def CreateOptionChainSecurity(self, algorithm, symbol, settings,
                                  initializer):

        algorithm.Log(
            f"OptionUniverseSelectionModel.CreateOptionChainSecurity({algorithm.UtcTime}, {symbol}): Creating Option Chain Security"
        )

        market = symbol.ID.Market
        underlying = symbol.Underlying

        marketHoursEntry = MarketHoursDatabase.FromDataFolder().GetEntry(
            market, underlying, SecurityType.Option)
        symbolProperties = SymbolPropertiesDatabase.FromDataFolder(
        ).GetSymbolProperties(market, underlying, SecurityType.Option,
                              CashBook.AccountCurrency)

        return SecurityManager.CreateSecurity(
            typeof(ZipEntryName), algorithm.Portfolio,
            algorithm.SubscriptionManager, marketHoursEntry.ExchangeHours,
            marketHoursEntry.DataTimeZone, symbolProperties, initializer,
            symbol, settings.Resolution, settings.FillForward,
            settings.Leverage, settings.ExtendedMarketHours, False, False,
            algorithm.LiveMode, False, False)