Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K.
HUTSON
Using Fourier
by JACK K. HUTSON
J oseph Fourier (1768-1830) (pronounced "fooryay'') was a French mathematician and inventor of
Fourier analysis. His work helped show the way to expressing periodic curves or functions by a sum of
sines and cosines. These simple functions are easy for our computer to evaluate and project into the
future. Many natural physical phenomena are oscillatory, that is repeating over and over again, much like
the Markets.
The Markets are not a function in the mathematical sense, but do seem to go up and down over and over
again. During the late 1960's a number of Fast Fourier Transforms methods were divised to 'transform'
time dependent data, such as the daily market close, to frequency. The frequency Vs. amplitude squared
is referred to as the 'Power or Transformation Spectrum'. A typical plot of a 'Transformation Spectrum' is
shown in Figure 1. The plot shows which frequency has the most relative impact on daily (weekly,
monthly) closes.
FAST FOURIER TRANSFORM WITH DATA PREPROCESSING
The program Fourier Analysis, included in this issue, was developed on two microcomputers: the Radio
Shack (Tandy) Color Computer™, and the Apple ][™. The original Fast Fourier Transform Algorithm
(Cooley-Tukey 1965) was supplied to us by one of the co-authors, James W. Cooley, at the IBM Thomas
J. Watson Research Center, and we would like to express our gratitude to him. Most of the
microcomputers on the market today operate with a BASIC interpreter developed here in the Seattle area
by a prominent company called Microsoft™. (This includes the Apple as well). Transferring this BASIC
program, or almost anything written in BASIC, to another machine would not be a programming problem
since the microcomputer BASIC's are so similar.
With this Fourier routine one must translate significant frequencies into cycle length by hand (see below
under WHAT IS IT). The method behind the FFT is a mathematical operation known as the Discrete
Fourier Transform (DFT). Each daily close is used as a discrete data point. If each and every daily close
was used to compute the 'Transformation Spectrum' (see Dr. Warren's aritcle) you would get half as many
frequencies as daily closes. In addition an "FFT Composite" graph using the total spectrum would pass
through the daily closes exactly (i.e. the process is reversible).
ABOUT THE PROGRAM OPERATION
The program presented here will take all the data from any column, truncate any leading or trailing zeros
(possibly from prior studies), detrend, level and apply a 'window' to the data (see Dr. Warren's article).
Then the data array length is doubled by adding zeroes to increase the output resolution. An optimized
Discrete Real Fast Fourier Transform is performed that is about eight times faster than the original
Compu Trac transform. This speed increase is possible because we have reduced the number of
computations (multiplication and division) in the innermost (time critical) programming iteration and the
fact that we use a REAL-FFT rather than a COMPLEX-FFT such as Compu Trac's version). FFT Power
(this is the amplitude squared) or Amplitude is computed in terms of Percentage of TOTAL Power (or
Article Text Copyright (c) Technical Analysis Inc. 1
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
FIGURE 1:
Copyright (c) Technical Analysis Inc.
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
amplitude) and stored in the Study column for the Compu Trac system to graph.
In an effort to save time we have implemented a high speed algorithm for computing the discrete Fourier
transfrom known as the Real Fast Fourier Transform (FFT). The term 'Real' refers to the type of data used
as input (i.e. Real Vs. Complex). Speed is a real problem, so some shortcuts have been made. The
number of days of data used has been limited to those that equal powers of 2 (i.e. 4, 8, 16, 32, 64, 128 &
256 etc.). This is a great help in speeding up the computation from a two hour wait to less than two
minutes.
The program is comprised of a number of subroutines written in BASIC. Although the program was
designed to be used from within the Compu Trac System, it may be modified to run on any computer.
The Compu Trac System runs on an Apple ][™ computer and contains many thousands of lines of
programming code similar to the program included in Dr. Warren's article (refer elsewhere in this issue).
When using the Compu Trac System, the program is accessed through the Study (2.) Menu and followed
by User Study Program (A.). At this point the Compu Trac system will prompt you for a Study
Number.(We have used 30)
STUDY NO.: 30
and proceed to 'EXEC', the BASIC computer routine stored on your Data Disk (as a 'T' type sequential
text file named STUDY.30).
NOTE: For those of you that would prefer not to laboriously type 120 lines into the Compu Trac
Programming Subsystem, a disk may be purchased for $20 from TECHNICAL ANALYSIS, P.O. Box
46518, Seattle, WA 98146. This program, as well as the entire magazine contents, is Copyright 1983 by
TECHNICAL ANALYSIS of Stocks and Commodities (All Rights Reserved) through the United States
Register of Copyrights, Library of Congress, Washington, D.C. 20559.
Because of the size of this program it will take about 50 seconds to load Fourier Analysis into the Compu
Trac system. This slow loading could be eliminated only at the expense of added program complexity. It
will become clear in future issues of Technical Analysis that this Fourier Analysis tool has a myriad of
applications including selection of moving average lengths and evaluation of other trading systems.
The following line will then appear at the Command line:
1:O 2:H 3:L 4:C 5:V 6:OI 7:S :
This is your prompt to choose which COLUMN of data you wish to run Fourier Analysis against.
1 = 1:O Open Mean open trade price
2 = 2:H High Highest trade price
3 = 3:L Low Lowest trade price
4 = 4:C Close Last trade or bid price
5 = 5:V Volume Number of shares or contracts traded
6 = 6:OI Open Interest Total contracts or optioned shares
7 = 7:S Study Last Study results
Article Text Copyright (c) Technical Analysis Inc. 2
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
Fourier Analysis will preprocess the data in the matrix column of your choice, do the Fast Fourier
Transform, and then ask:
1:Power 2:Amplitude Vs. Frequency
This is the prompt for you to specify the type of plot i.e. 1) for Power or 2) for Amplitude (square root of
power). The transform result is stored in the Study column. The Compu Trac System then takes over and
graphs the Fourier Transform from the study column.
WHAT IS IT (THE FOURLER TRAMFORM)?
1) The X-Axis (from RIGHT to LEFT i.e. 0 to N/2) is the Frequency (complete cycles).
N
Days in Cycle= ,
Frequency
N = Length of FFT series
NOTE: This RIGHT to LEFT graphing method is just the reverse of text book examples, but works best
from within the Compu Trac System. To determine the most prominent Frequency, use (from within
Compu Trac) Tool Menu (3.) and then Vertical Line (B.). This feature displays the number of points
between the right margin (0) and any Frequency plotted to the left by using the Arrow keys or Game
Paddle control.
2) The Y-Axis is the Percent (%) of TOTAL Discrete Fast Fourier Transform Power or Amplitude
present at that Frequency. This is a direct relative measure of the detrended data's cyclical price
movement as a function of Frequency.
EXAMPLES → INTERPRETATION SUGGESTIONS
A major application of the Fourier Transform is in the design and verification of filters, such as a moving
average. With this tool one may 'design' a filter that enhances large component cycles and suppresses
minor aberrations or random market noise. Refer to Figure 2 for an example showing the effect of a
seven day simple linear moving average on the Fourier Analysis plot output. By comparing this with the
raw data Fourier Analysis plot (Figure 1) the moving average filtering effect is apparent.
Figure 3 is a three dimensional representation of a series of Fourier Transforms using different quantities
of data. By using the new FFT program we may display one slice of this graph at a time. Each slice is
shown as a cut at the WEEKS (of daily data) axis 29, 32, ... ,50, and 53. It is apparent that for this
security (IBM prior to September 16, 1982) as the number of weeks of daily data is increased the long
cyclical content of the closing prices which were used completely over-powers the effect of shorter cycles.
Let us briefly examine a concrete example, using Fourier Analysis, and propose a few applications and
point out a pitfall or two. Look again at Figure 1, the approximate mean highest line in Area A. is a peak
area of cycle strength (i.e. 256/21 = 12.2 Day Cycle). This means one of the cycles prominent in this data
is about 12 days in length.
USE OF THE AMPLITUDE PLOT:
The relative importance of individual cycles may be approximated by adding the heights of adjacent
Article Text Copyright (c) Technical Analysis Inc. 3
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
FIGURE 2:
FIGURE 3:
Figures Copyright (c) Technical Analysis Inc. 6
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
histogram bars on either side of the peak. If the Amplitude plot option is used this will be in percent of
the total cyclic price movement. The total of all histogram bars has been normalized to equal 100% prior
to plotting with both the Power and Amplitude plot options. With the Compu Trac system one may center
the 'live cursor' above the peak and review the Fourier study data by using the systems hidden command
'P'. By pressing 'P' the screen will display seven days of historical data centered around the live cursor
position. In this case adding the Fourier study results shows about 28% of the cyclic price motion is
centered about a 12 Day Cycle. Actually, Area A. encompasses cycle lengths of between 9 to 15 days
centered at about 12 days. The 9 to 15 day AREA A. is 28% of the total price motion.
GENERAL RULE:
The Higher The Frequency The More Likely The Cycle Is Important.
That is, when a peak, located AWAY from the right side of the screen. occurs. This means the data has
oscillated over and over a number of times in the past. Thus the probability that that cycle is significant is
increased the further the peak is located, on our plot, to the left. The fact that we have detected a larger
(to the left) frequency of that cycle implies that statistically our sample size, of cycles, is larger and
therefore more likely to continue into the future.
For example suppose a peak was found located at 2 lines from the right, on our plot, with N = 256 this
would suggest a 128 Day Cycle. But, with the Technical Analysis Fourier program, to obtain an N= 256
we could have used as few as 65 Days of data (see Dr. Warren's article). To have a peak located at a 128
Day Cycle our data would have to be 'shaped' something like Figure 4.
Since Fourier Analysis indiscriminately interprets ANY data as a cycle, this 'Cycle' would be the most
significant (128 days). It should be obvious that, although one could imagine a cycle of this shape (Figure
4) repeating itself, it is hardly statistically important. For Stock or Commodity analysis we need more
cycles samples in our data to infer any cyclic continuity into the future. The practical crux of this is that
PLOTTED PEAKS IN THE 1 TO (about) 6 FREQUENCY RANGE SHOULD BE USED ONLY WITH
A GREAT DEAL OF CAUTION. At a later date we will write about filters and detrending that may be
used to help alleviate part of this problem (Highpass, Bandpass, etc.).
A NOTE ABOUT THE EXISTING COMPU TRAC FOURIER ANALYSIS(U.) PROGRAM
The Compu Trac program will Fourier Transform a quantity of daily (weekly, monthly) data equal to a
power of two up to seven (i.e. 27 = 128). Thus N can equal 4, 8, 16, 64 or 128 days of data. If more data
is available only the last 128 days will be used. The program allows transformation of the daily close
column. This restriction may be circumvented by moving the data, such as the study column, to the close
column just prior to Fourier Transform with Tool Menu (3.) and then Move column (G.).
NO DATA PREPROCESSING IS PROVIDED PRIOR TO THE FOURIER
TRANSFORMATION.
Without at least some sort of detrending preprocessing the Transform results could be severely skewed
toward the long cycle end of the frequency spectrum in a trending market. Thus the system should only
be used on sideways markets or one of the oscillatory systems. such as Relative Strength, these are
already detrended. The Amplitudes that are displayed are those with the greatest magnitude. The
technique used to graph the derived cycles and extrapulate a forecast is an appealing visual experience.
Article Text Copyright (c) Technical Analysis Inc. 4
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
FIGURE 4:
Stocks & Commodities V. 1:2 (32-35): Using Fourier by JACK K. HUTSON
Our routine does not provide its own graphics, but relies on the standard Compu Trac 'Histogram'
graphics routine.
Please note that the Compu Trac Fourier Analysis Study has been released for many months. It is much
easier for us to revise and improve on an existing idea than research and produce the original.
1. Brigham, E. Oran, The Fast Fourier Transform. Englewood Cliffs, N.J.: Prentice-Hall, 1974.
2. Cooley, J.W., P.A.W. Lewis, and P.D. Welch, "The Fast Fourier Transform and Its
Applications," IEEE Trans. Education, Vol. E-12, pp. 27-34, March 1969.
3. Hurst, J.M., The Profit Magic of Stock Transaction Timing. Englewood Cliffs, N.J.:
Prentice-Hall, 1970.
Copyright (c) Technical Analysis Inc. 5