NaN.

TutorialMachine LearningLast updated

Measuring Momentum[ Edit ]

I have explained the basic idea behind Momentum Strategies and the comparison between Momentum and Mean-Reversion Strategies in my last article. I would like to clarify one thing here: I mentioned momentum strategy compared to mean-reversion strategy could be a relative long-term strategy since the volatility within the price series may drive the price up and down all the time, therefore, the trendline outlines the long-term trend that the price prices end up following.

However, I found out (based on the research I did afterward)that the patterns of stock price movements within a trading day actually show not reversion buy momentum. There are a bunch of people using momentum to construct their intraday, high-frequency strategies which happen within extremely short time sometimes i.e. nanosecond.

Also, I will add some details about Momentum Strategies here also. There are two types of momentum: time series momentum and cross-sectional momentum, following the corresponding classifications of mean reversion.

- Time-series Momentum: the pattern of future returns of price series are positively correlated with the past returns;
- Cross-sectional Momentum: refers to the relative performance of another price series, and we believe if a price series with returns outperformed other price series then it is more likely that this trend will maintain in the future and vice versa.

In order to better use the Momentum Strategy, we have to measure the states of the Momentum and capture the enter/exit signals behind the states. I will introduce how to examine momentum states using moving average crossover strategy in this article.

First of all, I just randomly choose 8 stocks and plotted their price series from 2013–01–18 to 2015–12–18 on the same graph(I distinguish them with the different colors). You can see very directly that their prices are so diversified. The range is from almost $0 up to almost $140 per share.

The examples I am explaining and testing here are about the time-series momentum(absolute momentum also) means I will use price series directly to test its momentum then to identify the signals within the series.

Here is a common way to obtain a momentum signals called Moving Average Crossover Strategy.

The stock I choose to testify is the first one in the basket which is ‘AA’(based on the ranking of the prices). Simply plot the price series on the graph shown below. We can see the moving trend more clearly when we zoom in the graph for the specific stock.

I need to plot the moving average on the graph and to check if there are any crossovers between/ among the averages. I will use both short-term(as an approximation of current state which might be sensitive to the noise) and long-term moving average(for smoothing the noises and get a clear picture about the actual prices trend ) such as the short-term period I choose here is 15 days and the long-term period is 150 days.

One of the benefits of including both short-term and long-term moving average is that we can see the effects of short-term fluctuations are minimized but not ignored so it will greatly reduce the number of false buy and false sell signals that we may detect. Thus, our goal is just to identify the crossover points of two moving averages and what we are curious about is when was the current state moving away from the overall average?

Actually, you can find a lot information from the graph beyond what I just talked about such as if you are doing mean-reversion strategy and you find that the current state is way higher than the 150 days long-term moving average line, you can make you decision based on it and say they probably will catch on with each other in the future and I will bet on it and vice versa.

Or if you are doing momentum strategy, you can find the two crossovers in the graph. You can see it from the graph that one is at the end of 2013, The current state(15 days moving average) starts to move higher than the long-term 150 days moving average which indicates a ‘BUY’ signal ( generated when the short-term average crosses above the long-term average) and which also implies the upward momentum; The other one happened at the beginning of 2015 and the current state started to move below the 150 days long-term moving average state which indicates a ‘SELL’ signal(which is triggered by a short-term average crossing below a long-term average) and which also implies the downward momentum of the stock price.

As you can see from the chart above, those signals are very objective, which is why this method is so popular. These two points would actually be your entry and exit signals for the positions.

However, I would have to emphasize again about the potential overfitting problem here. In this case, it is essential for us to determine the lengths of both short-term and long-term moving average periods. As I always emphasized, we should try not to optimize the window lengths unless you know what you are doing and how to deal with robust optimization(what I will briefly explain by the end of the article) and end up with the overfitting problem which is super dangerous. What’s more, it is incredibly easy to overfit these window lengths to a specific set of the dataset and works very well in your historical backtest but will not work in the future trading.

I did some research on how to choose the lengths of the short-term and long-term moving average and I found that there is no clearly and uniform answer. Many traders will place 5-, 10-, and 20-day moving average onto a chart respectively; then wait for the 5-day average crosses up through the others(primary ‘buy’ sign). Or waiting for the 10-day average to cross above the 20-day average which is often used as a confirmation(common techniques used to reduce the occurrence of the false signals).

A popular way to resolve this problem is to gauge the strength of a trend and likelihood that trend will continue — here I will use moving average ribbon(a technique used in technical analysis to identify the strength of the current trend and which is achieved by placing a large number of moving averages onto the same chart. Whenever identifying all averages are moving to the same direction, you can judge that the trend is strong to some extent. Reversals are confirmed when the averages crossover and head in the opposite direction.) which proved to be less prone to overfitting because instead of choosing specific window length you just dropped a ton of them.

Often ribbons start with 50-day moving average and add average in 10-day increments up to the final average of 200 as the graph shows below( so there are 15 averages in total).

We have the moving average ribbons here and the next step would be how could we extract as much as information(trading signals) from it. I will use distance metrics here which is based on the hamming distance formula(‘For a fixed length *n*, the Hamming distance is a metric on the set of the words of length n (also known as a Hamming space), as it fulfills the conditions of non-negativity, identity of indiscernibles and symmetry, and it can be shown by complete induction that it satisfies the triangle inequality as well.’).

The general idea is to use a distance metric to see how far away from some given ranking our ribbon is(here we check against 1–15 ranking). If the price of the stock moving towards a certain direction in a smooth way the distance of each ribbon will keep stable and high. Once the stock price is undergoing some momentum shift, then you will see the crossovers happened among these averages and the distances of them will drop.

We will show this process through Hamming distance: which counts the number of difference between two series and captures their ranking shifts. Then in order to better capture and analysis regarding the ranking shifts we need to normalize the rank of moving averages(make sure they are normally distributed).

As I explained, the distance metrics can help us to capture the signals when there is more difference appear in my ribbon compared to the standard 1–15 ranking(which is ranked by the length of moving average from 50-, 60-, …, to 200-days(ascending way)). There are too many lines and movements going on here so you may find it is kind of hard to understand.

I will explain it with the graph below. You can see that when the stock price moves up(averages are moving up too from Oct. 2013 to June 2014), the ranking of them actually is upside down(since the shorter term moving average is actually the one highest, however, it should be the lowest one based on the ranking system that we set before). It explains the reason why the distance metrics graph is relatively high here and that is also why when the stock price moves down( all the averages are moving down along with the stock price from Feb. 2015 to Oct. 2015) the distance drops to 0(the rankings now are accordance with the original setup rankings in this period).

Every time a ‘BUY’ signal shows up(the short-term state will move up higher than the long-term one and their rankings are moving up too), the distance line will move upwards. In other words, the line will move downward when the ‘SELL’ signal shows up. All the signals are hidden behind those spikes and lows if you notice the pattern.

In order to show information more clearly and to create a clear visualization, I combined the asset price, moving averages, and the distance metrics lines in one graph(so you can compare them on the same graph easily).

The other way is to generate the Spearman Rank Correlation metrics to capture the signals. This way is more easy and simpler to understand. Once those moving average come across with each other you can see a peak on the graph as below. The reason behind is that the scores that we plot here is actually the p-value of Speakman Rank Correlation(the cutoff point is .05; if p-value <= 0.05, we should accept the alternative hypothesis that they have correlation, and if p-value > 0.05, we can accept the null hypothesis that they do not have any correlation).

Therefore, the p-value is actually is 0(or close to 0) when all the moving averages are moving up and down smoothly because they are perfectly positive(when they are moving downside) or perfectly negative(when they are moving upside) correlated with default ranking as I discussed above. However, the p-value becomes really large when they have crossovers since they are really correlated with each other anymore. The second picture below is the one I combined asset price series, averages, and correlation metrics lines together for you to better identify the signals.

We can also achieve the goal by measuring the thickness of those averages by taking the range of values at any given time to monitor the thickness of the ribbon. Thus, we can see the line goes down once there is a crossover.

I would like to add a little explanation here. You can see that the multiplier that I set up for the previous distance metrics and correlation metrics, as well as the graph right above, is 10x(from the code I upload), which means that I multiply the result with 10 in order to amplify the effect showing on the graph. But I change the multiplier for the graph below, I change it into 5x for better visual effect, but the mechanism is the same (if I keep 10x as the multiplier the yellow line will be much higher than the rest lines).

After introduced those different measurements, I would like to sum up a little bit. The distance metrics wold be the clearest one for capturing the signals because you can actually identify the both ‘BUY’ and ‘SELL’ signals from the graph( spikes imply the ‘BUY’ signal and lows imply the ‘SELL’ signal); the rest two methods can only give you the information about the occurrence of the signal but without telling you which signal it is. You have to compare them with the moving averages to make a judgment about ‘BUY’ or ‘SELL’ by yourself.

As I mentioned in the article, I will explain a little about ‘Robust Optimization’(you can check the basic concept by clicking the word): I will only talk about the solution about how to avoid overfitting by robust optimization regarding the case here. In order to optimize your model, you need to try a bunch of values and look at the distribution of Sharpe Ratios and Profits that you make using the model over those values. Then make sure that the values you are choosing for the window lengths are not some isolated points but the true optimal values could be the real ones plus some noises. By doing this, you will give your model a higher chance to be resilient to those noises at some point.

Generally, they are all very effective and easy to understand ways for measuring the momentum and capturing the signals. You can choose from them based on your own purposes. Hopefully, my explanation will help you to better understand these strategies and develop your momentum strategy. Once you finish choosing your asset(s) and know how to measure the momentum, the next step would be examining the strategy and checking if the states are actually predictive and how long would the strategy be predictive.

From next article, I will strat to show you more practical examples that I have learned and tried for making trading strategy and backtesting it.

Please feel free to leave your comment on anything you think I can improve here. Thank you for your time and hope you enjoy the content.

Reference:

Read more…(2323 words)

About the contributor:

Haohan Wang

100%

Loading…

Join the discussion. Add a reply…

Post

Contributor

Haohan Wang

100%

Ready to join our community?

Sign up below to automatically get notified of new courses, get **reminders** to finish ones you subscribe to, and **bookmark** lessons to read later.

Continue with Facebook

— OR —

Your Full Name

Email address

I have an account. Log in instead

By signing up, you agree to our Terms and our Privacy Policy.

Popular Courses

New Courses

About Us

Get in touch

Copyright 2016-18, Compose Labs Inc. All rights reserved.