Strategy Library

Momentum Effect in Stocks

Introduction

The momentum anomaly says that what was strongly going up in the near past will probably continue to go up shortly. Stocks which outperform peers on 3-12 month period tend to perform well also in the future. This algorithm will explore the momentum effect on large-cap stocks.

Method

Universe Selection

We use the universe selection API to create a momentum portfolio. Our coarse-universe selection eliminates stocks with a price lower than $5 and ETFs which do not have fundamental data. Fine-universe selection chooses the 50 largest companies ranked by market capitalization.

Momentum Calculation

Momentum is the absolute difference in stocks. \[Momentum = Close_{today}-Close_{N-days-ago}\] LEAN has the Momentum indicator. We create a class to save the momentum value and warm up the indictor for each symbol.

class SymbolData:
    def __init__(self, symbol, lookback):
        self.symbol = symbol
        self.MOM = Momentum(lookback)

    def WarmUpIndicator(self, history):
        # warm up the Momentum indicator with the history request
        for tuple in history.itertuples():
            item = IndicatorDataPoint(self.symbol, tuple.Index, float(tuple.close))
            self.MOM.Update(item)
  

Dictionary self.symbolDataDict is used to save the momentum class instance SymbolData for each symbol. In OnSecuritiesChanged event method, we add the newly selected symbol to the dictionary and initialize the momentum indicator with the history request. For symbols removed from the universe, we remove it from the dictionary. Each day in OnData, the Momentum indicator for all symbols in the dictionary will be updated with the latest closing price.

We choose a period of 12 months for the momentum indicator. Stocks with the best 12-month momentum (12-month performance) are then added to our portfolio and are weighted equally.

Monthly Rebalance

The portfolio is rebalanced once a month. The coarse and fine universe selection is set to default to run at midnight once a day. To make the universe selection run at the first trading day each month, we use the bool variable self.monthly_rebalance to manage the universe selection. At the start of each month, the universe selection will filter new stocks. On all other days, the universe selection function will return the same symbols. In contrast to returning an empty list, returning the same symbols as before is a better way for monthly rebalance universe selection. Since if there are no open positions for certain symbol, returning empty list will stop the data subscription of that symbol halt updates of the indicator.

Algorithm

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

Did you find this page Helpful ?