logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Ben_Zurich  
#1 Posted : Monday, February 12, 2007 6:41:14 AM(UTC)
Ben_Zurich

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/4/2006(UTC)
Posts: 57
Location: Zurich, Switzerland


How can I access the results from the FFT function
through an indicator or another formula ?





hayseed  
#2 Posted : Monday, February 12, 2007 11:13:15 AM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey ben..... can remember having a tough time with that also..... the problem was the number of bars ploted.... can't recall if i ever figured it out..... using the "fft" formula as in below the 1695 is the number of bars, but if you move to a chart that has less bars than 1695 you get an error.... if you move to a chart that has 2000 bars, only 1695 plot....

possibly changed my load options for the charts but can't remember for sure..... more than likely i had no clue as to the proper structure of the indicator.....h

a:= FFT(C ,1695 ,1 ,MEAN ,AMPLITUDE);

a

Ben_Zurich  
#3 Posted : Monday, February 12, 2007 1:25:06 PM(UTC)
Ben_Zurich

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/4/2006(UTC)
Posts: 57
Location: Zurich, Switzerland

thanks for the quick note,
but the output doesn't really make sense to me.

I again get a sort of frequency distribution at the left hand border of the price chart; what the heck should that be good for? Actually, it is not accessible at all - Equis should rethink and redefine this function pretty quickly, or open up the code into a publicly accessible function.


What one would need would be a formula that would require the following input:

a) Lookback period (counted from the most recent date loaded)
b) Rank of Frequency to be displayed (e.g. the 1st most frequent, the n-th most frequent, etc.)
OR
Rank of Amplitude to be displayed (e.g the 1st largest amplitude, etc.)


Then the output needs to be e.g. a rolling result of the rolling FFT lookback period.
This result in turn needs to be available for reading into e.g. Mov or Momtm indicator lengths.






hayseed  
#4 Posted : Monday, February 12, 2007 2:22:55 PM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey ben...... yes i agree.... it's confusing and limited in use as is..... unless there is something we are doing wrong, which is quite possible..... i never emailed or chat with tech support about it...... they have always been good in response.... that might be the next step in understanding the fft......h
Ben_Zurich  
#5 Posted : Monday, February 12, 2007 2:44:28 PM(UTC)
Ben_Zurich

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/4/2006(UTC)
Posts: 57
Location: Zurich, Switzerland

Hey Hayseed,

I actually submitted a support inquiry AND posted here....

Let's wait and see what they will have to say.

Will keep you posted what I hear back.

Cheers.



Ben_Zurich  
#6 Posted : Tuesday, February 13, 2007 4:14:09 AM(UTC)
Ben_Zurich

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/4/2006(UTC)
Posts: 57
Location: Zurich, Switzerland

This is what Equis says:


Dear Sir,

Unfortunately, or FFT functions will not be much help to you. They only return raw data and then only the amplitude, but not the frequency that corresponds to those amplitudes. Because of the limitations on our FFT functions, I have not been able to use then in any formula. The only way to do what you want is to get an FFT DLL file and our support department does not have the resources to create suck a file. You can check the online forum to see if someone there has one or knows of someone able to create such a file.

William Golson

MetaStock Support Representative


wabbit  
#7 Posted : Friday, February 16, 2007 5:46:35 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Ben and H,

I would use caution regarding the FFT alogorithm on stock prices for many many reason, but the main one being, FFT uses 2, 4, 8, 16, 32, 64, 128, 256 or any other value of 2 raised to the power n bars of information. Of course this means, in a stock that has many thousands of bars of information, not all of the data is used in the FFT algorithm to return the results.

When dealing with stock data, we should be analysing ALL of the data, not just 1024 or 2048 bars in a chart because it makes the algorithm faster to run! (The handbook makes a brief mention (like most publications about FFT) that accuracy is sacrificed for speed).

To be more accurate, one should use a DFT (Discrete Fourier Transform) to incorporate all of the data. The algorithm may have to detrend the data, but there will always remain the problem for comparing stock bars to dates when determining the periodicity of any prominant cycle. The DFT and FFT algorithms are freely available on the net and could be easily incorporated into an external function, with some periodicity limitations. (Maybe, given some spare time I might even get around to doing it myself, if someone hasn't already done it already?) If you are really keen to use spectral analysis techniques on stock market data then let me know, I might see what I can come up with...


wabbit [:D]

Derek Worswick  
#8 Posted : Saturday, June 23, 2007 3:39:50 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi ,

Thank you for your prompt answer on the DFT (Discrete Fourier Transform).

If you can help, I am keen to use spectral analysis techniques on stock market data.

Below is the TradeStaion code for the Discrete Fourier Transform

if you could convert it to MetaStock code.

The only the value of the DFT is important not the

Heat Map.

-------------------------------------------------------------------------------------------------------

http://www.traders.com/Documentation/FEEDbk_docs/Archive/012007/TradersTips/TradersTips.html#tradestation
 
 
Strategy: Ehlers DFT
inputs:
 Price( MedianPrice ),
 Window( 50 ), { maximum Window = 50 }
 OverBought( 70 ),
 OverSold( 30 ),
 Frac( 0.5 ) ;
variables:
 HP( 0 ),
 CleanedData( 0 ),
 Per( 0 ),
 CosPer( 0 ),
 CycPer( 0 ),
 Alpha1( 0 ),
 Period( 0 ),
 n( 0 ),
 MaxPwr( 0 ),
 Num( 0 ),
 Denom( 0 ),
 ThreeMinus( 0 ),
 DominantCycle( 0 ),
 Change( 0 ),
 AbsChange( 0 ),
 Count( 0 ),
 DFT_RSI( 0 ) ;
{ arrays are sized for a maximum period of 50 bars }
arrays:
 CosinePart[50]( 0 ),
 SinePart[50]( 0 ),
 Pwr[50]( 0 ),
 DB[50]( 0 ),
 SF[50]( 0 ),
 NetChgAvg[50]( 0 ),
 TotchgAvg[50]( 0 ),
 RSIArray[50]( 0 ) ;
{ detrend data by high-pass filtering with a 40 period
 cut-off }
if CurrentBar <= 5 then
 begin
 HP = Price ;
 CleanedData = Price ;
 end
else if CurrentBar > 5 then
 begin
 Per = 360 / 40 ;
 CosPer = Cosine( Per ) ;
 if CosPer <> 0 then
 Alpha1 = ( 1 - Sine( Per ) ) / CosPer ;
 HP = 0.5 * ( 1 + Alpha1 ) * ( Price - Price[ 1 ] ) +
 Alpha1 * HP[1] ;
 CleanedData = ( HP + 2 * HP[1] + 3 * HP[2] + 3 *
 HP[3] + 2 * HP[4] + HP[5] ) / 12 ;
 end ;
{ calculate DFT }
for Period = 8 to 50
 begin
 CosinePart[Period] = 0 ;
 SinePart[Period] = 0 ;
 for n = 0 to Window - 1
 begin
 CycPer = ( 360 * n ) / Period ;
 CosinePart[Period] = CosinePart[Period] +
 CleanedData[n] * Cosine( CycPer ) ;
 SinePart[Period] = SinePart[Period] +
 CleanedData[n] * Sine( CycPer ) ;
 end ;
 Pwr[Period] = Square( CosinePart[Period] ) +
 Square( SinePart[Period] ) ;
 end ;
{ find maximum power level for normalization }
MaxPwr = Pwr[8] ;
for Period = 8 to 50
 begin
 if Pwr[Period] > MaxPwr then
 MaxPwr = Pwr[Period] ;
 end ;
{ normalize power levels and convert to decibels }
for Period = 8 to 50
 begin
 if MaxPwr > 0 and Pwr[Period] > 0 then
 DB[Period] = -10 * log( 0.01 / ( 1 - 0.99 *
 Pwr[Period] / MaxPwr ) ) / log( 10 ) ;
 if DB[Period] > 20 then
 DB[Period] = 20 ;
 end ;
{ find dominant cycle using CG algorithm }
Num = 0 ;
Denom = 0 ;
for Period = 8 to 50
 begin
 if DB[Period] < 3 then
 begin
 ThreeMinus = 3 - DB[Period] ;
 Num = Num + Period * ThreeMinus ;
 Denom = Denom + ThreeMinus ;
 end ;
 end ;
if Denom <> 0 then
 DominantCycle = Num / Denom ;
Change = Price - Price[1] ;
AbsChange = AbsValue( Change ) ;
for Count = 1 to Window
 begin
 if CurrentBar = 1 then
 begin
 SF[Count] = 1 / Count ;
 NetChgAvg[Count] = ( Price - Price[Count] ) /
 Count ;
 TotChgAvg[Count] = Average( AbsChange, Count ) ;
 end
 else
 begin
 NetChgAvg[Count] = NetChgAvg[Count][1] +
 SF[Count] * ( Change - NetChgAvg[Count][1] ) ;
 TotChgAvg[Count] = TotChgAvg[Count][1] +
 SF[Count] * ( AbsChange -
 TotChgAvg[Count][1] ) ;
 if TotChgAvg[Count] <> 0 then
 RSIArray[Count] = ( 50 *
 ( NetChgAvg[Count] / TotChgAvg[Count] +
 1 ) )
 else
 RSIArray[Count] = 50 ;
 end ;
 end ;
DFT_RSI = RSIArray[ iff( Frac * DominantCycle < 50,
 Frac * DominantCycle, 50 ) ] ;
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
if Currentbar > 1 then
 begin
 if DFT_RSI crosses over OverSold then
 Buy ( "RSI-LE" ) next bar at market ;
 if DFT_RSI crosses under OverBought then
 Sell Short ( "RSI-SE" ) next bar at market ;
 end ;

Hoping you can help

Best regards.

Derek

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.