Overall Statistics
Total Trades
557
Average Win
1.77%
Average Loss
-1.76%
Compounding Annual Return
3.000%
Drawdown
24.600%
Expectancy
0.155
Net Profit
98.885%
Sharpe Ratio
0.354
Probabilistic Sharpe Ratio
0.032%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
1.01
Alpha
0.029
Beta
-0.013
Annual Standard Deviation
0.079
Annual Variance
0.006
Information Ratio
-0.284
Tracking Error
0.196
Treynor Ratio
-2.139
Total Fees
$3494.67
Estimated Strategy Capacity
$540000000.00
 
 
# https://quantpedia.com/strategies/turn-of-the-month-in-equity-indexes/
#
# Buy SPY ETF 1 day (some papers say 4 days) before the end of the month and sell the 3rd trading day of the new month at the close.

class TurnoftheMonthinEquityIndexes(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(1998, 1, 1)
        self.SetCash(100000)
        
        self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        
        self.sell_flag = False
        self.days = 0
        
        self.Schedule.On(self.DateRules.MonthStart(self.symbol), self.TimeRules.AfterMarketOpen(self.symbol), self.Rebalance)
        self.Schedule.On(self.DateRules.MonthEnd(self.symbol), self.TimeRules.AfterMarketOpen(self.symbol), self.Purchase)
    
    def Purchase(self):
        self.SetHoldings(self.symbol, 1)
    
    def Rebalance(self):
        self.sell_flag = True
        
    def OnData(self, data):
        if self.sell_flag:
            self.days += 1
            if self.days == 3:
                self.Liquidate(self.symbol)
                self.sell_flag = False
                self.days = 0