Z-Score Factor Portfolio Weighting

Technical Indicators can be used for timing and weighting strategies. Using momentum as an example, you could go long if the momentum turns positive, or you could dimension the weight of your position depending on the level of momentum. Applied on a portfolio of assets, this would be called factor investing. This article will show you a way to weight your portfolio using factors.

Basic factor investing

Factors in factor investing can be technical (like momentum) or fundamental (like P/E ratio). The basic assumption in factor investing is, that stocks with high factor values will outperform stocks with lower factors. This basic assumption can be used in different ways. A lot of investors would only buy the stocks with the highest factor, as they would assume that high momentum stocks would outperform the average market. Or they could buy the top percentile and go short the bottom percentile to get a delta neutral portfolio. Usually an investor would try to out perform the index buy buying or selling a selection of stocks contained in this index.

rate of change factor scan

rate of change factor scan

Another way to do this would be to use a scoring card approach: the best stocks gets x points, the next one gets x-1 points… and in the end the points will determine the weighting of the specific stock in your portfolio. Both approaches are valid concepts and have been used for many years.

Z Score of factors

The approaches mentioned above unfortunately carry a lot of hidden parameters, which makes them sensitive to curve fitting. Which percentile of stocks will you buy, how will you weight them, how many points will you give to the best and to the other stocks, how many stocks should make it through this selection process….? These questions come even before the question on how you will weight your different factors…

A simple statistical trick can circumstance all these questions and directly lead to a sound portfolio weighting. This is done by z-scoring factors and thus converting them directly into the needed weights for the stocks in your portfolio.

The screenshot below shows how a z-scoring of factors is done with excel:

First you calculate the average over all stocks. Then calculate the standard deviation of your factors. To calculate the z-score of your factor just subtract the average from each factor and divide it by the standard deviation.

If you got more than one factor, do this for each factor individually.

z score factors

z score factors

On the screenshot above the top stock would get 2.56 times the capital (compared to original weighting in portfolio). The z-scored factor directly translates to the amount of capital invested. The sum over all weights is zero, thus it would be capital wise delta neutral portfolio.

Z-score portfolio weighting

The z-score is something really beautiful.  It has a mean of zero and a standard deviation of one.

The mean of zero means that the z-scores factors directly lead to a delta neutral portfolio.

The standard deviation of one brings the outliers under control, and, as you will see with the long-only portfolio, also defines the number of stocks invested.

Z-score factor combinations

Usually a portfolio will depend on more than one factor. But keeping in mind that the mean of the z-scores is zero, it is easy to sum up and weight different factors.

If you got more than one factor, just do the z-normalisation for each factor individually, and then sum it up to end up with the final factor score. If you give a different weight to each factor it does not matter, the mean of the sum of all factors will still be 0.

Total Factor = Weight(1)*factor(1) +weight(2)*factor(2)+…weight(n)*factor(n)

Long only factor portfolio

A delta neutral portfolio can be easily archived by just using the z-scores directly as portfolio weights. To construct a long only portfolio you will have to do some further calculations.

z score factors long only

z score factors long only

In a long only portfolio each stock would get its initial (cash equal) capital + factor*initial capital. So if the equal invested stock would get 1000$ and the factor would be 1, this specific stock would invest 2000$.

On the screenshot above I have got 30 stocks, so each stock would get 3.33% of the total portfolio value. To exclude short positions, I reset all factors below -3.33% to -3.33. According to the weighting formula above, these stocks would get no money to invest. Only stocks with a factor above -3.33% would be invested.

The example above has 12 out of 30 stocks invested. As the long-only condition destroyed the mean=0 property of the z-score, you will have to scale down the long positions to end up with a 100% investment grade. To do so just sum up the weights of all long positions and divide the weights by this number. In the end the sum of all positions has to be 1.

Backtests of a z-score model

For a sample backtest of a factor weighted portfolio I took the 11 biggest automobile producers. See the screenshot below. It shows the returns of a cash equal weighted portfolio which has 100.000$ invested at all time and does not re-allocate the P/L.

100.000$ cars portfolio equal weighted no re-allocation

100.000$ cars portfolio equal weighted no re-allocation

The next chart shows a z-score weighted portfolio. The only factor used is the % change of the stock over the last 12 months. At the end of each month the portfolio is re-weighted.

z-score weighted 100.000$ portfolio

z-score weighted 100.000$ portfolio

The z-score weighting automatically puts the money in the stocks with the highest momentum. The histogram under the portfolio equity shows the number of stocks invested. Usually around half of the stocks are invested. For most of the time in history the z-weighted portfolio had about the same performance as the neutral weighted portfolio, but in 2020 the momentum weighting pushed more money into TESLA, which lead to nice outperformance. Also keep in mind that you only had to trade 5 stocks on average, and not all 11 automobile stocks of this basket.

Tradesignal implementation of z-score portfolio

At the end of the article there is the source code of this portfolio. It can be used in Tradesignal

The given implementation of the z-scores weighting contains three different factors. Factor A is the standard deviation, factor B is the distance from the upper Bollinger band, and factor C is the rate of change (%momentum).  Feel free to change the code to test your own factors. Each of the factors can be weighted. Give it a positive weighting if you believe that a high factor is a good thing to have, otherwise give it a negative rating if you think that a low factor is advantageous. A weighting of zero removes the factor.

The factors on the screenshot below have been optimised for the highest risk/reward ratio. The data before 2015 is in-sample data, the data 2015-now is out of sample data.

cross currency z-score weighted portfolio

cross currency z-score weighted portfolio, 30 cross rates combined, 1m invested, no re-allocation

Continue reading

The coastline paradox and the fractal dimension of markets

Coastlines are fractal curves. When you zoom in, you will see similar shaped curves on every scale. The same is true for market data. On a naked chart you can hardly tell if it is a daily or hourly chart. This article will explore this feature of crinkly curves and show how much markets and coastlines have in common.

The coastline paradox

When trying to measure the length of the British coastline you will quickly notice, that the length measured depends on the length of the ruler you use. The shorter the ruler, the longer the measured length of the coastline.

When measuring a straight line, the length of the ruler has no influence. You can measure 1 meter with a 1cm ruler applied 100 times or with a 50cm ruler applied 2 times. Both methods will give you the same result. Not so when measuring a crinkly line like a coast.

British coastline length paradox

British coastline length paradox (c) wikipedia

In 1967 Benoit Mandelbrot wrote a famous article in Science magazine about this problem. This was the birth of fractal geometry. The basic assumption was, that if a curve is self similar, this self similarity can be described by the fractal dimension of a curve. Self similarity means, that if you zoom into a curve, it looks similar on all zoom levels.

Coastline paradox in financial markets

Continue reading

Detecting Support and Resistance Levels

Support & Resistance levels are essential for every trader. The define the decision points of the markets. If you are long and the market falls below the previous support level, you most probably have got the wrong position and better exit.

The detection of support and resistance levels is usually highly subjective and based on the analysts experience. In this article I will use a simple algorithm to detect the levels and show them on the chart. Continue reading

Profit from large daily moves

Whenever the market shows an exceptional day ranges it is time to take bite. See how you can profit from large daily market moves.

Open-Close Range

When looking at any chart, you will surely notice that the large candles tend to close near the high or low. This is due to herding. Once the market is moving significantly, everyone hops on and the large move becomes even larger. This is true for daily, weekly and intraday candles.

The chart shows an indicator which plots the daily move. Every opening is set to zero and the absolute move of the day is drawn. Around these normalised candles a long term 2 standard deviation volatility band is drawn.  Right now the 2 standard deviation volatility for SPX is about +/- 46 points.

Take a bite before the market closes

As you can see this +/-46 point barrier above/below the opening of the day is a wonderful entry point. If you enter long 46 points above the opening and go short 46 points below the opening nearly all entries would have lead to a profitable trade. To get an even higher probability of success you can volume as a confirmation. Large moves must also show high volume. The exit is done at the end of the session. This analysis does not give any indication for the next days move. So be fast, take your bite and go home with a small profit and no overnight position.

No free lunch

On the chart it looks easy, but be careful. As an example the last bar shown on the chart first crossed the band to the downside, reversed and crossed above the upper band. So you will need to use a trailing stop to lock in profits and avoid to take the full -46 to +46 points trade as a loss!

 

 

 

 

Python Regression Analysis: Drivers of German Power Prices

German Power prices can be explained by supply and demand, but also by causal correlations to underlying energy future prices. A properly weighted basket of gas, coal and emissions should therefore be able to resemble the moves of the power price.  This article will introduce multivariate regression analysis to calculate the influence of the underlying markets on a given benchmark. It is an example of  a machine learning algorithm used in analysis and trading.

Multivariate regression analysis

Continue reading

How to detect unwanted curve fitting during backtest

Whenever you develop an algorithmic trading strategy, unwanted curve fitting is one of the most dangerous hazards. It will lead to substantial losses in real time trading. This article will show you some ways to detect if the performance of your algorithmic trading strategy is based on curve fitting.

Curve fitting – what is it?

Every algorithmic trading strategy will have some parameters. There is no way around it. You will have to decide what length your indicators have, you will have to specify a specific amount for your stop loss or profit target. Beside the actual rules of your strategy the chosen parameters will usually significantly influence the back-test performance of your strategy. And with any parameter you add the danger of curve fitting rises significantly. Continue reading

The Edge of an Entry Signal

When developing a new trading strategy you are usually confronted with multiple tasks: Design the entry, design the exit and design position sizing and overall risk control. This article is about how you can test the edge of your entry signal before thinking about your exit strategy. The results of these tests will guide you to the perfect exit for the tested entry signal (entry-exit combination)

Quality of an Entry Signal

When you develop a new idea for an entry signal there are two things you would like to see after the entry: no risk and fast profits. This would be the perfect entry with the highest possible edge. In reality the market response to your entry will be risk and chance. With a good entry the upside would outnumber the downside. Continue reading

The Edge of Technical Indicators

Classical technical indicators like RSI and Stochastic are commonly used to build algorithmic trading strategies.  But do these indicators really give you an edge in your market? Are they able to define the times when you want to be invested? This article will show you a way to quantify and compare the edge of technical indicators. Knowing the edge of the indicator makes it an easy task to select the right indicator for your market.

The edge of an indicator

Any technical indicator, let it be RSI, moving averages or jobless claims, has got a primary goal. It should signal if it is a wise idea to be invested or not. If this indicator signal has any value, on the next day the market should have a higher return than it has on average. Otherwise  the usage of no indicator and a buy and hold investing approach would be the best solution.

The edge of an indicator in investing consists of two legs.

  1. the quality of the signal
  2. the number of occurrences

Continue reading

Daily Extremes – Significance of time

Analyzing at which time daily market extremes are established shows the significance of the first and last hours of market action. See how different markets show different behavior and see what can be learned from this analysis.

Probability of Extremes

A day of trading usually starts with a lot of fantasies for the future, then we try to survive the day and end it with a lot of hope for tomorrow. This psychological pattern can also be shown when analyzing intraday market data. A high level of fantasies usually leads to a strong market movement, and thus market extremes can often be seen near the beginning or the end of the trading session. Continue reading

Noisy Data strategy testing

Adding some random noise to historic market data can be a great way to test the stability of your trading strategy. A stable strategy will show similar profits with noisy and original data. If the noise has a great impact on your results, the strategy might be over fitted to the actual historic data.

Synthetic market data?

Generating completely synthetic market data to test algorithmic trading strategies is a dangerous endeavour.  You easily lose significant properties like classic chart patterns or the trend properties of your market. Continue reading