Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-10.959%
Drawdown
35.800%
Expectancy
0
Net Profit
-20.742%
Sharpe Ratio
-0.417
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.222
Beta
6.769
Annual Standard Deviation
0.216
Annual Variance
0.046
Information Ratio
-0.507
Tracking Error
0.216
Treynor Ratio
-0.013
Total Fees
$1.00
class CalibratedMultidimensionalPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)  
        self.SetEndDate(2002, 1, 1)  # remove this and it gets slowed down 
        self.SetCash(10000)  
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddEquity("SPY", Resolution.Daily)
        
        self.numberOfSymbolsCoarse = 250
        self.numberOfSymbolsFine = 25
        self.dollarVolumeBySymbol = {}
        self.symbols = []
        self.lastMonth = -1
        
        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
        
        
    def CoarseSelectionFunction(self, coarse):
        
        if self.Time.month == self.lastMonth: 
            return self.symbols

        filtered = [x for x in coarse if x.HasFundamentalData and x.Volume > 0 and x.Price > 0]
        sortedByDollarVolume = sorted(filtered, key = lambda x: x.DollarVolume, reverse=True)[:self.numberOfSymbolsCoarse]

        self.symbols.clear()
        self.dollarVolumeBySymbol.clear()
        
        for x in sortedByDollarVolume:
            self.symbols.append(x.Symbol)
            self.dollarVolumeBySymbol[x.Symbol] = x.DollarVolume

        return self.symbols

    def FineSelectionFunction(self, fine):
        if self.Time.month == self.lastMonth: 
            return self.symbols
        self.lastMonth = self.Time.month

        filteredFine = [x for x in fine if x.CompanyReference.CountryId == "USA"
                                        and (x.CompanyReference.PrimaryExchangeID == "NAS")
                                        and (self.Time - x.SecurityReference.IPODate).days > 180
                                        and x.CompanyReference.IndustryTemplateCode == "N"]

        sortedByDollarVolume = []

        sortedByDollarVolume = sorted(filteredFine, key = lambda x: self.dollarVolumeBySymbol[x.Symbol], reverse=True)
        
        self.symbols = [x.Symbol for x in sortedByDollarVolume[:self.numberOfSymbolsFine]]
        
        return self.symbols


    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)