Hi i have a zipline pipline algo(2017-2019) that was long only with binance's data and works only during bull market. 

But i am trying to re-implement with Quantconnect bitfinex's *BTC paris so i can build long/shorts portfolio and hedge during bears market.

  1. .Univers should changes over time with new listing and delisting.
  2. Factor:Momentum/Returns over D days.
  3. Rebalance every R day at the close with Market order at the open: 
  • -longs=Top quantile Momentum with 50% of BTC Equity
  • shorts=Bottom Quantile of Momentum with 50% of BTC Equity

so i far i am stuck with the universe filtering giving me error:

from Alphas.HistoricalReturnsAlphaModel import HistoricalReturnsAlphaModel from Execution.ImmediateExecutionModel import ImmediateExecutionModel from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel class ResistanceNadionGearbox(QCAlgorithm): def Initialize(self): self.stateData = { }; self.SetStartDate(2019, 1, 19) # Set Start Date self.SetCash(100000) # Set Strategy Cash # self.AddEquity("SPY", Resolution.Minute) self.AddAlpha(HistoricalReturnsAlphaModel(7, Resolution.Daily)) self.SetExecution(ImmediateExecutionModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.__numberOfSymbols = 100 self.__numberOfSymbolsFine = 5 self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction, self.FineSelectionFunction, None, None)) def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' # if not self.Portfolio.Invested: # self.SetHoldings("SPY", 1) # sort the data by daily dollar volume and take the top 'NumberOfSymbols' def CoarseSelectionFunction(self, coarse): # sort descending by daily dollar volume #sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) # return the symbol objects of the top entries from our sorted collection #return [ x.Symbol for x in sortedByDollarVolume[:self.__numberOfSymbols] ] for cf in coarse: if cf.Symbol.SecurityType == SecurityType.Crypto: #self.Debug(type(cf)) #self.Debug(type(cf.Symbol)) self.Debug(cf.Symbol.SecurityType) self.Debug("SecurityType.Crypto={}".format(SecurityType.Crypto)) self.stateData[cf.Symbol] = SelectionData(cf.Symbol, 200) # sort the data by P/E ratio and take the top 'NumberOfSymbolsFine' def FineSelectionFunction(self, fine): # sort descending by P/E ratio sortedByPeRatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=True) # take the top entries from our sorted collection return [ x.Symbol for x in sortedByPeRatio[:self.__numberOfSymbolsFine] ]