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

Regression analysis describes an usually linear relationship between two assets.  This is expressed in a simple equation: Asset2 = Cash+Factor*Asset1. But in reality you will never come across an asset which can be priced using such a simple relationship. Usually the market has several dependencies. This is where multivariate regression analysis comes into play. It outputs an equation in the form of Benchmark = intercept+f1*asset1+f2*asset2+f3*asset3+…  Intercept, f1,f2,f3… would be called the coefficients of this equation and are numbers. To translate this formula into the traders language, we can call the output of a multivariate regression analysis a weighted basket of different assets plus a little cash. The algorithm uses some training data to calculate the individual weightings.

Multivariate regression analysis uses gradient descent to calculate the individual coefficients / weightings. It is an algorithm of the machine learning class. I used the sklearn Python module to do all the calculations.

Drivers of German Power Prices

To give an example how multivariate regression analysis can be used in trading and analysis, I will do an analysis of the German power prices. But feel free to use this kind of analysis with any kind of market and it’s causally correlated drivers.

German Power regression analysis

German Power regression analysis

 

German power, I will use the yearly base price, can be explained by it’s drivers gas (TTF month/season), coal (API2) and the price of emission certificates (CFI2). Depending on the volatility and direction of these legs, power prices will change. (there are surely more drivers, but let’s keep it simple…)

On the chart above a multivariate regression analysis has been used to calculate the influence of TTF month, API2 and CFI2 on the yearly power price. As you can see coal has got the highest influence on power prices, gas and emission prices explain about 30% of the power price move. This is not about the physical energy mix needed to produce power, but the fitting of a weighted basket of energy futures to replicate the index’s movements.

To calculate the numbers shown above  the regression model was trained with the last 30 closing prices of gas, coal and emissions. With every day of new data, the model is automatically re-trained and calculates a new set of coefficients.

If you know the influence of each market on the benchmark, you can also turn it around and calculate the “fair” value of the benchmark, according to the underlying futures. On the chart above today’s gas/coal/emission prices where used to give an estimation for tomorrow’s power price. This is the blue line on top of the power chart.

German Power: TTF month and season

The more legs or driving factors you add, the better your prognosis should be. At least multivariate regression analysis is capable to work with as many legs as you want, if more really means better the results will have to show.

For the chart below I added the TTF season gas contract, additionally to the TTF front month. Together with emissions and coal the regression algorithm now is based on 4 correlated legs. This leads to a slightly more precise prognosis of the power price. Compare the red prognoses (4 legs) to the blue prognosis (3 legs). The downside of adding more legs usually is, that the individual factors get more volatile (as the system has more degrees of freedom).

German Power 4 legs machine learning regression analysis

German Power 4 legs machine learning regression analysis

Beside doing a prediction or calculating a fair value for the benchmark, this kind of analysis is also important in risk control. Knowing the driving factors of your portfolio surely helps in designing the right hedging strategy.

Regression analysis: other markets

Regression analysis is not limited to German power markets and it is not limited to a specific number of legs. The example below shows a regression analysis done to see the influence of the sector ETFs for financial, tech and t-bonds on the SPY. The chart shows the % weightings of a tracking basket and a one day prognosis of SPY using the 3 mentioned ETFs. The model uses the previous 30 closing prices and is retrained every day.

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

VIX Futures spread trading

VIX futures are usually in contango, meaning that the next month future is quoting at a higher price than the current month VIX future. But this spread in not constant, and at the end of the expiry cycle an interesting VIX future spread trading idea comes to my mind…

End of cycle VIX futures spread trading

Having a look at the chart below you hopefully see the spread trading idea by yourself: 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

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

The Probability of Normality

When selling implied volatility you want the market to stay within the  expected range. But what is the historic probability that markets behave as expected? And what other analysis could be done to enhance your chances and find the periods when it is wise to sell an at the money straddle? This article will try to give some answers to this question.

The normal distribution cone

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

S&P500 – when to be invested

The stock market shows some astonishingly stable date based patterns. Using a performance heat map of the S&P500 index, these patterns are easily found.

Date based performance

The chart below shows the profit factor of a long only strategy investing in the S&P500. Green is good, red is bad. The strategy is strictly date based. It always buys and sells on specific days of the month. 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

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.

Factor investing

Buy and hold has been a profitable approach in investing. But customers ask for more. So technical analysis came around and held up the promise that market timing is possible. As the returns did not match this promise, algorithmic trading was invented. Clearly defined rules made it possible to backtest any given strategy, and if done properly, the returns equal the ones promised during the backtest. But this requires a lot of intellectual power and relies on cheap execution, so these returns are usually not available to the public. Continue reading

Dollar Cost Averaging Investment Strategy – success based on luck?

This article is about the dollar cost averaging investment strategy and the influence of luck in it.

The Dollar Cost Averaging Investment Strategy

To invest parts of your income into financial markets has been a profitable approach, especially in times when bond yields are low. One approach to do so is the dollar cost averaging investment strategy. Continue reading

Historic Bear Markets & Crashes (business as usual)

Since S&P500 has lost 20% from its top in 2018 and everybody is talking about bear markets. See what has happened in history.

We all have been spoiled by artificially low volatility over the last years.

Now people blame the gone-wild president or algorithmic trading for the market correction, but let us have a look into history to see how common market corrections have been over the last century. 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

Bullish? Buy stock or sell put option?

So you are bullish on a specific stock, but you also have realised that timing is major problem? So what would be the best strategy to implement your bullish opinion but avoid the problems of any timing strategy?

Selling a put option might be the answer.

Bullish probability

For discussing this question let’s use the current Apple chart as an example. The question is, if you are bullish on apple, should you buy 100 Apple stocks right away or should you sell an at-the-money put option. To find the pros and cons of these two possibilities let’s have a look at some charts. Continue reading

Technical vs. Quantitative Analysis

“The stock market is never obvious. It is designed to fool most of the people, most of the time” Jesse Livermore

Technical Analysis

Technical analysis is a form of market analysis based on historic price patterns. The basic assumption of technical analysis is, that human behaviour does not change over time, and thus similar historic market behaviour will lead to similar future behaviour. Technical analysis is a predictive form of analysis, a technical analyst will try to estimate what the market might most probably do over the next period of time. Continue reading