Overall Statistics
Total Trades
452
Average Win
0.88%
Average Loss
-0.76%
Compounding Annual Return
1.962%
Drawdown
11.900%
Expectancy
0.238
Net Profit
48.094%
Sharpe Ratio
0.51
Probabilistic Sharpe Ratio
0.977%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
1.15
Alpha
0.017
Beta
0.044
Annual Standard Deviation
0.04
Annual Variance
0.002
Information Ratio
-0.252
Tracking Error
0.187
Treynor Ratio
0.464
Total Fees
$2420.44
# https://quantpedia.com/strategies/payday-anomaly/
#
# The investment universe consists of the S&P500 index. Simply, buy and hold the index during the 16th day in the month during each month of the year.

class PayDayAnomaly(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)
        self.SetCash(100000)
        
        self.symbol = 'SPY'
        data = self.AddEquity(self.symbol, Resolution.Minute)

        csv_string_file = self.Download('data.quantpedia.com/backtesting_data/economic/payday.csv')
        dates = csv_string_file.split('\r\n')
        dates = [datetime.strptime(x, "%d.%m.%Y") for x in dates]

        self.liquidate_next_day = False
        
        self.Schedule.On(self.DateRules.On(dates), self.TimeRules.BeforeMarketClose(self.symbol, 1), self.DayBefore16th)
        self.Schedule.On(self.DateRules.EveryDay(self.symbol), self.TimeRules.BeforeMarketClose(self.symbol, 1), self.Rebalance)
    
    def DayBefore16th(self):
        if not self.Portfolio[self.symbol].IsLong:
            self.SetHoldings(self.symbol, 1)
            self.liquidate_next_day = True

    def Rebalance(self):
        if self.liquidate_next_day:
            self.liquidate_next_day = False
            return
        
        if self.Portfolio[self.symbol].IsLong:
            self.Liquidate(self.symbol)