Strategy Library

Turn of the Month in Equity Indexes


The turn of the month is an effect on stock indices which states that stocks will rise during the last day before the end of the month and the first three days of each month. Researchers believe this significance comes as a result of pension funds receiving cash flows and reinvesting in the market, along with this period being a natural point for portfolio rebalancing between retail and professional investors. This algorithm is an approximation of the following strategy.


We start by creating scheduled events. The event at MonthEnd() will trigger the algorithm to buy SPY and the event at MonthStart() will start the process to sell SPY.

self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY", 1), self.rebalance)
self.Schedule.On(self.DateRules.MonthEnd("SPY"), self.TimeRules.AfterMarketOpen("SPY", 1), self.purchase)

We will purchase the SPY immediately, and we will wait 3 trading days, as suggested, before liquidating our portfolio. Assigning self.sell_flag in the scheduled event handler will help us wait 3 days before executing the liquidate order in OnData(). The equity index is bought and sold every month.

def purchase(self):
        self.SetHoldings("SPY", 1)
def rebalance(self):
    self.sell_flag = True
def OnData(self, data):
    if self.sell_flag:
        self.days += 1
        if self.days == 3:
            self.sell_flag = False
            self.days = 0


You can also see our Documentation and Videos. You can also get in touch with us via Chat.

Did you find this page Helpful ?