def __init__(self, resolution=Resolution.Daily): '''Initialize a new instance of EqualWeightingPortfolioConstructionModel Args: resolution: Rebalancing frequency''' self.insightCollection = InsightCollection() self.removedSymbols = [] self.nextExpiryTime = UTCMIN self.rebalancingTime = UTCMIN self.rebalancingPeriod = Extensions.ToTimeSpan(resolution)
def __init__(self, resolution, slowPeriod, longPeriod, positive_abnormal, negative_abnormal): '''Initializes a new instance of the EmaCrossAlphaModel class Args: slowPeriod: The slow EMA period''' self.resolution = resolution self.slowPeriod = slowPeriod self.longPeriod = longPeriod #self.positive_abnormal = positive_abnormal #self.negative_abnormal = negative_abnormal self.predictionInterval = Time.Multiply( Extensions.ToTimeSpan(self.resolution), self.slowPeriod) self.symbolDataBySymbol = {} resolutionString = Extensions.GetEnumString(self.resolution, Resolution) self.Name = '{}({},{})'.format(self.__class__.__name__, self.slowPeriod, resolutionString)
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 __init__(self, rebalancingParam=Resolution.Daily): '''Initialize a new instance of EqualWeightingPortfolioConstructionModel Args: rebalancingParam: Rebalancing parameter. If it is a timedelta or Resolution, it will be converted into a function. The function returns the next expected rebalance time for a given algorithm UTC DateTime''' self.removedSymbols = [] # If the argument is an instance of Resolution or Timedelta # Redefine rebalancingFunc rebalancingFunc = rebalancingParam if isinstance(rebalancingParam, int): rebalancingParam = Extensions.ToTimeSpan(rebalancingParam) if isinstance(rebalancingParam, timedelta): rebalancingFunc = lambda dt: dt + rebalancingParam if rebalancingFunc: self.SetRebalancingFunc(rebalancingFunc)
def __init__(self, rebalancingParam=Resolution.Daily): '''Initialize a new instance of EqualWeightingPortfolioConstructionModel Args: rebalancingParam: Rebalancing parameter. If it is a timedelta, date rules or Resolution, it will be converted into a function. If None will be ignored. The function returns the next expected rebalance time for a given algorithm UTC DateTime. The function returns null if unknown, in which case the function will be called again in the next loop. Returning current time will trigger rebalance.''' self.removedSymbols = [] # If the argument is an instance of Resolution or Timedelta # Redefine rebalancingFunc rebalancingFunc = rebalancingParam if isinstance(rebalancingParam, int): rebalancingParam = Extensions.ToTimeSpan(rebalancingParam) if isinstance(rebalancingParam, timedelta): rebalancingFunc = lambda dt: dt + rebalancingParam if rebalancingFunc: self.SetRebalancingFunc(rebalancingFunc)
def __init__(self, rebalance=Resolution.Daily, portfolioBias=PortfolioBias.LongShort): '''Initialize a new instance of EqualWeightingPortfolioConstructionModel Args: rebalance: Rebalancing parameter. If it is a timedelta, date rules or Resolution, it will be converted into a function. If None will be ignored. The function returns the next expected rebalance time for a given algorithm UTC DateTime. The function returns null if unknown, in which case the function will be called again in the next loop. Returning current time will trigger rebalance. portfolioBias: Specifies the bias of the portfolio (Short, Long/Short, Long)''' self.portfolioBias = portfolioBias # If the argument is an instance of Resolution or Timedelta # Redefine rebalancingFunc rebalancingFunc = rebalance if isinstance(rebalance, int): rebalance = Extensions.ToTimeSpan(rebalance) if isinstance(rebalance, timedelta): rebalancingFunc = lambda dt: dt + rebalance if rebalancingFunc: self.SetRebalancingFunc(rebalancingFunc)