Help with Fourier - page 8

 
ANG3110 писал (а):
klot wrote (a):
ANG3110 wrote (a):
With hmax =2; there will be a simple MA, on a given period, it's not quite clear, why bother with a full FFT then?

Nah, I noticed too, full FFT is much more stable (less redrawing).
In general, I think you need to filter
if(hmax>0) for(i=hmax;i<N;i++) data[i]=0.0;
to make up some smart filter. We need it to selectively leave the necessary harmonics, and zero out the unnecessary ones. Then it may have some sense and stability.

Also, NeuroshellDayTrader uses five or six different filters in FFTadon, sorry I don't have formulas, I could tinker with them.
And if you limit frequencies not only at the top but also at the bottom, you can select a certain band of oscillations. The indicator looks nice, it reminds of a stochastic.
The goodness with it let it redraw. The Fourier's value is that if it is appropriately tuned, it shows well the times where turning points are probable. And the fact that the amplitude trajectory does not coincide very much is not so bad, on the contrary it is good, the phase change velocity can be taken into account.

Actually, I don't mind. :) Phase is a phase, you can easily calculate it too.
After direct FFT in data array, in even cell the real part is stored in odd cell, in odd cell the imaginary part is stored,
the phase will be:
MathArctan(data[2*i+1]/data[2*i]);
amplitude will be
MathSqrt(data[2*i+1]*data[2*i+1]+data[2*i]*data[2*i]);
again, select the required harmonic and watch :)
you can sum up the phases and amplitudes in a given frequency band and draw some conclusions :)
 
klot писал (а):

I don't mind, actually. :) Phase is a phase, it's easy to calculate, too.
After direct FFT in data array in even cell the real part is stored in odd cell the imaginary one,
the phase will be:
MathArctan(data[2*i+1]/data[2*i]);
amplitude will be
MathSqrt(data[2*i+1]*data[2*i+1]+data[2*i]*data[2*i]);
again, select the required harmonic and watch :)
you can sum up the phases and amplitudes in a given frequency band and draw some conclusions :)

Yes, and the amplitudes of the harmonics can even be plotted against time:



And this is a 48 hour harmonic spectrum in 1 hour steps, plotted for the current time.

 
ANG3110 писал (а):
klot wrote (a):

I don't mind, actually. :) Phase is a phase, you can easily calculate it too.
After direct FFT in data array in even cell the real part is stored in odd cell the imaginary one,
the phase will be:
MathArctan(data[2*i+1]/data[2*i]);
amplitude will be
MathSqrt(data[2*i+1]*data[2*i+1]+data[2*i]*data[2*i]);
again, select the required harmonic and watch :)
you can sum up the phases and amplitudes in a given frequency band and draw some conclusions :)
And I have a nice drawing too.
At present, I think this system plus a neural network, the most promising for forex. Well of course strictly IMHO. :)
 

I actually have this idea about applying the Fourier method.

Fourier method gives good enough approximation of function on time interval excluding some neighborhood of ends (interval). It would be nice if Fourier approximated the end that corresponds to the current time (t=0) as well as the middle of the interval. It would also be nice to construct a Fourier series so that it can predict the future. To do this we can apply the following idea:

Let us build a Fourier series on the interval [T,-T] (-T - time which has not yet occurred, t=0 - present time)
However, we do not have any data on the interval [0,-T]. Therefore at the zero iteration we will take close[t]=close[0] (for t<0) and use this data to build a Fourier series f on the interval [T,-T]. And then we iterate sequentially as follows:

1) Construct on the interval [eps,-T] an approximation of the Fourier series f by a power function g (eps>0)
2) Construct a Fourier series for the interval [T,-T] by f (on T>t>eps) + g (on eps>t>-T)

That is we will consistently approximate the resulting function first by a Fourier series and then by a power function. There's an assumption that the misalignment {transformed forecasted price function (t<0) + history price function (t>0)} with {Fourier series of that function} will be minimal (i.e. tend to zero with increasing number of iterations). I think it is a necessary condition for the end [eps,0] to coincide well with the price function, and secondly, we will get a forecast for the future.

 
shobvas писал (а):

I actually have this idea about Fourier method application.

Fourier method gives good enough approximation of function on time interval excluding some neighborhood of ends (interval). It would be nice if Fourier approximated end that is responsible for current time (t=0) as well as middle of interval. It would also be nice to build a Fourier series so that it can predict the future. To do this we can apply the following idea:

We will build a Fourier series on the interval [T,-T] (T is time that has not yet occurred, t=0 is the present time).
However, we do not have any data on the interval [0,-T]. Therefore at the zero iteration we take close[t]=close[0] (for t<0) and plot the Fourier series f on the interval [T,-T] using this data. And then we iterate sequentially as follows:

1) On the interval [eps,-T] we approximate the Fourier series f by the power function g (eps>0)
2) Construct a Fourier series for [T,-T] on f (on T>t>eps) + g (on eps>t>-T)

It means that we sequentially approximate the resulting function first with a Fourier series and then with a power function. There is an assumption that the misalignment {transformed forecasted price function (t<0) + historical price function (t>0)} with {Fourier series of this function} will be minimal (i.e. tend to zero with increasing number of iterations). I think it is a necessary condition for the end [eps,0] to coincide well with the price function, and secondly, we will get a forecast for the future.


Why bother with Fourier equations when you can very simply filter out a series of prices without knowledge of individual harmonics. For example, high frequency harmonics can be filtered by a simple moving average or a digital filter. Unfortunately, SMA, EMA and other digital filters have a delay. Then the last interval of the price series can be approximated by a power function. This idea is implemented here:

'AFIRMA'.

All that remains is to extrapolate the power function. But the prediction will be very poor. In general, extrapolating the price of a series based on fitting a smooth function is a waste of time. Extrapolating a Fourier series will also get us nowhere. If you extrapolate a cosine Fourier series, it is essentially assuming that in the future the price will move along a trajectory that is an exact mirror copy of the past trajectory. If you extrapolate a sine Fourier series, it is essentially assuming that in the future the price will move along a trajectory that is an inverted mirror copy of the past trajectory. What's the point of the Fourier series then? Decide for yourself how the old trajectory will be mirrored into the future and off you go!
 
gpwr писал (а):
The only thing left to do is to extrapolate the step function. But the prediction will be very poor. In general, extrapolating the price of a series based on fitting smooth functions is a waste of time. Extrapolating a Fourier series will also get us nowhere. If you extrapolate a cosine Fourier series, it is essentially assuming that in the future the price will move along a trajectory that is an exact mirror copy of the past trajectory. If you extrapolate a sine Fourier series, it is essentially assuming that in the future the price will move along a trajectory that is an inverted mirror copy of the past trajectory. What is the Fourier series for then? Decide for yourself how the old trajectory will mirror into the future
and off you go!

You should have read what I wrote more carefully.
If you draw a Fourier series on the interval [T,0] and try to calculate the value at t<0 using harmonic coefficients then you will get a symmetric value. But I proposed to build a Fourier series for the interval [T,-T], it obviously will not be symmetric about 0!!!! That's why we need iterations to build a Fourier series on such a segment.

gpwr wrote (a):
Then the last interval of the price series can be approximated by a power function. This idea is implemented here:

'AFIRMA'.

I have seen this indicator. It's not a bad indicator. But agree that there is a Fourier series that approximates the function at the ends as well as in the middle.
 
Here's a picture - the Koch's phrontal curve, from top to bottom five steps in its construction. Each straight line
is divided into three sections and the middle section is connected by an angle.




At infinite iterations it turns into a "fluffy snowflake".

Here is the Mandelbrot fractal curve and its construction steps. Each straight line is replaced
by a zigzag.



At infinite iteration it becomes similar to a quotation chart.

I think it's clear that fractal curves cannot be extrapolated
using spectral decomposition or linear approximations. For fractal
curves it is possible only by similarity methods.

Of course nobody has proved that real quotes are similar to fractal functions, but
the fact that graphs are self-similar (i.e. if you remove scales it becomes impossible
to distinguish for example minutiae from vicle) leads one to think about their fractal-like
nature.

In his work Multifractal Walk on Wall Street
Mandelbrot proposes to use
fractals based on deformed zigzags. But I think the reality is even
more complicated.

 
shobvas писал (а):
But agree that there is a Fourier series that approximates the function at the ends as well as in the middle, it just can't be found out of the blue!

Yes, there is. It's a complete Fourier series, with sines and cosines. But it's also flawed. The frequencies of the discrete Fourier transform are given by the formula 2*pi*k/N. That is, all the sines and cosines in the Fourier series will repeat their values with a periodicity of N bars: cos(2*pi*k/N*i)=cos(2*pi*k/N*(i+N)), sin(2*pi*k/N*i)=sin(2*pi*k/N*(i+N)). So the extrapolation of the Fourier series will result in a repetition of the past. For example, today's price will repeat itself after N bars. Since you select N you will control when the price will repeat. Again. Why do you need a full Fourier series? Decide for yourself after how many bars price will repeat and start trading.

The extrapolation of a power function is also irrelevant. You cannot predict the market by fitting some functions to historical data. You must use either statistical or self-learning methods. Read books about econometrics and time series analysis. The most common prediction method is the Box-Jenkins autoregressive method. The problem with this method is that you can fit a truckload into its confidence interval. It seems to me that more success should be expected from self-learning neural networks.
 
gpwr писал (а):
shobvas wrote (a):
But agree that there is a Fourier series that would approximate the function at the ends as well as in the middle, you just can't find it so bluntly!

Yes, there is. It's a complete Fourier series, with sines and cosines. But it's also flawed. The frequencies of the discrete Fourier transform are given by the formula 2*pi*k/N. That is, all the sines and cosines in the Fourier series will repeat their values with a periodicity of N bars: cos(2*pi*k/N*i)=cos(2*pi*k/N*(i+N)), sin(2*pi*k/N*i)=sin(2*pi*k/N*(i+N)). So extrapolating the Fourier series will result in a repetition of the past. For example, today's price will repeat itself after N bars. Since you select N you will control when the price will repeat. Again. Why do you need a full Fourier series? Decide for yourself after how many bars price will repeat and start trading.

The extrapolation of a power function is also irrelevant. You cannot predict the market by fitting some functions to historical data. You must use either statistical or self-learning methods. Read books about econometrics and time series analysis. The most common prediction method is the Box-Jenkins autoregressive method. The problem with this method is that you can fit a truckload into its confidence interval. I think more success should be expected from self-learning neural networks.

The results are not bad if we make a support for Fourier decomposition. In particular, we can easily extrapolate the regression forward and build the Fourier relative to it. You can put a mouving as a support and plot the sum of harmonics, in a separate window, as if the mouving continues linearly. You can base it on a smoothly varying average like T3 shifted by half a period back to fit the data exactly, and extrapolate the end with a parabola, which is adjusted for minimum RMS, and plot the Fourier relative to this extrapolation. But in any case, there is a high probability of repeating cycles if we build several variants of the Fourier extrapolation with different periods and optimize each variant with respect to the minimum RMS. If there is a coincidence in the readings of several variants, they can be considered probable. If there is further advance or lag, this will produce a corrective difference signal that can be used for auto-tuning or recalculation. This is reminiscent of the FATF detector in radio receivers, which is the most efficient and immune to interference.
 
New писал (а):
Here's a picture - the Koch's phrontal curve, from top to bottom five steps in its construction. Each straight line
is divided into three sections and the middle section is connected by an angle.

...

Of course nobody has proved that real quotes are like fractal functions, but
the fact that charts are self-similar (i.e. if you remove the scale it becomes impossible to
to distinguish for example minutiae from vicle) leads one to think about their fractal-like
nature.
Fractals have nothing to do with it. The topic is about Fourier series. Why did you bring up so much off-topic flameworthiness? Besides, you won't believe it, but I can easily tell minutes from 15 minutes and 15 minutes from hours.

gpwr wrote (a):
Yes there is. It's a full Fourier series, i.e. with sines and cosines. But it has flaws too. The frequencies of the discrete Fourier transform are given by the formula 2*pi*k/N. That is, all the sines and cosines in the Fourier series will repeat their values with a periodicity of N bars: cos(2*pi*k/N*i)=cos(2*pi*k/N*(i+N)), sin(2*pi*k/N*i)=sin(2*pi*k/N*(i+N)). So extrapolating a Fourier series will result in a repetition of the past.
I see no point in explaining a second time why there will be no repetition and symmetry.