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

RSI Hellfire Heatmap Indicator

Chart analysis is all about visualizing data. The RSI hellfire indicator uses a heat-map to visualizes how overbought or oversold the market is on a broad scale. This helps to get a broad picture of the current market setup.

Multiple Time-frame Relative Strength Index

Wells Wilder’s RSI is an old timer of technical indicators. It tries to find out if markets are overbought or oversold. Usually it is calculated using a 14 bar setting. But a 14 bars RSI on a daily chart will give a different reading than 14 bars on an hourly or weekly chart. As it is always nice to see what traders on a different time-frame see on their charts, you could simply display several RSI settings on your chart. 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

A simple algorithm to detect complex chart patterns

Finding complex chart patterns has never been an easy task. This article will give you a simple algorithm and a ready to use indicator for complex chart pattern recognition. You will have the freedom to detect any pattern with any pattern length. It has been described as Fréchet distance in literature. This article shows a simple adaptation for chart pattern analysis.

Defining a chart pattern

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

Monte Carlo Simulation of strategy returns

Monte Carlo Simulation uses the historic returns of your trading strategy to generate scenarios for future strategy returns. It provides a visual approach to volatility and can overcome limitations of other statistical methods.

Monte Carlo Simulation

Monte Carlo is the synonymous for a random process like the numbers picked by a roulette wheel. Continue reading

Overnight vs Daytime Performance & Volatility

Analysing the market performance of the day session vs. the overnight movement reveals some interesting facts.

Daytime vs. Overnight Performance

The chart below gives a visual impression on where the performance of the SPY ETF is coming from.

The grey line represents a simple buy and hold approach. The green line shows the performance if you would have held SPY only during daytime, closing out in the evening and re-opening the position in the morning. Continue reading

An Algorithmic Stock Picking Portfolio

In this article I will discuss a simple algorithmic stock picking approach based on momentum and volatility. The goal will be to generate excess returns versus a capital weighted stock basket.

Alpha and Beta

Investing in assets with low volatility and high return is on a lot of peoples wish list. Portfolios which archive this goal will have a high Sharpe ratio and in the end get the investors money. By reverse engineering this criteria, one can find promising stocks to invest in and out perform a given capital weighted index.

Alpha and beta are measures to describe an assets performance relative to its index. Both are used in the CAPM – capital asset pricing model.

Alpha is a measure for an assets excess return compared to an index. Continue reading

Weis Wave indicator code for Tradesignal

The Weis Wave indicator combines trend and volume information. It seems to be of some interest for timing short term market reversals. Here comes a version of this indicator for usage in Tradesignal.

The Weis Wave indicator for Tradesignal

The basic idea of the Weis Wave indicator is to sum up the traded volume, as long as the market moves in the same direction. The bullish volume wave is displayed in green. As soon as the market changes direction, a red wave is constructed. by comparing the magnitude of the Weis wave with the magnitude of the market move, valuable insights for short term market timing can be found.

More information can be found via a web search or from the page I got the idea form: https://weisonwyckoff.com/weis-wave/ Continue reading

Tradesignal Implied Volatility and IV Percentile Scanner

Implied volatility data is key in options trading. This article shows how to access free volatility data in the Tradesignal software suite.

Implied Volatility and IV Percentile

Thanks to https://www.optionstrategist.com/calculators/free-volatility-data  implied volatility and IV percentile data is available. For free on a weekly basis. Using this data and the given code the data can be loaded into Tradesignal. This enables you to do your custom market scans, combining Tradesignal technical analysis and the implied volatility data from the optionstrategist website.

Free implied volatility data

The first step to use the optionstrategist data would be to safe it into a text file. Just copy and paste the data, no additional formatting is required. The free data on the website is updated every Continue reading

Implied vs. Realized Volatility for NASDAQ100 stocks

(1) You shall only trade when the chances are on your side

Comparing implied and realised volatility

Selling volatility can be a profitable game, but only if you sold a higher volatility than the market realises later on. Comparing realised and current implied volatility gives you an idea if the chances are on your side.

We already had a look at realised volatility and what the fair price for a straddle might be. Have a look at the kvolfair bet articles. These articles present a way to calculate the historically correct price for a straddle. Whenever you sell a straddle (to sell volatility), implied volatility should be higher than the fair bet price. Only then you will win on a statistical basis. Also have a look at the statistics of VIX, to get a clue when a downturn in volatility can be expected. Continue reading

Seasonal trouble ahead

If a bitchy prime minister and a crazy president weren’t enough, for the upcoming months the seasonal chart is also indicating further price setbacks.

Seasonality of DAX

Analyzing the average monthly performance of the German DAX index a distinct pattern of seasonality can be observed. On average June has been down 0.6%, but the big trouble is yet to come.

Continue reading