Fourier Analysis With Excel Transcript
Fourier Analysis With Excel Transcript
Fourier Analysis With Excel Transcript
Hi Bro,
This information is really not very useful for investment. Although not exactly misleading, far
more is claimed for the method it is really justifiable. I suggest this relegated to the same
section that deals with technical analysis. It's one of those things that some people can get to
work but others just can't. I'm one of the latter, and if I can't get it to work , I don't think I
should be teaching it to the students
The fact is there are some things used by engineers that are useful to financial mathematics,
and other things that just aren't!
SLIDE 2
• Quoting from a 1946 work by Mitchell and Burns, “Business cycles are a type of
fluctuation found in the aggregate economic activity of nations…a cycle consists of
expansions occurring at about the same time in many economic activities, followed by
similarly general recessions”. So business cycles are an economic rather than a financial
phenomenon. Also, Mitchell and Burns thought these cycles recurrent, but not necessarily
periodic or waveform in the sense that we’ll use. We’ll just look briefly at these economic
phenomena, then consider the more controversial, shorter-term cycles of interest to
financiers.
• The traditional business cycles start at three years. All are due to the tendency to
overinvest in some economic resource during the good times, thereby overproducing, and
creating a downturn. The economy then recovers until overinvestment starts again.
• The Kitchin inventory cycle is one of 3 to 5 years, discovered by Joseph Kitchin. It’s
caused by the tendency to overproduce during good times, thereby flooding the market
and creating the bad times.
• The Juglar fixed-investment cycle of 7 to 11 years was described by Clément Juglar. It’s
like the Kitchin but bigger and longer scale. It’s caused by tendency to overinvest in fixed
capital (machinery, land, and workforce) in the good times, flooding the market and
creating the bad.
• The Kuznets infrastructural investment cycle or building cycle of 15 to 25 years,
according to one Simon Smith Kuznets, is caused by overinvestment in major
infrastructure, buildings, factories, education.
• Finally, we have the Kondratiev wave or long technological cycle of 45 to 60 years
(named for Nikolai Kondratiev). This is caused by overinvestment in technology, which
is either superseded by new technology or exhausts the resource that powers it,
necessitating its replacement.
SLIDE 3
1
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
• We are concerned with non-traditional cycles of three years or less. The investigation of
these started with R. Barsky and J.A. Miron (1989) The Seasonal Cycle and The Business
Cycle.
SLIDE 4
2
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
but this isn’t relevant to us, since we’ll be relying on Excel to do all the splitting. The
application, assuming the cycles actually exist, is obvious—if our original set of data is a
share price, we could subject historical data to a Fourier analysis, and use what we find to
project the combination of waveforms into the future.
LIDE 5
First, let’s acquire a vocabulary about waves and waveforms. This is the algebra that
describes a wave.
𝐴 sin(𝑓𝜃 + 𝜙)
= 𝐴 cos(𝑓𝜃 + 𝜙 + 90°)
• theta is the angle—the independent variable. For us, time will take the place of theta.
• sine, pretty obviously, is the function that generates the wave.
• So here, set out three times in in black, is the basic waveform. Now we’ll change the
coloured parameters to make some comparisons.
• 𝐴 is the amplitude: how far up and down the wave gets. the greater the amplitude, the
more pronounced is the wave.
• And here in red is the result of increasing the amplitude from one to two—higher
peaks, deeper troughs.
• 𝑓 signifies the frequency, how many waves you get to a period of time. The higher the
value of 𝑓, the higher the frequency, and the more the peaks and troughs we get
crowded into the same space.
• and here in blue is the result of increasing the frequency from one to three. There are
now three peaks where there used to be just one.
• phi is the phase, which tells us where the wave starts. Zero phase means a sine wave
starts at value zero at time zero. Positive phase shifts the whole wave to the left, so it
starts earlier, and negative phi shifts the wave to the right, so the wave starts later.
• Here in green is the result of changing the phase from zero to plus 45 degrees. A the
wave shifts by this much towards the left, so it starts earlier.
3
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
SLIDE 6
Now we’ll take the combined wave w and use Excel’s Fourier transform to confirm the
component waveforms. I’ll start with an overview, and introduce some important terms.
The reason is that Excel always outputs cosines not sines. So for this waveform, we’d get
the three cosine answers with phase -90°. But there’s always some phase to take into
account in practice, so the cosine version won’t be more complicated in general.
• Excel can only transform 2M data points. This wave was sampled at 11.5° intervals,
giving N=25=32 data points. The amplitude is the xith datum, being the amplitude of the
combined sinewave for that degree.
• This is a sampling frequency of four points—four amplitudes—every 45 degrees.
32 samples 4
𝐹= =
360 degrees 45
• The frequency resolution Delta eff 𝛥𝑓is the difference in frequency between each
possible component our analysis will generate, so it sets a limit on how precise the results
can be. It’s equal to the sample frequency over the number of points. So here the
4
𝐹 45⁄ 1
frequency resolution is 𝛥𝑓 = 𝑁 = 32 = 360, a difference of one whole wave per 360
degrees. So our possible components, or frequency bins, start at
• f0=0/360 (which is a constant or baseline, and is generally ignored),
• our second f1=1/360 (a whole wave every 360 degrees),
• the third f2=2/36 (2 whole waves every 360 degrees),
• and so on. It’s easiest to think of these in terms of harmonics,
• so f0=0H constant, f1=1H the first harmonic or fundamental, etc.
SLIDE 7
Here’s the EXCEL sheet for our analysis, with all the initial data columns filled in, and the
remaining columns—which EXCEL will fill in for us—titled appropriately. We only need to
fill in the rows 1 to 33 for our data—and we’ll read only rows 1 to 17, as we’ll see.
• COLUMN A has our 32 sampled points numbered from 𝑛 equals zero to 31.
• COLUMN B has the degree at which each sample is made.
• COLUMN C has the amplitude sampled at that point. This is the really important data.
4
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
• COLUMN D sets up 16 frequency bins. Fourier analysis delivers half as many possible
frequency components as the sample size, so here we can expect information on 16
possible components.
That covers all the inputs—what you’re expected to put in yourself. Lets flip the slide, and
look at the outputs.
SLIDE 8
I’ve cropped the screen to COLUMN D and after. We’ll need the data in COLUMN D in just
a moment. The output will be set out against the frequency bins—the components of the
waveform—in COLUMN E.
SLIDE 9
So here’s all the actual Fourier analysis done by EXCEL. The remaining columns interpret
this output.
• The MAG column F finds the magnitude of the complex number in column E. The cells
here have algebra MAG =IMABS(E2), and when filled
• start to narrow down the frequencies we’re interested in. But we haven’t finished—the
magnitudes here haven’t been properly scaled to take into account the sampling
frequency. That requires
• The MAG SCALED column G, where the algebra reduces the magnitude by a factor of
half the sample size. =2*F2/32.
5
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
• There’re the figures. Compare how a random number in an SDE has to be scaled by the
time step delta 𝑡. This really gives us all the information we need, but there’s a traditional
further step, the
• NYQUIST column H, named for the engineer Harry Nyquist, where we just cut out the
redundant information in rows 17 onwards. The algebra, an IF command
=IF(A3<=8/2,F3,0)
• just reduces the final half of the entries to zero. Now clearing the looking at the
NYQUIST column, we can see that only
• contributor waves f1,
• f2 and
• f7 have substantial contributions- the rest are either zero or so small they require scientific
notation.
• But this is just what we expect from the original algebra of the wave. Actually, let’s
isolate that a new slide.
SLIDE 10
• Here’s the original equation for the wave I generated. Relating these,
• we have a component wave of magnitude 3 and frequency one, or one times 𝑡, a whole
wave over the 360 degrees (or days, or whatever a unit happens to be).
• we have a component of magnitude one and frequency two,
• and a component of magnitude five and frequency seven.
• Just tidying up that slide…Now recall that Excel outputs not component sine waves but
component cosine waves. So, the output doesn’t really give us our three sinewaves with
phase angle zero, but three cosine waves with phase angles of -90°. We can see this from
the FREQUENCY BIN CONTRIBUTIONS. These are complex numbers, so they have x
and y parts, so we can get angles out of them. These angles are the phases.
• Minus 48.0000000001651i, zero real part, gives a tangent of minus infinity, so an angle
of minus 90° (or 270°)
• No real part in the second, either, so a minus over zero, so an angle of minus 90
degrees…
• …and same here, a minus over zero, so minus infinity, so the arctan is minus 90 degrees.
There’s one more step, next slide.
SLIDE 11
Now insert a bar chart using NYQUIST (only plot from n=1 to n=15). I’ve filled in the graph
and axis titles manually. From this, we can indeed see that the major components of the
original waveform are:
6
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
Now let’s consider an example with a phase difference, which is what you’re likely to see in
real data. I’ll split the slides here, and continue in a separate presentation.
SLIDE 1 TITLE
SLIDE 2
• we’ll take the combined wave w, where w is 2 times the cosine of t with a phase of 45
degrees, plus five times the cosine of t with a phase of minus 120 degrees. When we split
this wave, it’s important that we recover the phases as well as the frequencies and
amplitudes.
• 𝑤(𝑡) = 2 𝑐𝑜𝑠(𝑡 + 45°) + 5 𝑐𝑜𝑠(9𝑡 − 120°)
• The wave was sampled at 2.8125° intervals,
• giving N=27=128 data points,
• and the actual sample is of course the amplitude at that point.
𝑛𝐹 𝑛
• Our frequency bins start at X0 = 0 = constant, and rise at intervals of = 360 per bin. Our
𝑁
first bin f0=0H constant, f1=1H the first harmonic or fundamental, etc.
• Generate the complex numbers as before, and fill in the MAG, MAG SCALED, and
NYQUIST columns as above.
• We can see that only contributor waves f1 and f9 have substantial contributions, so the
major components of the original waveform are
• 1H (a whole wave every 360°) with amplitude 2, and 9H (nine waves every 360°) with
amplitude 5. Butm this is all familiar stuff.
• What about the phases? Since this slide is getting a little crowded, let’s open another.
SLIDE 3
• And these are the only two we have to investigate, f1 and f9. The idea is to find the
tangent of the phase, and arctan this to get the phase degrees.
• That’s the arctan of the imaginary part over the real part.
• Firstly, in the f1 row, we see an imaginary part of ninety point 5 something,
7
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
SLIDE 4
This is a plot of closing prices for National Retail Properties, Inc. (NNN). I chose this
company on the sole grounds that we’ve rather neglected real estate as a sector.
• You can find this in the file FOURIER ANALYSIS OF NNN. We’ll assume that there are
cycles in the data.
• What is an appropriate period to sample? We can at least exploit the fact that a trading
year of 252 days is close to 28 = 256, and use multiples of this to sample and overlay
data. But it must be remembered that a poor choice of period is likely to obscure any real
cycles.
• I’ve therefore analysed the average of five 512-day periods. You’ll find this in Excel file
FOURIER ANALYSIS OF NNN.
• Looking at our average 2-year period, then, the plot does look vaguely periodic. At least,
without too much exercise of imagination,
• we can propose a first harmonic, here in blue, lasting the whole two years,
• and a second harmonic with a period of one year. So, let’s perform the Fourier analysis.
SLIDE 5
The instantaneous averages stand in for our sampled magnitudes, and we can quickly follow
the above process to get a list of frequencies, magnitudes and phases.
8
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
• However, there are so many of these that a simple histogram of the NYQUIST column is
useless.
• Instead, cut the top half of the data (where the NYQUIST values are non-zero), and sort
this according to scaled magnitude in order of decreasing size.
• It can be seen that the powers of the individual frequencies do drop off quite quickly
from a small number of “winners”, the most powerful being f2, f1, f4, f3 and f7. Now
let’s take just these top few and interpret them.
SLIDE 6
• We must interpret these frequencies in terms of the period examined, but I’ll do so in
order of frequency.
• f1, a period of two years, has magnitude of 0.16, and phase from taking the arctan the
imaginary part -38.42 over the real part -16.6, giving a phase of 66.63 in the third
quadrant, so minus 113.37 degrees.
−38.42
tan−1 −16.60 = 66.63° in III, 113.37
• f2, a period of one year (half of two years), has magnitude 0.17, and phase of 89.5
degrees in the second quadrant, so we’ll call this 90 degrees.
45.46
phase 𝑡𝑎𝑛−1 −0.40 = 89.5° in II, 90° degrees.
• f3, a period of 8 months (one third of two years), magnitude 0.08, phase of 19.65 degrees
in the 1st quadrant.
6.75
phase tan−1 18.90 = 19.65° in I.
• f4, a period of 6 months (one quarter of two years), magnitude 0.11, phase of 82.83
degrees in the second quadrant, so 97.69 degrees.
29.76
phase tan−1 −4.02 = 82.31° in II, so 97.69° degrees.
• f7, a period of 3-4 months (one seventh of two years), magnitude 0.07, phase of 65.18
degrees in the third quadrant, so minus 114.82 degrees.
−17.15
phase tan−1 = 65.18° in III, so −114.82°
−7.93
• That’s five waves to generate and superimpose. Enough to be going on with—we can
always see if we need more.
SLIDE 7
9
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
• If we now take the cycles we have, plot them in EXCEL over 512 points of the 360-
degree cycle, which is still two years from our perspective, and add, say, 11 to
compensate for losing the baseline (scaling f0 by half of 512 wouldn’t quite do this,
because we lost a lot of height from the harmonics we’ve not plotted),
• we get the blue line, here superimposed on the average in orange:
• Yes, we are clearly starting to reconstruct the average curve solely in terms of its
constituent harmonics. This does hold out some promise that we can get a simple,
indicative curve to superimpose on an arbitrary year, but we must be cautious.
SLIDE 8
• Early promises are made very easily by this technique, which would after all reconstitute
any curve, however arbitrary, given enough harmonics. It’s a situation analogous to over-
fitting a polynomial. But here we have just a very few dominant harmonics.
• Fundamental analysis is the study of contributing factors to share price changes. There
are many contributions to a complete fundamental analysis, but our hypothetical cycles
could contribute…
• … because we could return to the company’s history and consider what mechanisms
might be responsible for these periods of 6 and 8 months, of one and two years and so on,
and perhaps get some valuable predictive information about the share prices. For instance,
• Budgeting and finance plans over a 2-year period are common, and the publicity caused
by appraisals of these can impact investor confidence.
• Over 1 year, seasonal factors must dominate. In fact, we should be suspicious if we don’t
find some indication of a yearly cycle. Kamstra et al, in a 2017 paper noted the
phenomenon of “Spring bulls and Autumn bears”, in which investors tended to buy into
concerns in the spring and out of them in the autumn.
• 8 months and 6 months cycles are noted by Tanokura and Kitagaw in a recent publication
(2016), and we might link these to publicity regarding the progress of much longer term
plans.
• 3-4 months: may relate to quarterly reviews, and the publicity around these. So given all
these cycle, we could perhaps consider where in the cycle a price happens to be, and
project whether it will rise or fall.
10
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
• Fundamental analysis represents the respectable use of cycles. It is cautious and based on
some idea of causality.
SLIDE 9
• Technical analysis is the study of patterns in stock prices. It is very controversial: witness
the
• XKCD cartoon of https://xkcd.com/2101/ of 26 Aug 2020, which I won’t reproduce here.
You can find a link in the notes.
• If we superimpose the reconstructed curve against the next 512-day period 21/11/1994-
27/11/1996 (so no issues of phase),
• the reconstructed curve does give us apparent clues regarding buying strategies.
• An investor at this date might indeed be able to see past the random activity and
anticipate an overall rise, whereas
• an investor on this date might anticipate good conditions to sell short.
• But there are at least two partial contradictions,
• here,
• and here, where the curve is at least misleading.
• Your lecturer confesses to having had very little success applying this technique—in fact
this example looks a lot more encouraging than most I’ve seen.
SLIDE 10
Our caveat, or warning, is taken from James Gleick’s excellent book Chaos. I have edited the
quote which takes in two separate chapters.
• “Why do investors insist on the existence of cycles? Because periodicity is the most
complicated orderly behaviour they can imagine… Economists imagined that prices
change smoothly, in the sense that they pass through all the intervening levels on the way
from one point to another. But prices can change in instantaneous jumps. A stock market
strategy was doomed to fail if it assumed that a stock would have to sell for $50 on its
way down from$60 to $10.”
• Don’t be too scared by this. We can see share prices changing more or less continuously
on Bloomberg,
• There are alternative models and statistical distributions (Gleick himself cites the
Mandelbrotian) that can inform our choices, taking periodicities as a kind of average
motion.
11
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
SLIDE 11
• Fourier analysis allows these waveforms to be isolated, and used to inform decision-
making. The two principle schools that might use cycles—among many other criteria--
are
• Fundamental analysis, in which individual cycles are studied for clues to fluctuations in
investor confidence, or business practice, and
• Technical analysis, in which simple superimpositions are taken to give clues as to how
peaks follow troughs, and vice versa, in prices.
• We should of course be aware if the method, even if we don’t use it. Perhaps you’ll have
more success. Even if you don’t use them yourself, be prepared to have to talk your
clients out of them!
• CLICK
12
USE WITH CAUTION! I RECOMMEND YOU NOT USE IT AT ALL!
Sources
R. Barsky and J.A. Miron (1989) The Seasonal Cycle and The Business Cycle. Journal of
Political Economy 97(3):503-34
A.F. Burns and W.C. Mitchell, Measuring Business Cycles. New York: National Bureau of
Economic Research.
Kamstra, M., Kramer, L., Levi, M., & Wermers, R. (2017). Seasonal Asset Allocation:
Evidence from Mutual Fund Flows. Journal of Financial and Quantitative Analysis, 52(1),
71-109. doi:10.1017/S002210901600082X
Sangbae, K. and Haeuck, I.F. (2003) The Relationship Between Financial Variables and Real
Economic Activity: Evidence From Spectral and Wavelet Analyses. Studies in Nonlinear
Dynamics & Econometrics, (7)4, 1-18
B. Stádník, J. Raudeliuniene and V. Davidavičienė (2016) Fourier Analysis for Stock Price
Forecasting: Assumption and Evidence. Journal of Business Economics and Management
17(3):365-380.
V. Zarnowitz (1963) On the Dating of Business Cycles. The Journal of Business, 36(2):179-
199
Yoko Tanokura, Genshiro Kitagawa (2016). Indexation and Causation of Financial Markets.
Springer Verlag, Tokyo.
13