Introduction
Based on the market cap, we can divide the stocks into large-cap, mid-cap and small-cap stocks. In each of those categories, we can subdivide them into value stocks and growth stocks. The growth stocks typically grow revenues faster than the market average and have relatively high P/E ratios and P/B ratios. The value stocks have relatively low P/E ratios and P/B ratios. There are six styles in total. We've demonstrated various momentum strategies to generate excess returns at the firm, industry, and country level. In this algorithm, we'll explore the momentum effect at the style index ETF level.
Method
We choose six index ETFs to represent different Equity styles (small-cap value, mid-cap value, large-cap value,
small-cap growth, mid-cap growth, large-cap growth). After adding the assets, we save the momentum percent indicator in
the dictionary self.momp
for each style. The formation period of 12-month is used to gauge the value of momentum.
def initialize(self):
self.set_start_date(2001, 1, 1)
self.set_end_date(2018, 8, 1)
self.set_cash(100000)
tickers = ["IJJ", # iShares S&P Mid-Cap 400 Value Index ETF
"IJK", # iShares S&P Mid-Cap 400 Growth ETF
"IJS", # iShares S&P Small-Cap 600 Value ETF
"IJT", # iShares S&P Small-Cap 600 Growth ETF
"IVE", # iShares S&P 500 Value Index ETF
"IVW"] # iShares S&P 500 Growth ETF
lookback = 12*20
# Save all momentum indicator into the dictionary
self.mom = dict()
for ticker in tickers:
symbol = self.add_equity(ticker, Resolution.DAILY).symbol
self.momp[symbol] = self.MOMP(symbol, lookback)
Six ETFs are ranked based on their prior 12-month performance in the formation period. The algorithm goes long the top performing ETF and short the ETF at the bottom and holds the position for one month. The portfolio is rebalanced at the start of next month.
def rebalance(self):
# Order the MOMP dictionary by value
sorted_momp = sorted(self.momp, key = lambda x: self.momp[x].current.value)
# Liquidate the ETFs that are no longer selected
for symbol in sorted_momp[1:-1]:
if self.portfolio[symbol].invested:
self.liquidate(symbol, 'No longer selected')
self.set_holdings(sorted_momp[-1], -0.5) # Short the ETF with lowest MOMP
self.set_holdings(sorted_momp[0], 0.5) # Long the ETF with highest MOMP
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jing Wu
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!