Overall Statistics
Total Orders
645
Average Win
1.71%
Average Loss
-1.72%
Compounding Annual Return
2.789%
Drawdown
24.600%
Expectancy
0.146
Start Equity
100000
End Equity
209790.11
Net Profit
109.790%
Sharpe Ratio
-0.007
Sortino Ratio
-0.004
Probabilistic Sharpe Ratio
0.001%
Loss Rate
43%
Win Rate
57%
Profit-Loss Ratio
1.00
Alpha
-0.011
Beta
0.205
Annual Standard Deviation
0.071
Annual Variance
0.005
Information Ratio
-0.37
Tracking Error
0.141
Treynor Ratio
-0.002
Total Fees
$3870.49
Estimated Strategy Capacity
$240000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
6.54%
# 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.

from AlgorithmImports import *

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