Overall Statistics
Total Trades
39
Average Win
19.59%
Average Loss
0%
Compounding Annual Return
28.621%
Drawdown
32.600%
Expectancy
0
Net Profit
141.393%
Sharpe Ratio
0.882
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.197
Beta
5.71
Annual Standard Deviation
0.352
Annual Variance
0.124
Information Ratio
0.826
Tracking Error
0.352
Treynor Ratio
0.054
Total Fees
$316.78
# https://quantpedia.com/Screener/Details/25

class SmallCapInvestmentAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2016, 1, 1)
        self.SetEndDate(2019, 7, 1)
        self.SetCash(100000)

        self.UniverseSettings.Resolution = Resolution.Daily
        self.count = 10

        self.year = -1
        self.symbols = []
        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)


    def CoarseSelectionFunction(self, coarse):
        ''' Drop stocks which have no fundamental data or have low price '''

        if self.year == self.Time.year:
            return self.symbols

        return [x.Symbol for x in coarse if x.HasFundamentalData and x.Price > 5]
 

    def FineSelectionFunction(self, fine):
        ''' Selects the stocks by lowest market cap '''

        if self.year == self.Time.year:
            return self.symbols

        # Calculate the market cap and add the "MarketCap" property to fine universe object
        for i in fine:
            i.MarketCap = (i.EarningReports.BasicAverageShares.ThreeMonths *
                           i.EarningReports.BasicEPS.TwelveMonths *
                           i.ValuationRatios.PERatio)

        sorted_market_cap = sorted([x for x in fine if x.MarketCap > 0], key=lambda x: x.MarketCap)

        self.symbols = [i.Symbol for i in sorted_market_cap[:self.count]]
        return self.symbols


    def OnData(self, data):

        if self.year == self.Time.year:
            return

        self.year = self.Time.year

        for symbol in self.symbols:
            self.SetHoldings(symbol, 1.0/self.count)


    def OnSecuritiesChanged(self, changes):
        ''' Liquidate the securities that were removed from the universe '''

        for security in changes.RemovedSecurities:
            symbol = security.Symbol
            if self.Portfolio[symbol].Invested:
                self.Liquidate(symbol)