|
Hello,
>would have been even a little bit more happy if the
function should have been like this :
>FFT(Array, Len, Start, End )
There is no reason to do this like that because it would be
redundant.
Already available FFT function allows that as
well.
As you probably know the syntax of FFT(Array, Len,
Start, End ) is redundant
because it does not make sense to define "End"
parameter if you already defined "Len",
simply because End = Start + Len;
So if you are after FFT( array, len, start )
where "start" refers to "start bar" it can be done using
existing function:
function FFT2( array, len, start )
{
return FFT( Ref( array, start ), len );
}
Best
regards, Tomasz Janeczko amibroker.com
----- Original Message -----
Sent: Saturday, October 14, 2006 3:20
PM
Subject: Re: [amibroker] Re: FFT example
(4.86 beta required)
Thanks Fred. I understood that what TJ posted was
an example of how to use the FFT function in a AFL formula. I also know that
what I want to do can be done within AFL by cutting the timeserie in pieces.
Although I am more than happy with the FFT function and am sending Tomasz
flowers for being so fast with AB developments, I would have been even a
little bit more happy if the function should have been like this
:
FFT(Array, Len, Start, End ). Again I know
this can be done within AFL but I am wondering if this kind of looping thru
the timeseries is not a hell of a lot faster in the FFT function than in
AFL code. Therefore to make a long story short, I did not agree with TJ answer
to PS. That's all ...
Talking about Fourier Analysis, as you know doing
the standard Fourier Analysis integration process you will get a bunch of
sine/cosine waves that combined with the trend will give you the original
timeserie again. Normally 3 to 6 will suffice. Having the first harmonic of
course does not give me the higher harmonics. Any idea how this can
be done with FFT and more in particular the FFT() function in AB ?
Ton.
----- Original Message -----
Sent: Friday, October 13, 2006 5:11
PM
Subject: [amibroker] Re: FFT example
(4.86 beta required)
What TJ posted was simply an EXAMPLE of how to use the FFT that he
built into the product ...
What you are asking for is easily
doable in AFL by downshifting the data array by the difference between
LastValue(BarIndex()) and either
SelectedValue(BarIndex()) or EndValue(BarIndex()) and then
basing the AFL calculations on SelectedValue or EndValue ( Range
Marker ) respectively rather than LastValue ...
--- In [EMAIL PROTECTED]ps.com,
"Ton Sieverding" <ton.sieverding@...> wrote: > >
I agree with PS, Thomasz. For BackTesting purposes it would have been
nice to be able to select the last value in de FFT. Also for other
analysis like checking the stability of the first harmonic, it would
have been nice to have a last value selection in FFT not being the last
value of the financial timeserie. Now I first must cut the timeserie in
several parts in order to do that. Or am I missing something ? >
> Ton. > > ----- Original Message ----- > From:
Tomasz Janeczko > To: [EMAIL PROTECTED]ps.com
> Sent: Thursday, October 12, 2006 9:19 PM > Subject: Re:
[amibroker] Re: FFT example (4.86 beta required) > > >
Hello, > > Yes it uses last value. But if you are after finding
cycles > you have to assume anyway that given cycle will last at least
a bit, > without such assumption there are no cycles :-) >
So last value from say one year back should work forward. > >
Best regards, > Tomasz Janeczko > amibroker.com > -----
Original Message ----- > From: "vlanschot" <[EMAIL PROTECTED]> >
To: <[EMAIL PROTECTED]ps.com> >
Sent: Thursday, October 12, 2006 12:42 PM > Subject: [amibroker] Re:
FFT example (4.86 beta required) > > > Thanks TJ, >
> > > Just wondering if I am correct that one has to be careful
in > > extending this in backtests, since detrending (LR) is based
on the > > last value of the regression? > > >
> PS > > > > --- In [EMAIL PROTECTED]ps.com,
"Tomasz Janeczko" <groups@> > > wrote: >
>> > >> Hello, > >> > >> Here are
few words about new FFT function. > >> It requires AmiBroker
4.86 BETA to run. > >> http://www.amibroker.com/devlog/2006/10/11/amibroker-4860- beta- >
> released/ > >> =============== > >>
> >> FFT( array, len = 0 ) > >> > >>
performs FFT (Fast Fourier Transform) on last 'len' bars of the >
> array, if len is set to zero, then FFT is performed > >> on
entire array. len parameter must be even. > >> > >>
Result: > >> > >> function returns array which
holds FFT bins for first 'len' bars. > > There are len/2 FFT
complex bins returned, > >> where bin is a pair of numbers
(complex number): first is real part > > of the complex number
and second number > >> is the imaginary part of the complex
number. > >> > >> result = FFT( array, 256
); > >> > >> where: > >> 0th bin
(result[0] and result[1]) represents DC component, > >> 1st bin
(result[1 ] and result[2]) represents real and imaginary > >
parts of lowest frequency range > >> and so on upto result[ len
- 2 ] and result[ len - 1 ] > >> > >> remaining
elements of the array are set to zero. > >> > >>
FFT bins are complex numbers and do not represent real amplitude
> > and phase. To obtain amplitude and > >> phase from
bins you need to convert inside the formula. The > > following
code snipplet does that: > >> > >> ffc =
FFT(data,Len); > >> for( i = 0; i < Len - 1; i = i + 2
) > >> { > >> amp[ i ] = amp[ i + 1 ] = sqrt(ffc[
i ]^ 2 + ffc[ i + 1 ] > > ^2); > >> phase[ i ] =
phase[ i + 1 ] = atan2( ffc[ i + 1], ffc[ i ] ); > >> } >
>> > >> IMPORTANT note: input array for FFT must NOT
contain any Null > > values. Use Nz() function to convert Nulls to
zeros > >> if you are not sure that input array is free from
nulls. > >> > >> > >> Below is example
code showing how to use new FFT function in AFL. > >>
> >> SetBarsRequired(100000,100000); >
>> > >> Len = Param("FFT Length", 1024, 64, 10000, 10 );
> >> > >> Len = Min( Len, BarCount ); >
>> > >> x = BarIndex(); > >> x1 = x -
BarCount + Len; > >> > >> > >> input
= C; > >> a = LastValue( LinRegIntercept( input, Len - 1 ) );
> >> b = LastValue( LinRegSlope( input, Len - 1 ) ); >
>> > >> > >> Lr = a + b * x1; >
>> > >> data = "" - Lr;// de-trending >
>> > >> ffc = FFT(data,Len); > >>
> >> for( i = 0; i < Len - 1; i = i + 2 ) > >>
{ > >> amp[ i ] = amp[ i + 1 ] = sqrt(ffc[ i ]^ 2 + ffc[ i + 1
]^2); > >> phase[ i ] = phase[ i + 1 ] = atan2( ffc[ i + 1],
ffc[ i ] ); > >> } > >> > >> auto =
ParamToggle("Auto dominant cycle", "No|Yes", 1 ); > >>
sbar = Param( "Which FFT bin", 1, 0, 50 ); > >> >
>> skipbin1 = ParamToggle("Skip 1st FFT bin", "No|Yes", 1 );
> >> > >> if( auto ) > >> { >
>> sbar = int( LastValue(ValueWhen( amp == LastValue(Highest(
IIf ( > > skipbin1 AND x < 4, 0 , amp ) )), x / 2 )) );
> >> } > >> > >> fv =
Status("firstvisiblebar"); > >> > >> thisbar
= Ref( int(x/2) == sbar, -fv); > >> Plot(
Ref(amp,-fv),"amplitude (bin " + Ref( int(x/2), -fv ) +")",
> > IIf( thisbar, colorRed, colorBlack ),styleArea); >
>> > >> Plot( IIf( BarCount - BarIndex() < Len, data,
Null ) , "de- trended > > input ("+Len+" bars)", colorOrange,
styleLeftAxisScale ); > >> Plot( cos( phase[ sbar * 2 ] +
(sbar) * x1 * 2 * 3.1415926 / > > Len ), "dominant cycle "+
Len/(sbar) + "(" + sbar + " bin) bars", > > colorBlue,
styleOwnScale ); > >> > >> GraphZOrder=1;
> >> GraphXSpace = 10; > >> > >> Best
regards, > >> Tomasz Janeczko > >>
amibroker.com > >> > > > > > >
> > > > > > Please note that this group is for
discussion between users only. > > > > To get support
from AmiBroker please send an e-mail directly to > > SUPPORT
{at} amibroker.com > > > > For other support material
please check also: > > http://www.amibroker.com/support.html >
> > > > > Yahoo! Groups Links > > >
> > > > > > > >
> >
__._,_.___
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
__,_._,___
|