Overall Statistics
Total Orders
97
Average Win
12.72%
Average Loss
-8.37%
Compounding Annual Return
7.414%
Drawdown
55.700%
Expectancy
0.522
Start Equity
100000
End Equity
577453.23
Net Profit
477.453%
Sharpe Ratio
0.266
Sortino Ratio
0.28
Probabilistic Sharpe Ratio
0.015%
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
1.52
Alpha
0.001
Beta
0.973
Annual Standard Deviation
0.159
Annual Variance
0.025
Information Ratio
-0.001
Tracking Error
0.037
Treynor Ratio
0.044
Total Fees
$766.92
Estimated Strategy Capacity
$1600000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
1.08%
# https://quantpedia.com/strategies/january-effect-in-stocks/
#
# Invest in small-cap stocks at the beginning of each January. Stay invested in large-cap stocks for the rest of the year.
#
# QC implementation changes:
#   - Small cap etf (IWM) and large cap etf (SPY) are used as investment assets.

from AlgorithmImports import *

class JanuaryEffectInStocks(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)  
        self.SetCash(100000) 

        data = self.AddEquity("SPY", Resolution.Daily)
        data.SetLeverage(10)
        self.large_cap = data.Symbol
        
        data = self.AddEquity("IWM", Resolution.Daily)
        data.SetLeverage(10)
        self.small_cap = data.Symbol

        self.start_price = None
        self.recent_month = -1
        
    def OnData(self, data):
        if self.recent_month == self.Time.month:
            return
        self.recent_month = self.Time.month

        if self.Securities[self.large_cap].GetLastData() and self.Securities[self.small_cap].GetLastData():
            if (self.Time.date() - self.Securities[self.large_cap].GetLastData().Time.date()).days < 5 and (self.Time.date() - self.Securities[self.small_cap].GetLastData().Time.date()).days < 5:
                if self.Time.month == 1:
                    if self.Portfolio[self.large_cap].Invested:
                        self.Liquidate(self.large_cap)
                    self.SetHoldings(self.small_cap, 1)
                else:
                    if self.Portfolio[self.small_cap].Invested:
                        self.Liquidate(self.small_cap)
                    self.SetHoldings(self.large_cap, 1)
            else:
                self.Liquidate()
        else:
            self.Liquidate()