# Rule-based Momentum Investing

Trying to escape local optima on a random walk through life.

04.08.2020

Note: I’m by no means an expert on this topic. However, these strategies are based on deterministic statistical rules so you can easily check them against historical data.

In my first article about simple investing strategies, I took a look at long-term investing using a savings plan and one or multiple index funds. You can of course stick with that strategy, it’s the absolute least amount of effort, thinking and worry one can possibly put into investing, and still do pretty well. However, with some time and still pretty much no – except for maybe some initial – thinking and effort, one can easily outperform that first strategy.

There are two approaches I will present in this article; both are classified as Momentum investing strategies. I will explain how you can reduce your risk, profit from upward trends in the market, avoid losses from downward trends and in general how to pick the right stocks at the right time. All based solely on statistics, no (other) magic involved.

But first, let’s take a look at the weaknesses of the Buy and hold strategy presented in the first article, so we know what to focus on when trying to improve it.

## The problems of Buy and hold

When investing in only one index fund, there’s a non-negligible chance that you’ll experience a crash at least once, especially when investing over a longer time frame. This isn’t a huge problem for long-term investing, as crashes usually won’t stay around for too long and the markets usually recover quite quickly. Of course, you can (at least try to) prevent this altogether by properly diversifying or choosing a fund like the MSCI World.¹ But there are other, real problems…

Take a look at this chart of the German DAX lasting from 1961 to 1983:

Source: finanzen.net

You can see that, in the past, if you’ve invested in an index fund at the wrong time you could wait for as long as 20 years and still not see any returns. That’s a pretty strong argument against blindly following the Buy and hold strategy.

Another weakness is that – while simple and comfortable – it’s just suboptimal:
When buying an index fund, you’re buying all of the included stocks, no matter if they’re currently performing well or badly. As I’ve shown in the previous article on this topic, as long as the market in general is in an upward trend – and that’s the default – the overall growth will dominate in the long run. But why should you buy the whole index, when you could try to pick just the well-performing stocks and omit the bad ones, thus increasing returns and lowering risks?

But in order to achieve this, we will have to do some more than simply buying and holding an index fund.

In the following paragraphs, we will use basic statistics to try to classify stocks into two categories, rising and falling, good and bad, buy and sell. After finding out how to make an educated guess on their trends, we will develop rules that will enable us to enter the right stocks at the right time (i.e. those currently in an upward trend) and stay out of the wrong ones (i.e. those in a downward trend).
As a basis for the presented strategies I’m assuming that stocks generally move in trends, which you can easily convince yourself of by taking a look at an arbitrary stock chart.

First, I’ll explain some required technical terms – they’re really simple though – and then I’ll present the two strategies.

## The Absolute Momentum

The Absolute Momentum of a stock is an empirical binary indicator for its current trend. We can use it to determine if a single stock is currently in an upward or downward trend.

The underlying statistical indicator is a Moving Average, usually a Simple Moving Average (SMA) or an Exponential Moving Average (EMA).

### The Simple Moving Average (SMA)

The simple moving average of a stock on a day D is calculated by adding up the closing-values p of that stock from the last n trading days before D, and dividing that sum by n.

The simple moving average over n days on D is thus calculated as

$\bar{p}_{D,n} := \frac{1}{n} \sum_{i=1}^{n} p_{D-i}$

### The Exponential Moving Average (EMA)

The exponential moving average is basically the same as the SMA, but instead of equal weighting, exponential weighting is applied. It weights the summands differently, based on their date.

It can be defined explicitly as follows, where the coefficient α (between 0 and 1) controls the degree of weight decrease and the series (p) consists of the closing-values, starting from the most recent day and going back in time over all earlier trading days:

$\bar{e}_{(p),\alpha} := \alpha [ p_{1} + (1-\alpha) p_{2} + (1-\alpha)^{2} p_{3} + (1-\alpha)^{3} p_{4} + \dots ]$

By definition, the EMA reacts to changes a bit quicker than the SMA:

Source: Fidelity

### Determining the Absolute Momentum

Once you’ve calculated a moving average for the stock you’re analyzing, determining its Absolute Momentum is pretty straightforward:
If the current value of the stock is higher than its current moving average value, that symbolizes an upward trend (Buy signal), if it is lower, that implies a downward trend (Sell signal).

Oftentimes the SMA200 is used, which is the simple moving average over the last 200 trading days.

### The Envelope filter

As – by definition – every moving average tries to emulate its input, the Absolute Momentum of a stock can change quite often. Using the raw Absolute Momentum as buying and selling indicator would thus lead to a lot of different signals which, in turn, would lead to a lot of purchases and sales, which lead to high operating expenses.

There’s a simple filter you can use to avoid this, and it’s called envelope.
The envelope filter consists of an upper and a lower bound – and implicitly a gray area in between – for switching signals. Choosing a difference of 3% both on top and below the moving average is quite usual. This results in an upper bound of 1.03 times the moving average and a lower bound of 0.97 times the moving average.

When using a moving average with envelope, you’re not buying or selling whenever the current value crosses that of the moving average, but only when it crosses the upper bound from below or the lower bound from above.

Note, that you’ll miss out on the maxima and minima, especially when using a bigger envelope. But that’s okay, as you’ll still make enough each upward trend and not lose too much each downward trend, all while having way less actions to perform.

This way, you are left with around 1-2 signals per year, which is definitely feasible.

## The Relative Momentum

The Relative Momentum is another indicator for a stock’s trend. While the Absolute Momentum focuses on one stock only and tries to determine if it’ll go up or down in the future, the Relative Momentum calculates a stock’s delta, a value that determines how much it has risen or fallen recently, in relation to its general trend.

A stock’s delta value is calculated by dividing the value of a short-term moving average by that of a long-term moving average. Oftentimes the two averages used are the SMA38 and the SMA200.

A delta value of 5% (i.e. a ratio of 1.05) would be a good short-term development, one of -5% (i.e. a ratio of 0.95) would be rather bad.

Even though it’s mathematically incorrect, you could think of the Absolute Momentum as a stock price’s first derivative, and of the Relative Momentum as its second derivative.

## Picking an initial stock pool

In both strategies, you will have to start with an initial selection of stocks you’re considering in your analysis. All rules will only be applied to these stocks, in order to determine which of them to buy and which to sell. I call this initial set of stocks the stock pool.

You don’t have to pre-filter these stocks manually, so you can just pick all the stocks in an index or multiple indices (don’t add the same stock twice though) or go with all the stocks represented in the MSCI World or something similar.

However, keep diversification in mind!
The strategies contain mechanisms that help avoid crashes, but it’s still better to make money in market B while there’s a crash in market A, than to just take few losses in market A. If your stock pool doesn’t contain enough diversified stocks, there’s no way you could further diversify down the road, so you should choose it as widely distributed as possible.

## The Absolute Momentum Strategy

In general, you want to own stocks that will increase in value and don’t want to own those that decrease.

So using the Absolute Momentum of each single stock, you can determine which one you should buy (or keep) and which one to sell (or not to buy). If a stock’s value is breaking through the upper bound of the moving averages envelope, you want to buy it, if it’s crashing through the lower bound, you want to sell it. If it’s on either side of the envelope or in between, in the gray zone, you just keep it in/out of your portfolio, like it currently is.

But how much do you invest in each one of the stocks that is doing well?
If your stock pool contains x stocks, you’re investing 1/x of the total amount you want to invest into each of the selected stocks.² This way, you’ll be less invested in the market in times where there’s a general downward trend and fully invested only if every single stock is doing well. This simple mechanism automatically regulates the risk depending on the current trends of the market.

When you sell stocks, make sure to distribute the returns evenly on all your stocks by just adding them to the total amount you’re investing. This is important to make use of the compound effect, as I’ve described in the previous article.

### Performance compared to Buy and hold

Let’s compare this strategy to the index performance (that you would duplicate with the simple strategy explained in my first article).

Take a look at this graphic: Source: GFA-Finanzinstitut.

The red line is what you would replicate with a Buy and hold strategy applied on an index fund emulating the HDAX. The blue line is the result of the just presented Absolute Momentum strategy.

First off, you can see that even with the extremely simple strategy described in the first article, you can achieve pretty good returns.
But notice how even though upward trends in the red line are also replicated by the blue line, the crashes and long downward trends in the red line are mostly avoided by the blue one.

This is achieved by being less invested in those times and especially not holding any of the stocks performing too badly. You can see the amount of stocks being held using the newly presented strategy by looking at the gray area in the background. Notice how it’s low in the long downward trends of the whole market and high in its upward trends.

So these are the main results of the Absolute Momentum strategy:
It provides for general low investment in downward trends and almost none in crashes. This serves as a measure to avoid losses, prevent personal crashes and thus reduce risk. Otherwise, you still profit from the stocks in an upward trend, as well as avoid parallel losses of the bad performers.

## The Momentum Strategy

The presented Absolute Momentum strategy can be further improved. We will now use this first strategy as a mere preselection and out of all the stocks that are currently in an upward trend, we will select only the fastest growing ones to invest into.

So like above, take your stock pool and apply the Absolute Momentum strategy to obtain all the stocks that are assumed to currently be in an upward trend. Now the Relative Momentum comes into play: Calculate the delta values of all the well-performing stocks and sort them in descending order.

You have another degree of freedom: the amount x of stocks you want to invest in. A high amount results in a more defensive strategy, a low amount enables higher returns. However, you probably shouldn’t go below 5.

Now, pick the first x stocks of the delta-sorted list of stocks currently in an upward trend and invest in those. Each of them gets 1/x of your total investment sum. Even when some of them have a negative delta, you’re investing, as they’re still in a general upward trend.
This means, when there are no less than x stocks in an upward trend, you’re fully invested in the fastest growing ones of them. You’re only less invested in times where there are less than x stocks in an upward trend.

As delta values can change quite often, this could potentially lead to a lot of buy/sell signals. But again, there’s a trick to filter those as well: Suppose you’ve decided on x=20 and one stock falls from position 3 in your delta-sorted list to position 21. Usually you’d sell it and buy the one at position 20 instead. But with this filter, you’re only selling when a stock falls below, say, position 25 and only then you buy the one at position 20.
So what you’re doing is simply inserting a gray zone for not having to exchange fastest growing stocks all too often.

## The Code

I’ve written some python code to help with calculating the data needed for applying these strategies. It fetches the latest data from the Yahoo Finance API and provides the presented statistical methods, even the strategies themselves are implemented already.

Check it out on my Github.

Start the script using python -i stocks.py.

¹: Of course, these can also crash, but the more diversified you are, the safer you are in general.

²: You could try to increase your returns (but also your risk!) by not investing 1/x in each of those, but evenly splitting your whole investment sum over the selected stocks. This would immensely increase your risk though, so consider this option carefully.