Overall Statistics
Total Orders
568
Average Win
0.86%
Average Loss
-0.82%
Compounding Annual Return
1.389%
Drawdown
12.100%
Expectancy
0.157
Start Equity
100000
End Equity
140599.43
Net Profit
40.599%
Sharpe Ratio
-0.31
Sortino Ratio
-0.079
Probabilistic Sharpe Ratio
0.004%
Loss Rate
43%
Win Rate
57%
Profit-Loss Ratio
1.04
Alpha
-0.014
Beta
0.056
Annual Standard Deviation
0.037
Annual Variance
0.001
Information Ratio
-0.348
Tracking Error
0.155
Treynor Ratio
-0.209
Total Fees
$2801.97
Estimated Strategy Capacity
$400000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
6.28%
# 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.

from dateutil.relativedelta import relativedelta
from AlgorithmImports import *

class PayDayAnomaly(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)
        self.SetCash(100000)
        
        self.market: Symbol = self.AddEquity('SPY', Resolution.Minute).Symbol
        self.liquidate_next_day: bool = False
        
        self.Schedule.On(self.DateRules.EveryDay(self.market), self.TimeRules.BeforeMarketClose(self.market, 1), self.Purchase)
    
    def Purchase(self) -> None:
        alg_time = self.Time
        paydate = self.PaydayDate(alg_time)

        if alg_time.date() == paydate:
            self.SetHoldings(self.market, 1)
            self.liquidate_next_day = True

        if self.liquidate_next_day:
            self.liquidate_next_day = False
            return
        
        if self.Portfolio[self.market].IsLong:
            self.Liquidate(self.market)

    def PaydayDate(self, date_time):
        payday = date(date_time.year, date_time.month, 1) + relativedelta(day=15)
        
        if payday.weekday() == 5: # Is saturday.
            payday = payday - timedelta(days=1)
        elif payday.weekday() == 6: # Is sunday.
            payday = payday - timedelta(days=2)
        
        return payday