Overall Statistics
#https://www.quantconnect.com/forum/discussion/6171/dynamic-crypto-universe-portfolio/p1


from Alphas.HistoricalReturnsAlphaModel import HistoricalReturnsAlphaModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel

class CryptoMomentum(QCAlgorithm):

    def Initialize(self):
        self.stateData = {}
        self.SetStartDate(2019, 1, 19)  # Set Start Date
        self.SetEndDate(2019, 1, 22)
        self.SetCash(100000)  # Set Strategy Cash
        self.SetCash("BTC", 1)
        
        
        self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin)
        
        self.SetBenchmark('BTCUSD')
        
        
        # Add the pairs containing *BTC among all 346 pairs in Bitfinex
        symbols = ["LTCBTC", "ETHBTC", "ETCBTC", "RRTBTC", "ZECBTC", "XMRBTC",
                    "DSHBTC", "XRPBTC", "IOTBTC", "EOSBTC", "SANBTC", "OMGBTC",
                    "BCHBTC", "NEOBTC", "ETPBTC", "QTMBTC", "AVTBTC", "EDOBTC",
                    "BTGBTC", "DATBTC", "QSHBTC", "YYWBTC", "GNTBTC", "SNTBTC",
                    "BATBTC", "MNABTC", "FUNBTC", "ZRXBTC", "TNBBTC", "SPKBTC",
                    "TRXBTC", "RCNBTC", "RLCBTC", "AIDBTC", "SNGBTC", "REPBTC",
                    "ELFBTC", "IOSBTC", "AIOBTC", "REQBTC", "RDNBTC", "LRCBTC",
                    "WAXBTC", "DAIBTC", "CFIBTC", "AGIBTC", "MTNBTC", "SNGBTC",
                    "ODEBTC", "ANTBTC", "DTHBTC", "MITBTC", "STJBTC", "XLMBTC",
                    "XVGBTC", "BCIBTC", "MKRBTC", "VENBTC", "KNCBTC", "POABTC",
                    "LYMBTC", "UTKBTC", "VEEBTC", "DADBTC", "ORSBTC", "AUCBTC",
                    "POYBTC", "FSNBTC", "CBTBTC", "ZCNBTC", "SENBTC", "NCABTC",
                    "CNDBTC", "CTXBTC", "PAIBTC", "SEEBTC", "ESSBTC", "ATMBTC",
                    "HOTBTC", "DTABTC", "IQXBTC", "WPRBTC", "ZILBTC", "BNTBTC",
                    "XTZBTC", "OMNBTC", "DGBBTC", "BSVBTC", "BABBTC", "RBTBTC",
                    "RIFBTC", "VSYBTC", "BFTBTC"]
        
        Symbols = []
        for symbol in symbols:
            # add according forex data to add the crypto pairs
            self.AddForex(symbol[:3]+"USD", Resolution.Daily)
            Symbols.append(Symbol.Create(symbol, SecurityType.Crypto, Market.Bitfinex))
            
        self.SetUniverseSelection(ManualUniverseSelectionModel(Symbols))
        self.AddAlpha(HistoricalReturnsAlphaModel(7, Resolution.Daily))
        self.SetExecution(ImmediateExecutionModel())
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        
        self.__numberOfSymbols = 100
        self.__numberOfSymbolsFine = 5
        
    def OnData(self, data):    
        
        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)
        pass
        
        

    def CoarseSelectionFunction(self, coarse):    

        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)
        pass
        

    def FineSelectionFunction(self, fine):
        pass