Overall Statistics
Total Orders
25
Average Win
13.11%
Average Loss
-3.29%
Compounding Annual Return
3.961%
Drawdown
25.400%
Expectancy
0.662
Start Equity
100000
End Equity
150894.22
Net Profit
50.894%
Sharpe Ratio
0.229
Sortino Ratio
0.182
Probabilistic Sharpe Ratio
0.534%
Loss Rate
67%
Win Rate
33%
Profit-Loss Ratio
3.99
Alpha
0.002
Beta
0.304
Annual Standard Deviation
0.091
Annual Variance
0.008
Information Ratio
-0.301
Tracking Error
0.137
Treynor Ratio
0.068
Total Fees
$136.77
Estimated Strategy Capacity
$340000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
0.64%
#region imports
from AlgorithmImports import *
#endregion
# https://quantpedia.com/Screener/Details/113


class JanuaryBarometerAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2008, 1, 1)  
        self.set_end_date(2018, 8, 1)  
        self.set_cash(100000) 
        self.add_equity("SPY", Resolution.DAILY)
        self.add_equity("BIL", Resolution.DAILY)
        self.schedule.on(self.date_rules.month_start("SPY"), self.time_rules.after_market_open("SPY"), self._rebalance)
        self._start_price = None
        
    def _rebalance(self):
        if self.time.month == 1:
            self.liquidate("BIL")
            self.set_holdings("SPY", 1)
            self._start_price = self.securities["SPY"].price
        if self.time.month == 2 and self._start_price is not None:
            returns = (self.securities["SPY"].price - self._start_price)/self._start_price
            if returns > 0:
                self.set_holdings("SPY", 1)
            else:
                self.liquidate("SPY")
                self.set_holdings("BIL", 1)