Using spline(s) - page 3

 
Boxter:
Some Google Chrome translated english explanations of the AFIRMA indi:

"...MA-based digital filter is much closer to the price movement, but with a delay (or lag). There is no lag at MAs on the basis of fitting a smooth function (polynomial or sin/cos in the Fourier transform), but often poorly reproduces the movement of prices. The proposed digital filter MA smoothes price movement for all but the most recent candles, which is equal to the amount of the lag of the filter. These candles are smoothed by fitting a cubic spline method of least squares. At the junction of two superimposed MA, condition of continuity combined MA and its first derivative. The result is a smooth MA, that very closely tracks prices without delay.

The input parameters are:

- Periods - mounted bandpass pass filter, which equals 1 / (2 * Periods);

- Taps - the number of delay/lag candles in the filter (must be an odd number), meaning the filter must be given Taps prices, so he formed a new smoothed value of MA;

- Window - selects an approximation of the filter:

Window = 1 - rectangular window;

Window = 2 - Hanning;

Window = 3 - Hamming;

Window = 4 - Blackman;

Window = 5 - Blackman-Harris.

On the chart, the first part of MA, built a digital filter, represented by a blue curve. The second part of the MA, constructed by fitting a cubic spline curve is depicted in red.

Boxter

We have already something similar (with the usage of those kinds of windowing and some others added too - all in all 12 types of window functions) at this post : https://www.mql5.com/en/forum/general

But back to the subject of applying splies to HP as a sort of better extrapolation method. The problem that I am finding is the following : splines need some space. To explain a bit : splines are meant to do interpolation/extrapolation. If we give splines some control points it will "guess" the interpolated values and we can extend it beyond the rightmost (newest) control point and extrapolate some values (predict values) based on the interpolated value.

Using control points at two consecutive bars (as it is done in the "afirma" - that solution takes a minyte to copy/paste) is not what I am looking after. I would like a more general solution that would allow us to use different (even random) control points and I think that it would be a better solution

_______________________

PS : AFIRMA as is there is a non-causal filter (it is a centered firma + extrapolation). And the extrapolation is like any other extrapolation method - an approximation

 
mladen:
Well

Here is a first variation

A good thing about well defined interpolations (and cubic spline is a well defined interpolation) is that it is very easy to turn them "upside down" - to make them extrapolate instead to interpolate. And this version has both : interpolation based on user defined points, and then, as a sort of "prediction", an extrapolation to the future of the last defined point by required bars

Additional parameter added for that purpose is ExtrapolateBars: as it is saying it is the number of bars that the indicator will extrapolate to the right of the last (rightmost) defined point, and in that case it looks like this (the dotted line on the right is a cubic spline extrapolation) :

It works equally in linear mode too (when you define only 2 control points and when it turns to linear interpolation - in that case it is doing a linear extrapolation)

_________________________

To conclude : this is still a manual nonlinear trend line (user has to define and manage control points) Some "automatic" versions will follow soon I guess as soon as an acceptable manner of automatic finding control points emerges

Cubic spline and extrapolation made new metatrader 4 code compatible (in some case when global variable and local variable with a same name exists in the new metatrader 4, it does not handle those cases properly. All those cases are resolved in this version)

mnt_-_cubic_spline_amp_extrapolation_nmc.mq4

 

Hello mladen, I was offline quit a long time.

I discovered a nice actual paper including an Akime Spline based EMD forcasting with LSTM
"Prediction of Complex Stock Market Data Using an Improved Hybrid EMD-LSTM Model"
https://mdpi-res.com/d_attachment/applsci/applsci-13-01429/article_deploy/applsci-13-01429.pdf

You once wanted to check the MQL capability of the Akima interpolation because it requires 5 nodes for the polynomal slope calculation.
https://www.mql5.com/en/forum/179807/page78#comment_4670331

The following MQL5 EMD librarys contain only the basic cubic spline
https://www.mql5.com/en/articles/439

https://www.mql5.com/en/articles/7601

As you know there are a lot of advantages using the Akima interpolation approach, in particular avoiding overshooting.

There is an Akima spline interpolation code in the interpolation lib of the ALGLIB package: Spline1DBuildAkima
https://www.mql5.com/de/code/1146

A C implementation of the Akima interpolation here
https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/src-html/org/apache/commons/math3/analysis/interpolation/AkimaSplineInterpolator.html#line.48

or an improved Matlab version makima
https://blogs.mathworks.com/cleve/2019/04/29/makima-piecewise-cubic-interpolation/#855d8231-5957-4d70-9cb0-874725181ef5

The LSTM Lib for forecasting is also available
https://www.mql5.com/en/code/24200

In a first step the Akima spline interpolation mod of the EMD lib would be very interesting.
I wasn't very successful so far implementing it.

Forecasting Time Series (Part 1): Empirical Mode Decomposition (EMD) Method
Forecasting Time Series (Part 1): Empirical Mode Decomposition (EMD) Method
  • www.mql5.com
This article deals with the theory and practical use of the algorithm for forecasting time series, based on the empirical decomposition mode. It proposes the MQL implementation of this method and presents test indicators and Expert Advisors.
Reason: