Interpolating data points with polynomial functions

Algorithmic Trading With Matlab

Advanced Algorithmic Trading Strategies

Get Instant Access

You have just seen how a trading system's predictive power for the future changes with the number of rules which are involved in the strategy. In our system these rules have been the fast and slow moving average, the very effective intraday time filter and finally the three exits we added. You have seen that a simpler trading system has more predictive power than a more optimised one. We can state that this result was not just gained by accident but it is well founded on statistical rules. We will explain these rules now with a short discussion on interpolating data points with polynomial functions.

Let's assume that you have 10 data points as your sample data (Figure 5.12).

Figure 5.12: Ten points of sample data, generated with a sinus function and random distances from it. Curve generated with MATLAB.

Figure 5.12: Ten points of sample data, generated with a sinus function and random distances from it. Curve generated with MATLAB.

In our case the 10 points were not chosen randomly but with a combination of a rule and random behaviour. We took a sinus function which is a normal oscillation and placed the 10 points around the sinus function with randomly taken distances. Here these are just mathematical points but as a trader you can imagine that these values could also be the prices of any financial markets, for example values of a tick chart of the FTSE 100 future or any stock you like. Thus our data point simulation is an approximation for financial markets in the way that you assume that the markets have a certain order or direction (at least during special times or events) but that around this order you have lots of random behaviour and market noise.

To interpolate these 10 data points as well as possible you can use mathematic polynomial functions with different complexity. The higher the order of the polynom, the greater its complexity becomes. The easiest polynomial function (degree = 0) is a constant (Figure 5.13).

Figure 5.13: Approximation of the ten data points with a polynomial function of degree = 0, a constant with value = 0. Curve generated with MATLAB.

Figure 5.13: Approximation of the ten data points with a polynomial function of degree = 0, a constant with value = 0. Curve generated with MATLAB.

You see that this horizontal function touches some data points, but other points are a long way from it. The next higher complexity level is to interpolate the 10 data points with a linear function, which is a polynomial of degree 1 (Figure 5.14). In the picture of a trading system this line could be a simple trend line. Since the results of the constant and the linear function are rather poor fits to the 10 data points, we have to increase the adaptive function's complexity. The second order polynomial seems to give a quite good fit to the data points (Figure 5.15). This curve reaches more data points and comes quite close to all points, although not all are reached exactly. If we increase the degree of the polynomial function to 3 we already have a very nice fit to the data points and when we go to a much higher order of polynomial (degree = 9) we obtain a 100% fit to the training data (Figures 5.16 and 5.17). The polynomial of degree 9 passes exactly through each data point.

Figure 5.14: Approximation of the ten data points with a polynomial function of degree = 1, a linear function. Curve generated with MATLAB.

Polynomial of degree n=1

time

Figure 5.15: Approximation of the ten data points with a polynomial function of degree = 2, a parabolic function. Curve generated with MATLAB.

Figure 5.15: Approximation of the ten data points with a polynomial function of degree = 2, a parabolic function. Curve generated with MATLAB.

Figure 5.16: Approximation of the ten data points with a polynomial function of degree = 3. The fitness to the data points increases but also the complexity of the function. Curve generated with MATLAB.

Figure 5.17: Approximation of the ten data points with a complex polynomial function of degree = 9. Curve generated with MATLAB.

Polynomial of degree n=9

time

You can also plot the results of these graphs in a table (Table 5.4). There you see how the average error of the fitness function becomes smaller with a higher degree of polynomial. Whereas the polynomial of degree 0 has a big standard deviation from the 10 data points (5.39), the 9th degree polynomial nearly reaches the points without any error (0.0003).

Table 5.4: Average error of fit to data points (standard deviation) as a function of the degree of the polynomial. The higher the degree of the polynomial, the better its fit to the data points, but the higher its rule complexity becomes.

If you have a closer look at the result of the 9th degree polynomial fit you can see that the fitted curve oscillates wildly and gives only a very poor representation of the chosen sinus-function with the data points randomly around it. This 9th degree polynomial could stand for a very complex trading system with many components added until you have got a perfect fit of the trading logic to your market data.

But what are the conclusions which you can draw from these fitness functions and what is the predictive power of the different polynomials for the future?

Was this article helpful?

0 0
Forex Training Guide

Forex Training Guide

The Foreign Exchange Market (FOREX) offers an unlimited opportunity for profitability if you understand how it works. Expand Your Investment Strategy with FOREX Trading by Learning from the Pros How to Maximize Your Return on Investment.

Get My Free Ebook


Post a comment