Factor investing in portfolio management

Factor investing has been around in portfolio management for some years. Based on algorithmic rules it became the big thing in trading and the ETF industry. But is there still some money to be made? Is small beta still smart or just beta? This article will give you a Tradesignal framework to test the factor investing ideas by your own. Continue reading

If you like it please link it

Statistics of VIX

The CBOE volatility index VIX  measures the market’s expectation of future volatility. This article will show you some key statistics of VIX and help you to decide if it is better to buy or to sell volatility.

Statistics of VIX

The spikes to the top and the long phases of relatively low volatility are reflected in a left-leaning distribution diagram and a long tail towards the higher levels. The median value is 17%, meaning 50% of the prices are above (below) this level.

The next chart shows the distribution of returns over 25 trading days. The median price movement being slightly shifted to the negative area shows the mean reverting characteristics of volatility.

Buy or sell volatility?

Analysing the level of VIX and the returns afterwards yields an even more interesting picture:

The green line gives the 25 bar percentage returns of VIX, with VIX noting above 25, the red line gives the returns with VIX below 15. Observe the median of the two lines:

The median 25 bar return with VIX above 25 (green) is around -15%, only 20% of the returns are positive when VIX is currently above 25. Sell volatility.

The median returns with VIX currently below 15 (red) is above 0% and with a fat tail to positive returns. Buy volatility. (data from 2004-2018)

Adverse movement of VIX

The above chart suggests that going short on volatility, if VIX is above 25, seems to be a good idea. But it is not without risk. The chart below shows what can go wrong during the next 25 days. The distribution diagram gives the maximum adverse movement of the VIX, with VIX currently trading above 25.

The green line, VIX currently above 25, shows a +10% median maximum up movement over the next 25 days. So do not expect a short vola position to be without risk. Some adverse movement has to be expected.

On the other side, the distribution of the maximum loss of the VIX during a 25 day period shows a median of below -20%. This represents the profit potential of a short volatility position.

Conclusion of VIX statistics:

If you plan to short volatility wait until VIX is trading above 25. If you want to buy volatility, do so if VIX is trading below 15.

 

If you like it please link it

Machine learning: kNN algorithm explained

I always thought that inspiration and experience are key factors in trading. But every time my chess computer beats me without any inspiration, just by brute force, I get my doubts. This article will be about a brute force approach in trading. The kNN algorithm.

Rule based trading

Rule based trading – algorithmic trading, is just a name for a set of if..then rules which will define the machines trading decisions. e.g. if the market crosses below the 200 day line, then short 100 contracts. If the market rises by 2% then exit the position.  Easy stuff like this… (for the beginning)

This article will be a short introduction to machine learning. I will use a classic algorithm of machine learning to let my computer find a prediction for tomorrows market move. In the meantime I’ll have a glass of wine with some friends and let the machine do the job; At least that’s the idea, but can it be that simple in real life trading?

Unsupervised machine learning – kNN algorithm

The kNN algorithm is one of the most simple machine learning algorithms. Learning, in this case, is only a nice sounding label, in reality kNN is more of a classification algorithm.

This is how it woks:

The scatter chart above is a visualisation of a two dimensional kNN data set. For this article I used a classical indicators of technical analysis to do the prediction: a long-term and a short-term RSI indicator. The dots on the two dimensional scatter chart represent the historic RSI values at a given point of time.

Now have a look at the fat circled point. This point represents today’s value. It means, that today’s RSI1 has a value of 63, and RSI2 got a value of 70.

Additionally to the position on the chart the dots have got colours. A green dot means that the market moved up on the following day, a red dot shows a falling market on the day after.

We already know what has happened in history, so it is easy to colour the historic dots. But we do not know the colour of today’s dot, as it is not known where tomorrow’s market will end.

Based on the chart above, will it be a red or green dot? Will tomorrow be up or down?  Should I go long or should I go short?

kNN – k nearest neighbours

To do a prediction of tomorrow’s market move, the kNN algorithm uses the historic data shown on the scatter plot above and finds the k-nearest neighbours of today’s RSI values. As you can see, our current fat point is surrounded by red dots. This means, that every time the two RSI values have been in this area, the market fell on the day after. That’s why today’s data point is classified as red. Wish it would be that easy all the times…

Call it classification or prediction, the two dimensional kNN algorithm just has a look on what has happened in the past when the two indicators had a similar level. It then looks at the k nearest neighbours, sees their state and thus classifies today point.

kNN as Tradesignal Equilla Code

In this article I would like to show you an implementation with the Tradesignal programming language Equilla.

To implement the algorithm in Tradesignal we first have to do the shown scatter plot. The algorithm stores the values in an array.

8/9 calculates the value of the fast and slow RSI indicators

12/13 looks what will happen on the day after (for the training data set)

16/17/18 stores everything in an array.

The next task to complete is to calculate the distances of today’s RSI point to all the historic points in the training data set.

23/27 calculates the euclidean distance of today’s point to all historic points, line 29 then creates a sorted list of all these distances to find the k nearest historic data points in the training data set.

Nearly done. The next step is just to find out what classification (colour) the nearest points have got and use this information to create a prediction for tomorrow. This is done in lines 33 to 35

Have a look at the scatter chart at the beginning. If this would be the data stored in our training data set, the prediction, using the 5 nearest neighbours, would be -5. All the 5 nearest neighbours of our current data point are red.

Now that we got a prediction for tomorrow, we need to make use of this prediction and trade it. The returns then will show if everything works as predicted.

Over here I just do a simple long/short interpretation of the prediction, but of course you could also use the quality of the prediction (+5 or +1?) in some sort of way. Position sizing…?

kNN algorithm performance

The next chart shows 2000 bars of daily Brent data. It uses a 14 and 28 day RSI to predict the next day’s move in the Brent oil market. The training was on the first half of the data set, and the 5 nearest neighbours did the classification.

Underneath the chart the returns of this test are shown. (strategy equity). On the bottom of the char you see the two RSI indicators used for the generation of the prediction / buy-sell command.

kNN algorithm – conclusion

The kNN algorithm offers a framework to test all kind of indicators easily to see if they have got any predictive value. Judging on the shown graph it seems to work. It seems to be possible to use these two RSI indicators to predict tomorrow’s Brent move.

But unfortunately this also could be just completely useless curve fitting. It is you who has to select the indicators and their periods and you will have to define if you like the outcome of a selected parameter set. To many degrees of freedom to be sure. The kNN algorithm is useful, but its application in finance has to be treated carefully. Otherwise bad surprises are guaranteed

Not everything can be done by brute force, inspiration and experience are key factors in finance…

 

 

 

If you like it please link it

NASDAQ 100 long term candlestick scanner

A short update on the long term Candlestick Scanner.

The Candlestick Scanner scans the Nasdaq 100 stocks for long term bullish or bearish reversal patterns.

The basic idea is to search for hammer and hanging man candlestick patterns. Usually these patterns work nicely on daily charts. My Candlestick Scanner searches for these two patterns on every time frame, from a 1 day per bar compression up to a  250 days per bar compression. This enables me to use a simple, well defined and documented pattern as a description of short to long term reversal setups.

But see for yourself which Nasdaq stocks seem to change the direction according to the long term Candlestick Scan. The list gives you the duration of the reversal formation (expect about the same time to either reach the target or get stopped out) The detected pattern becomes a valid entry signal if a new high (hammer) or low (hanging man) is established.

Bullish reversals on the left side, bearish reversals on the right side.

 

If you like it please link it

Position sizing – the easy way to great performance

Working on your position sizing algorithm is an easy way to pimp an existing trading strategy. Today we have a look at an energy trading strategy and how the position sizing can influence the performance of the strategy.

The screenshot shows you the returns of the same trading strategy, trading the same markets, the same time frames and using the same parameters. The returns on the left side look nice, making money every year. The returns on the right side are somehow shaky, and you would have to love volatility of returns if you would think about trading this basket. The only difference between the basket on the right and on the left side is the position sizing.

The energy basket:

The basket trades German power, base and peak (yearly, quarterly, monthly), coal, gas, emissions. All instruments are traded on a daily and weekly time frame chart, using the same parameters. If the daily trading uses a 10-period parameter, the weekly trading would use a 10-week parameter. This limits the degrees of freedom I have when doing the strategy-time frame-parameter merge, thus minimizing the curve fitting trap.

Continue reading

If you like it please link it

Opening Range Breakout

Das Opening Range Breakout System wurde im Magazin “Technical Analysis of Stocks&Commodities” im Juli 1994 besprochen, und wie es scheint, funktioniert es, zumindest ohne slippage uns Speasen, noch immer.

Ein Opening Range Breakout System von Perry Kaufmann.

Es wurde im Magazin “Technical Analysis of Stocks&Commodities” im Juli 1994 besprochen, und wie es scheint, funktioniert es noch immer. (ohne slippage) Auch Tony Crabel schrieb zu diesem Opening Breakout System im selben Magazin

Das System wartet die erste Handelsstunde ab und geht dann bei Erreichen eines neuen Hochs oder Tiefs  long oder short.  Die Einstiegs Order (Stop Buy / Stop Sell) wird nicht exakt auf das Hoch / Tief gelegt, sondern ein paar Punkte darüber /darunter. (hier 20 Ticks)

Tradesignal Programmierung des Opening Range Systems

Durch das laden von drei Zeitreihen, 10min, Stunden- und Tagesdaten gestaltet sich die Programmierung sehr einfach. Dies schränkt jedoch die Flexibilität deutlich ein.

Prinzipiell ist die Strategie der Afternoon Trader Strategie sehr ähnlich, sie weist auch mehr Flexibilität in der Programmierung auf. Auch der Artikel über Range Breaks im intraday Markt basiert auf einer ähnlichen Idee.

TSM(S) 1st hour breakout detail

Da die hier vorgestellte Systemversion  ursprünglich für dieTradestation 2000i in Easy Language geschrieben wurde, ist das Laden von 3 Zeitreihen ein wenig kompliziert gelöst. Aber es funktioniert.

Strategie Backtest mit adjustiertem DAX Future:

TSM(S) 1st hour breakout backtest

zum Opening Range Tradesignal Equilla Code Passwort “code”

If you like it please link it

Selbstlernende Handelssysteme

Ein jeder kennt die klassischen Indikatoren wie RSI oder Stochastic. Und ein jeder kennt die dazugehörigen Handelsanweisungen: Long, wenn überverkauft, Short wenn überkauft. Und zumindest im Lehrbuch funktioniert das auch. Aber wie sieht das ganze am realen Chart aus? Würden Sie dem Lehrbuch vertrauen und Ihren Kunden auch einen baldigen Kauf empfehlen wenn der RSI unter 20 liegt?

Testen anstatt zu studieren

Schön, wenn ein Indikator im Lehrbuch funktioniert, doch will ich hier ein Verfahren darstellen, bei dem der Indikator selbst angibt ob, wann und wie gut er funktioniert! Dazu habe ich mir für diesen Beitrag den RSI Indikator vorgenommen.

Zunächst wird der Wert des Indikators betrachtet, sowie, ob er steigt oder fällt. Mit diesen beiden Kriterien lässt sich der RSI einfach klassifizieren.

RSI Prognose

Dann erfolgt der eigentliche Backtest: Innerhalb der letzten 1000 Bars wird nun geschaut, wie sich der Markt bei einem gleichen Indikatorstand (zwischen 90 und 100) und Richtung (über Triggerlinie) verhalten hat.

 

Am Bild kam dies innerhalb der letzten 100 bars 36 mal vor. Dabei war die durchschnittliche Bewegung innerhalb der darauffolgenden 5 min DAX Futures Kerze -0.03%. Der RSI hat beim aktuellen Stand also eine negative Kurs Prognose.

Dass es auch nach dem nächsten bar statistisch nach unten geht, sieht man an den 5 Prognose Punkten am Chart. Sie zeigen, wie sich der Markt statistisch innerhalb der nächsten 5 Bars verhalten hat, unter der Bedingung, dass der RSI den aktuellen Stand und Richtung hatte.

Markt Performance als Indikator

Der obige Screenshot zeigt den Indikator und die Prognose für den kommenden bar (sowie die 4 darauf folgenden). Er zeigt jedoch nicht, wie sich diese Prognosen in der Vergangenheit verhalten haben, in welchen Bereichen der Indikator in der Vergangenheit seine höchste Aussagekraft hatte. Dies ist am nächsten Chart dargestellt.

RSI Prognose

Am Bild ist unter dem eigentlichen RSI seine aktuelle prognose für den nächsten Bar dargestellt. Um diese prognose ist ein Bollingerband gelegt, um so die Bereiche zu definieren, an welchen der RSI seine höchste Aussagekraft hat (= die stärkste Bewegung vorhersagt)

Continue reading

If you like it please link it

Reality vs. Robert W. Colby, CMT

Dont`t believe!

Papier ist geduldig, darum ist es oft besser wenn man selbst testet bevor man ein veröffentlichtes Handelssystem mit seinem Geld ausprobiert. Heute geht es hier um einen Handelssystem out of sample Test

Ein schönes Beispiel dafür ist eine Strategie aus Robert Colbys Buch “The Encyclopedia of Technical Market Indicators“, 2nd edition, 2003, page 791ff.

Darin wird ein einfaches moving average crossover Systeme vorgestellt, welches anscheinend seit beinahe 100 Jahren phänomenale Gewinne verspricht.

Hier eine Kopie aus dem Buch:

colby wma strategy

colby2

Tradesignal Backtest

Continue reading

If you like it please link it