Money for nothing

We already had a post regarding the mean reverting behaviour of Volatility, now it`s time to make some money using this information.

Trading Volatility

The VIX volatility index on the chart above looks like an easy to trade instrument, just buy when it is around 10 and sell when it has doubled, tripled, quadrupled…

But unfortunately life is not that easy, VIX is just an index and you will not be able to buy or sell it. You might try to trade volatility using options, but there is a better plan to make money on this wonderful asset class, the VXX, BRCL BK IPTH S&P 500 VIX SH FTRS ETN.

VXX – the perfect money printing machine

The VXX is an ETN which tries to follow the vix on a short timescale buy having exposure to the first 2 VIX futures contracts. But like with commodities, where the further out contracts cost more money (a risk premium), this leads to severe losses in the long run. You buy expensive (far out) and then the premium melts away. This is a general problem of all ETFs which try to follow a physical market, and will be my edge in making money.

Like VXX also USO and UNG (physical Gas and Oil ETFs) are doomed to go to ZERO in the long run. Only reverse splits could hold them from reaching this target by now.

I am not up to track or trade the VIX on a short term basis, I am more interested in making money due to this structural bug build in in the methodology used to track the VIX. So for me VXX (similar to USO and UNG) is a long term short investment.

Having a look at a long term comparison between VIX and VXX will surely give you the same idea:

note the logarithmic scale for VXX!

No risk, no return

The above chart gives you the returns distribution of VXX over 5 -50 -250 trading days. On a yearly basis you hardly had any positive return, and the median loss (=win for shorties) would have been 47%. Even the 2-month 50 day return has got a median of -17%, with only a 20% chance of a positive return over this period of time. So the odds are clearly with you, the longer you hold, the more you gain.

On the other side, things are never that easy as they seem,  it would be suicide just to invest all your money in a VXX short trade.

Even when the odds are on your side, you will get a problem with risk. While VIX has the nasty tendency to quadruple from time to time, it even went from 10 to 90 in 2008, VXX as a short term tracker of VIX could also behave like this. Since 2013 when the instrument came into existence, there has been several incidents when VXX at least doubled on the short term. That would be the incident when your broker gives you a markin call or closes your position at the worst possible moment. To be on the safe side don`t invest more than 25% of your account into a VXX short trade!

VXX, USO, UNG – my short list for short trades

Your edge in trading VXX is not the trend down, but this fundamental problem in tracking the VIX index using the next two months futures contracts. The same problem which brings down the united states oil and gas fund USO und UNG. Like the VXX the returns distribution (50 and 250 days) gives a clear indication to trade these instruments only on the short side.

These returns distributions, caused by the the fundamental tracking problem of a futures market, make VXX, USO and UNG my private money printing machines. VXX is a clear “short and hold”, USO and UNG are a “short when strong” opportunity.

Research pays off!

 

 

 

Machine Learning – KNN using Tradesignal Equilla

I always thought that inspiration and experience is a key factor in trading. But everytime my chess computer beats me without any inspiration, just by brute force, I start to reconsider this assumption. This article will be about a brute force approach in trading.

Rule based trading

I have never been a great believer in classical technical analysis. If you ask 2 analysts about the current trend in the market, you get at least 3 answers. So I turned to algorithmic trading, using the tools of technical analysis in a new way, doing if..then conditions, backtesting them, refining the rules and parameters until the desired result was shown. These if..then based conditions, like if the market is above it`s 200 day line then go long, are mostly found by experience and inspiration. Isn’t my brain just a neural network which can be trained with historic data (experience), enhanced with a glass of wine for the inspiration?

Today I would like to take a voyage into machine learning. I would like to let my computer find the rules by itself, and just decide if I like the results or not. I’ll have the glass of wine with some friends and let the machine do the job; This sounds tempting to me, but can life really be as easy?

Unsupervised machine learning – kNN algorithm

The knn algorithm is one of the most simple machine learning algorithms. Learning might be the wrong label, in reality it is more of a classification algorithm. But first let’s see how it works.

The scatter chart above is a visualization of a two dimensional kNN data set. For this article I used a long term and a short term RSI. The dots represent the historic RSI values. Have a look at the fat circled point. It just means, that todays RSI1 has a value of 63, and RSI2 got a value of 70. Additionally the dots have got colours. A green dot means the market moved up on the following day, a red dot shows a falling market on the day after.

kNN – k nearest neighbours

To do a prediction of tomorrow’s market move, the kNN algorithm has a look at the historic data (shown on the scatter plot) 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 2 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. Call it classification or prediction, the kNN algorithm just has a look on what has happened in the past when the RSI indicators had a similar level. Have a look at this video, it is a great explanation on how the algorithm works.

kNN as Tradesignal Equilla Code

Computer kiddies would implement this algorithm in Python or R, but I would like to show you an implementation with the Tradesignal programming language Equilla. It is way faster than Python, and has got the advantage that I can directly see all the advantages and disadvantages on the chart. It is not just number crunching.

To implement the algorithm in Tradesignal we first have to do the shown scatter plot, but not graphically but store the 2 rsi values and the next days market move(colour of dots) into an array.

In line 8&9 the rsi values are calculated, line 12&13 calculates the next day`s market move. Line 15 to 20 then stores the data into the training data array. This is done for the first half of the data set, for my example I will use the data from bar 50 to 1000 on my chart of 2000 data points.

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.

Line 23 to 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.

We are 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 just have to trade it:

kNN algorithm performance

Lets have a look if this simple machine learning algorithm works. Using 2000 days of backward adjusted brent data, I used a 14 and 28 day RSI to predict the next day move. The training was done on bar 50 to 1000, and I used the 5 nearest neighbours for the classification.

Knn algorithm – conclusion

Judging on the shown graph it seems to work. It seems to be possible to use these 2 RSI indicators to predict tomorrow’s brent move.

kNN algorithm gives me a framework to test all kind of indicators or even different data sets easily and see if they have got any predictive value.

This is definitely an addition to classical algorithmic trading, using if..then conditions build from experience and intuition.

But you might still need some intuition to find the right data sets, indicators and parameters to get a useful prediction. Not everything can be done by machine learning…

 

 

 

Using Autocorrelation for phase detection

Autocorrelation is the correlation of the market with a delayed copy of itself. Usually calculated for a one day time-shift, it is a valuable indicator of the trendiness of the market.

If today is up and tomorrow is also up this would constitute a positive autocorrelation. If tomorrows market move is always in the opposite of today’s direction, the autocorrelation would be negative.

Autocorrelation and trendiness of markets

If autocorrelation is high it just means that yesterdays market direction is basically today’s market direction. And if the market has got the same direction every day we can call it a trend. The opposite would be true in a sideway market. Without an existing trend today’s direction will most probably not be tomorrows direction, thus we can speak about a sideway market.

Autocorrelation in German Power

But best to have a look at a chart. It shows a backward adjusted daily time series of German Power.

The indicator shows the close to close autocorrelation coefficient, calculated over 250 days. You will notice that it is always fluctuating around the zero line, never reaching +1 or -1, but let`s see if we can design a profitable trading strategy even with this little bit of autocorrelation.

The direction of autocorrelation

Waiting for an autocorrelation of +1 would be useless. There will never be the perfect trend in real world data. My working hypothesis is, that a rising autocorrelation means that the market is getting trendy, thus a rising autocorrelation would be the perfect environment for a trend following strategy. But first we have to define the direction of the autocorrelation:

To define the direction of the autocorrelation I am using my digital stochastic indicator, calculated over half of the period I calculated the autocorrelation. Digital stochastic has the big advantage that it is a quite smooth indicator without a lot of lag, thus making it easy to define its direction. The definition of a trending environment would just be: Trending market if digital stochastic is above it`s yesterdays value.

Putting autocorrelation phase detection to a test

The most simple trend following strategy I can think about is a moving average crossover strategy. It never works in reality, simply as markets are not trending all the time. But combined with the autocorrelation phase detection, it might have an edge.

Wooha! That`s pretty cool for such a simple strategy. It is trading (long/short) if the market is trending, but does nothing if the market is in a sideway phase. Exactly what I like when using a trend following strategy.

To compare it with the original moving average crossover strategy, the one without the autocorrelation phase detection, you will see the advantage of the autocorrelation phase filter immediately: The equity line is way more volatile than the filtered one and you got lots of drawdowns when the market is sideways.

Stability of parameters

German power has been a quite trendy market over the last years, that`s why even the unfiltered version of this simple trend following strategy shows a positive result, but let`s have a test on the period of the moving average.

Therefore I calculated the return on account of both strategies, the unfiltered and the autocorrelation filtered, for moving average lengths from 3 to 75 days.

Return on account (ROA) =100 if your max drawdown is as big as your return.

The left chart shows the autocorrelation filtered ROA, the right side the straight ahead moving average crossover strategy. You don`t have to be a genius to see the advantage of the autocorrelation filter. Whatever length of moving average you select, you will get a positive result. This stability of parameters can not be seen with the unfiltered strategy.

Autocorrelation conclusion:

Trend following strategies are easy to trade, but only make sense when the market is trending. As shown with the tests above, autocorrelation seems to be a nice way to find out if the market is in the right phase to apply a trend following strategy.

 

Measuring your EDGE in algorithmic trading

There are a lot of statistics which can be used to describe algorithmic trading strategies returns. Risk reward ratio, profit factor, Sharpe ratio, standard deviation of returns… These are great statistics, but they miss an important factor: Are your returns statistically significant or just a collection of lucky noise. The EDGE statistic might me the answer to this question.

 

Statistics in trading:

If the returns of your trading strategy are positive with in-sample and out-of-sample data this is a first sign that you are on the right path. The next step would be to have a look at the risk-reward ratio of your trading to get an impression if the strategy might be useful in a real world environment.

Assuming that your average yearly returns are about twice as big as the worst case historic draw down you can even be more confident that your strategy is useful. But there is still one thing to check before you can be sure that you are not just seeing a curve fit bullshit strategy. The standard deviation of the daily returns vs. your average daily return.

Defining EDGE

Assume your strategy made 250$ over the last year. This averages to about 1$ per day. This 1$ is a good or bad return, depending on the standard deviation of your equity line. If the standard deviation of your equity is 2$, then the 1$ average return strategy would be a bad strategy, as your average returns are way too small in respect to the volatility of your equity. If your volatility of your return curve would just be 50ct and you still make 1$ per day on average, your strategy would be ingenious.

Edge is the ratio of your average returns vs the volatility of your equity line. To be on the safe side,  your average return should be about 5% above the 90% confidence interval of your equity line volatility.

The left chart is a strategy trading an one month RBOB time spread, the right chart shows the same strategy trading German power. Rbob has got an edge of 3%, German power has got an edge of 5%.

If I would have to select which market I want to trade with this sample strategy, I surely would select German power over the rbob time spread. Both curves have their up and downs, but rbob is heavily relying on a lucky trade in September. This lead to a high standard deviation of the equity line , giving you a low edge reading.

Conclusion

Observing the ration between your average daily returns vs. the volatility of your equity curve can give you some valuable insights in the quality of your strategy. If it just called a few lucky trades in history, it will also show a high volatility in returns. And this you most probably want to avoid when turning to algorithmic trading. It`s not just the absolute profit at the end of the year, it is also the path you took to get to this number. The smoother, the better!

Tradesignal Equilla Code for the edge indicator:

This is a basic programming of the edge indicator. Make sure to adopt it to your own needs:

Calculation of returns: absolute/log?

Average: arithmetic average/median/weighted average?

keep researching!

 

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

EEX Phelix Base Yearly – Buy Wednesday, short Thursday?

When it comes to simple trading strategies, the day of the week is surely one of the best things to start with. That’s nothing new when it comes to equity markets. Everybody knows about the calendar effects, based on when the big funds get and invest their money. I do not know about any fundamental reason for the day-of-week effect in German power trading, but is seems to be a fruitful approach.

First of all I have to point out that it is not only the day of the week which is important. A strategy that just buys on Wednesdays and sells 1 or 2 days later would be doomed. But if you add a little filter which confirms the original idea, you will end up with a profitable trading strategy.

This filter will just be a confirmation of the expected move: If you suspect that Wednesday ignites a bullish movement, then wait until Thursday and only buy if the market exceeds Wednesdays high. Same for the short side, wait for a new low before you enter!

Have a look at the chart. The strategy shown buys on Thursdays if Wednesdays high is exceeded. The position is closed 2 days after the entry.

If you run a simple test which day of the week is the best to get ready for a long trade the day after then the next chart shows the return on account of the strategy using data from 2012 up to now: (exit one day after entry)

Continue reading

Bitcoin Trading Strategy – review of returns

Bitcoin is not as bullish as it used to be. May it be due to fundamental reasons like transaction cost and slow speed, or maybe the herd found a new playground, whatever it might be, it is a good time to have a look how my bitcoin trading strategy performed.

The bitcoin trading strategy uses two moving averages for the trend detection, and, when the averages say bullish, the strategy will buy if the market moves above it`s old swing high.

The position is protected with an exit at the last swing low and a 3% trailing stop.

But have a look how this simple strategy performed over the last two years:

Trading on a daily timeframe and investing 10000€ with each entry, the strategy managed to get more than a 100% return over the last 2 years.

Continue reading

The rhythm of the market

Usually we chart the market at it’s absolute level. But what, if we would just chart the net daily, weekly, monthly movement? Would this be an advantage? Would this show us new trading opportunities?

The short answer is: Yes! The trend is not everything, and it seems to be of some significance for further movements, if the market has moved more than x % from the beginning of the day, week or month.

But let’s have a look at some charts – and you will see how well it works:

The first chat is an intraday chart of EuroDollar, 8am-5pm CET. It shows you the daily net movement.

Continue reading

Bitcoin Handelsstrategie

Die Cryprowährung Bitcoin ist zurück!

Sie erlebte ihren Hype vor 2014, doch ging es seitdem fast nur noch bergab. Nach den Hochs um 1000$ für einen Bitcoin Ende 2013 verfiel der Preis bis auf 150$. Doch diese Zeiten scheinen vorbei zu sein, bitcoin is back!

Bitcoin Chart Analyse

Der Chart zeigt den Bitcoin / USD Verlauf der vergangenen 3 Jahre. Es spring sofort ins Auge, dass die lanfristige  fallende Trendlinie im Juni 2015 gebrochen wurde. Seitdem ist neben den Kursen auch das gehandelte Volumen stark am Steigen. (Kurs- und Volumsdaten von  bitstamp.net)

Bitcoin Chartanalyse

Noch immer ist die Volatilität des Marktes extrem hoch, Bitcoin ist ein reines Spekulationsobjekt, beliebt bei Leuten mit Hang zur Weltverschwörung.  Dies sind die besten Voraussetzungen dafür, dass eine automatisches Bitcoin Handelssystem funktionieren kann. Die hohe Volatilität ermöglicht zudem mit geringem Kapitaleinsatz ansprechende Gewinne.

Bitcoin Handelsstrategie

ich bin nicht an die Börse gegangen um mir den ganzen Tag Gedanken über Trendlinien zu machen, ein automatischen Handelssystem für Bitcoin ist da schon eher mein Ding.

Meine Bitcoin Handelsstrategie basiert auf klassischem Swing Trading. Die Strategie selbst wurde auf von mir auf der IFTA Konferenz in Tokyo vorgestellt, IFTA Mitglieder können den vollständigen Systemcode auf der Webseite http://www.ntaa.or.jp/ laden.

Die Basis des System sind die Swing Punkte.

Bitcoin Swing Points

Eine programmierte Definition dieser Punkte finden Sie im Swing Point Stop

Kombiniert man diese Swing Punkte mit einer einfachen Trenderkennung, ergibt sich ein hoch profitables Bitcoin Handelssystem.

Bitcoin Trading Strategy

Bitcoin Handels Regeln:

Continue reading