Overall Statistics
Total Trades
10
Average Win
46.41%
Average Loss
-0.07%
Compounding Annual Return
19.395%
Drawdown
39.900%
Expectancy
557.936
Net Profit
1486.887%
Sharpe Ratio
0.667
Probabilistic Sharpe Ratio
3.431%
Loss Rate
20%
Win Rate
80%
Profit-Loss Ratio
697.67
Alpha
0.077
Beta
1.096
Annual Standard Deviation
0.248
Annual Variance
0.061
Information Ratio
0.506
Tracking Error
0.167
Treynor Ratio
0.151
Total Fees
$147.64
Estimated Strategy Capacity
$380000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
Portfolio Turnover
0.12%
#region imports
from AlgorithmImports import *
#endregion
# https://quantpedia.com/Screener/Details/25
class SmallCapInvestmentAlgorithm(QCAlgorithm):

    def Initialize(self):

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

        self.year = -1
        self.count = 1

        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
        #self.AddRiskManagement(MaximumUnrealizedProfitPercentPerSecurity(0.10))
        self.AddRiskManagement(MaximumDrawdownPercentPortfolio(-0.10))
    def CoarseSelectionFunction(self, coarse):
        ''' Drop stocks which have no fundamental data or have low price '''
        if self.year == self.Time.year:
            return Universe.Unchanged

        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 '''
        sorted_market_cap = sorted([x for x in fine if x.MarketCap > 0],
            key=lambda x: x.MarketCap, reverse=True)

        return [x.Symbol for x in sorted_market_cap[:self.count]]


    def OnData(self, data):

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

        self.year = self.Time.year

        for symbol in self.ActiveSecurities.Keys:
            self.SetHoldings(symbol, 1/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, 'Removed from Universe')