1. Introduction 2. Basics of Fourier Series 3. Fitting a single sine wave to a time series 4. Fitting a set of sine waves to a time series 5. Real data example: U.S./New Zealand exchange rate forecast 6. Caution with PROC SPECTRA in SAS CHAPTER 2: Fourier Series (Spectral) Analysis Prof. Alan Wan 1 / 54
72
Embed
CHAPTER 2: Fourier Series (Spectral) Analysispersonal.cb.cityu.edu.hk/msawan/teaching/ms6215/MS6215Ch2.pdf · Fitting a single sine wave to a time series 4. Fitting a set of sine
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
CHAPTER 2: Fourier Series (Spectral) Analysis
Prof. Alan Wan
1 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Table of contents
1. Introduction
2. Basics of Fourier Series
3. Fitting a single sine wave to a time series
4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast
6. Caution with PROC SPECTRA in SAS
2 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Introduction
I A Fourier series is a representation of a wave-like function asthe sum of simple sine/cosine waves.
I More formally, it decomposes any periodic function into thesum of a set of simple oscillating functions, namely sines andcosines.
I It is suitable for modeling seasonality and/or cyclicalness, andidentifying peaks and troughs;
3 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Introduction
I A Fourier series is a representation of a wave-like function asthe sum of simple sine/cosine waves.
I More formally, it decomposes any periodic function into thesum of a set of simple oscillating functions, namely sines andcosines.
I It is suitable for modeling seasonality and/or cyclicalness, andidentifying peaks and troughs;
3 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I A sine wave is a repeating pattern that goes through onecycle every 2π (i.e. 2 × 3.141593 = 6.283186) units of time.
I For example,X 0 1.57 3.14 4.71 6.28
Y = sin(x) 0 1 0 -1 0
I Therefore, Y = sin(x) = sin(2π + x).
I The sine function attains a peak at π/2 and a trough at 3π/2.
4 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I A sine wave is a repeating pattern that goes through onecycle every 2π (i.e. 2 × 3.141593 = 6.283186) units of time.
I For example,X 0 1.57 3.14 4.71 6.28
Y = sin(x) 0 1 0 -1 0
I Therefore, Y = sin(x) = sin(2π + x).
I The sine function attains a peak at π/2 and a trough at 3π/2.
4 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I A sine wave is a repeating pattern that goes through onecycle every 2π (i.e. 2 × 3.141593 = 6.283186) units of time.
I For example,X 0 1.57 3.14 4.71 6.28
Y = sin(x) 0 1 0 -1 0
I Therefore, Y = sin(x) = sin(2π + x).
I The sine function attains a peak at π/2 and a trough at 3π/2.
4 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
5 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I One may also induce a phase shift in the spectrum of thefunction that has effect of changing the location of the peaksand the troughs.
I For example, if Y = sin(x) and Z = sin(x + π/2), then Zpeaks at x = 0 and bottoms at x = π, whereas Y peaks andbottoms at x = π/2 and x = 3π/2 respectively.
I π/2 is the amount of phase shift in this example; it has theeffect of producing a new sine wave Z that moves ahead ofthe original sine wave Y by π/2 units.
I Clearly, a phase shift of 2π will produce a sine wave identicalto Y .
6 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I One may also induce a phase shift in the spectrum of thefunction that has effect of changing the location of the peaksand the troughs.
I For example, if Y = sin(x) and Z = sin(x + π/2), then Zpeaks at x = 0 and bottoms at x = π, whereas Y peaks andbottoms at x = π/2 and x = 3π/2 respectively.
I π/2 is the amount of phase shift in this example; it has theeffect of producing a new sine wave Z that moves ahead ofthe original sine wave Y by π/2 units.
I Clearly, a phase shift of 2π will produce a sine wave identicalto Y .
6 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
7 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I One can also control the magnitude of the peaks and thetroughs by changing the amplitude of the sine function.
I For example, W = 25sin(x), then
8 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I One can also control the magnitude of the peaks and thetroughs by changing the amplitude of the sine function.
I For example, W = 25sin(x), then
8 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I Thus, a general wave like function of Y may be written as:
I Yt = Asin(2πft + P), where
Yt is the time series at time t, t = 1, · · · , n;n is the number of observations;A is the amplitude;2π is one complete cycle;f is the frequency representing the number of cycles perobservation, so that L = 1/f , the wavelength, is the numberof periods from the beginning of one cycle to the next; andP is the phase shift
9 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
0
0 n
n
nL
nf
;1
2
;2
nL
nf
2
n
10 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
I Consider the series
Z = 300 × sin( 4t482π + 1.5708) and
Y = 200 × sin( 4t482π)
Series A f P n LZ 300 4/48 1.5708 48 12Y 200 4/48 0 48 12
11 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Basics of Fourier Series
12 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a single sine wave to a time series
I How to fit a single sine wave to a time series?I Consider the following data with n = 20 observations:
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a single sine wave to a time series
The REG Procedure Model: MODEL1 Dependent Variable: y Number of Observations Read 20 Number of Observations Used 20 Analysis of Variance Sum of Mean Source DF Squares Square F Value Pr > F Model 2 1.56010 0.78005 84.52 <.0001 Error 17 0.15690 0.00923 Corrected Total 19 1.71700 Root MSE 0.09607 R-Square 0.9086 Dependent Mean 1.00000 Adj R-Sq 0.8979 Coeff Var 9.60698 Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept 1 1.00000 0.02148 46.55 <.0001 s5 1 0.38700 0.03038 12.74 <.0001 c5 1 0.07900 0.03038 2.60 0.0187 20 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a single sine wave to a time series
I Therefore,
b1 = 0.387
b2 = 0.079
A =√
0.3872 + 0.0792
= 0.395
P = tan−1(0.079
0.387)
= 0.2014
I Hence the estimated model may be expressed asYt = 1 + 0.395 × sin(π2 t + 0.2014)
22 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In practice, L and f are unknown. As well, amplitudes ofpeaks and troughs are rarely equal.
I The single sine wave model may be extended to the followinggeneral Fourier Series model:
Yt = µ+h∑
j=1
Ajsin(2πfj t + Pj) + εt
= µ+h∑
j=1
b1jsin(2πfj t) + b2jcos(2πfj t) + εt , (1)
I which comprises a linear combination of ”harmonic waves”,each with its own amplitude(Aj), phase shift (Pj), frequency(fj), wave length (Lj) and unique number of cycles (n/Lj).
23 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In practice, L and f are unknown. As well, amplitudes ofpeaks and troughs are rarely equal.
I The single sine wave model may be extended to the followinggeneral Fourier Series model:
Yt = µ+h∑
j=1
Ajsin(2πfj t + Pj) + εt
= µ+h∑
j=1
b1jsin(2πfj t) + b2jcos(2πfj t) + εt , (1)
I which comprises a linear combination of ”harmonic waves”,each with its own amplitude(Aj), phase shift (Pj), frequency(fj), wave length (Lj) and unique number of cycles (n/Lj).
23 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In order for the model to be estimable, it is assumed that theminimum number of observations for the completion of anyharmonic wave is 2, i.e., the maximum allowable number ofharmonic waves, h, is n/2.
I When n is even,
Harmonic wave, j 1 2 3 ... n2 − 1 n
2
Wavelength, Lj = nj n n
2n3 ... 2n
n−2 2
Frequency, fj = 1Lj
= jn
1n
2n
3n ... n−2
2n12
I j also represents the number of cycles for the given harmonicwave.
24 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In order for the model to be estimable, it is assumed that theminimum number of observations for the completion of anyharmonic wave is 2, i.e., the maximum allowable number ofharmonic waves, h, is n/2.
I When n is even,
Harmonic wave, j 1 2 3 ... n2 − 1 n
2
Wavelength, Lj = nj n n
2n3 ... 2n
n−2 2
Frequency, fj = 1Lj
= jn
1n
2n
3n ... n−2
2n12
I j also represents the number of cycles for the given harmonicwave.
24 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Note that when j = h = n/2,fj = 1
2 and sin(2πfj t) = sin(πt) = 0
I Hence the model reduces to
Yt = µ+
n/2−1∑j=1
b1jsin(2πfj t) + b2jcos(2πfj t)
+ b2n/2cos(2πfn/2t) + εt (2)
25 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Note that when j = h = n/2,fj = 1
2 and sin(2πfj t) = sin(πt) = 0
I Hence the model reduces to
Yt = µ+
n/2−1∑j=1
b1jsin(2πfj t) + b2jcos(2πfj t)
+ b2n/2cos(2πfn/2t) + εt (2)
25 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Alternatively, when n is odd, the maximum number ofharmonic waves is (n − 1)/2
Harmonic wave, j 1 2 3 ... n−12 − 1 n−1
2
Wavelength, Lj = nj n n
2n3 ... 2n
n−32nn−1
Frequency, fj = 1Lj
= jn
1n
2n
3n ... n−3
2nn−12n
I Hence the model is
Yt = µ+
(n−1)/2∑j=1
b1jsin(2πfj t) + b2jcos(2πfj t) + εt (3)
26 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In both models (2) and (3), the number of observations equalthe number of unknowns to be estimated, resulting in zerodegree of freedom !!
I The idea is not to use the general Fourier series model forforecasting but to use it to identify significant cycles.
I Consider the previous data set with 20 observations. Supposethat a general Fourier series model is fitted to this data set.Then h = 10 and the model is
Yt = µ+9∑
j=1
b1jsin(2πfj t) + b2jcos(2πfj t)
+ b2,10cos(2πf10t) + εt
27 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In both models (2) and (3), the number of observations equalthe number of unknowns to be estimated, resulting in zerodegree of freedom !!
I The idea is not to use the general Fourier series model forforecasting but to use it to identify significant cycles.
I Consider the previous data set with 20 observations. Supposethat a general Fourier series model is fitted to this data set.Then h = 10 and the model is
Yt = µ+9∑
j=1
b1jsin(2πfj t) + b2jcos(2πfj t)
+ b2,10cos(2πf10t) + εt
27 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I In both models (2) and (3), the number of observations equalthe number of unknowns to be estimated, resulting in zerodegree of freedom !!
I The idea is not to use the general Fourier series model forforecasting but to use it to identify significant cycles.
I Consider the previous data set with 20 observations. Supposethat a general Fourier series model is fitted to this data set.Then h = 10 and the model is
Yt = µ+9∑
j=1
b1jsin(2πfj t) + b2jcos(2πfj t)
+ b2,10cos(2πf10t) + εt
27 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
The SAS System
Obs FREQ PERIOD P_01 sq
1 0.00000 . 40.0000 0.00000
2 0.31416 20.0000 0.0000 0.00001
3 0.62832 10.0000 0.0016 0.00157
4 0.94248 6.6667 0.0033 0.00332
5 1.25664 5.0000 0.0074 0.00738
6 1.57080 4.0000 1.5601 1.56010
7 1.88496 3.3333 0.0060 0.00605
8 2.19911 2.8571 0.0184 0.01842
9 2.51327 2.5000 0.0011 0.00112
10 2.82743 2.2222 0.0005 0.00045
11 3.14159 2.0000 0.2372 0.11858
1.7170
33 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Some explanations of the symbols are in order:Obs - 1 = j ,PERIOD = Lj = wavelength,FREQ = 2πfj ,P 01 and sq are quantities related to the line spectrum (seeslides ahead)
I Note the sum of sq = 1.717 is precisely equal to theregression’s TSS.
34 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Some explanations of the symbols are in order:Obs - 1 = j ,PERIOD = Lj = wavelength,FREQ = 2πfj ,P 01 and sq are quantities related to the line spectrum (seeslides ahead)
I Note the sum of sq = 1.717 is precisely equal to theregression’s TSS.
34 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Define the line spectrum as
Pj =
{ n2 (b21j + b22j) if j < n/2
nb22j if j = n/2
I A plot of Pj versus Lj , the wavelength, is called theperiodogram. It measures the intensity of the specificharmonic wave.
I The P 01 column in the SAS output gives the line spectrumsfor all harmonic waves, except when j = n/2, where thecorrect line spectrum should be P 01/2.
35 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Define the line spectrum as
Pj =
{ n2 (b21j + b22j) if j < n/2
nb22j if j = n/2
I A plot of Pj versus Lj , the wavelength, is called theperiodogram. It measures the intensity of the specificharmonic wave.
I The P 01 column in the SAS output gives the line spectrumsfor all harmonic waves, except when j = n/2, where thecorrect line spectrum should be P 01/2.
35 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
I Define the line spectrum as
Pj =
{ n2 (b21j + b22j) if j < n/2
nb22j if j = n/2
I A plot of Pj versus Lj , the wavelength, is called theperiodogram. It measures the intensity of the specificharmonic wave.
I The P 01 column in the SAS output gives the line spectrumsfor all harmonic waves, except when j = n/2, where thecorrect line spectrum should be P 01/2.
35 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
36 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Fitting a set of sine waves to a time series
One may test for the significance of the harmonic waves by asequential testing procedure:
I Out-of-sample forecasts (from period 21 onwards):
Y21 = 1 + 0.387sin(π21
2) + 0.079cos(
π21
2) − 0.077cos(π21)
= 1.464016
.
.
Y24 = 1 + 0.387sin(π24
2) + 0.079cos(
π24
2) − 0.077cos(π24)
= 1.002016
38 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Real data example: U.S./New Zealand exchange rateforecast
I Let Yt=USD equivalence of one NZD between 1986Q2 and2008Q2 (i.e., n = 89)
I The NZD was floated in March 1985 (prior to that, it waspegged to the USD) and has been in the range of 1 NZD =0.39 to 0.88 USD between 1985 and 2014;
I The NZD is one of the most widely fluctuated currencies,being affected strongly by FOREX speculative trading andcommodity prices;
I The NZD’s post-float lowest and highest daily values were0.39 USD in November 2000 and 0.88 USD in July 2011;
I Use the Fourier Series to model ∆Yt = Yt − Yt−1 (forrequirement of ”stationarity” (see Chapter 5));
39 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Real data example: U.S./New Zealand exchange rateforecast
U.S. / New Zealand Exchange Rate
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Q2 1
986
Q1 1
987
Q4 1
987
Q3 1
988
Q2 1
989
Q1 1
990
Q4 1
990
Q3 1
991
Q2 1
992
Q1 1
993
Q4 1
993
Q3 1
994
Q2 1
995
Q1 1
996
Q4 1
996
Q3 1
997
Q2 1
998
Q1 1
999
Q4 1
999
Q3 2
000
Q2 2
001
Q1 2
002
Q4 2
002
Q3 2
003
Q2 2
004
Q1 2
005
Q4 2
005
Q3 2
006
Q2 2
007
Q1 2
008
Q4 2
008
Date
Rat
e actual
predict
40 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Real data example: U.S./New Zealand exchange rateforecast
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Real data example: U.S./New Zealand exchange rateforecast
I The fitted model is:
∆Yt = 0.0025 − 0.0075sinπ31t
44− 0.0122cos
π31t
44
+ 0.0113sinπ3t
44+ 0.0048cos
π3t
44
− 0.0061sinπ8t
44− 0.0102cos
π8t
44
43 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Real data example: U.S./New Zealand exchange rateforecast
I Out of Sample Forecasts:
∆Y2008Q3 = 0.0025 − 0.0075sin31π89
44− 0.0122cos
31π89
44
+ 0.0113sin3π89
44+ 0.0048cos
3π89
44
− 0.0061sin8π89
44− 0.0102cos
8π89
44= −0.00098
Y2008Q3 = −0.00098 + 0.7526 = 0.7516
44 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Real data example: U.S./New Zealand exchange rateforecast
∆Y2008Q4 = 0.0025 − 0.0075sin31π90
44− 0.0122cos
31π90
44
+ 0.0113sin3π90
44+ 0.0048cos
3π90
44
− 0.0061sin8π90
44− 0.0102cos
8π90
44= 0.012407
Y2008Q4 = 0.012407 + 0.7516 = 0.7640
45 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I Note that PROC SPECTRA can generate the coefficientestimates of the Fourier Series automatically viaPROC SPECTRA COEF;
I However, when interpreting the results, cautions must beexercised due to the peculiar way SAS defines the FourierSeries model.
46 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I Note that PROC SPECTRA can generate the coefficientestimates of the Fourier Series automatically viaPROC SPECTRA COEF;
I However, when interpreting the results, cautions must beexercised due to the peculiar way SAS defines the FourierSeries model.
46 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I SAS defines the Fourier Series model as follows (from SASmanual):
Yt =a02
+m−1∑j=1
ζj(ajcos(ωj t) + bjsin(ωj t)), (4)
I wheret = 0, 1, 2, .., n − 1; ωj = 2πj
n ;m − 1 = the number of harmonics cycles; and
ζj =
{12 if n is even and j = m − 11 otherwise
47 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
Hence,
I t under (1) is equivalent to t + 1 under (4);
I µ under (1) is equivalent to a0/2 under (4);
I ωj = 2πjn under (4) is identical to 2πfj under (1);
I h under (1) is the same as m− 1 under (4), hence m = n+22 if
n is even and m = n+12 if n is odd;
I due to the introduction of ζj under PROC SPECTRA, when nis even and j = m − 1 = h = n/2, the (correct) coefficientestimate of the cosine variable is equal to 0.5 times thereported estimate of aj ; hence b2, n
2(under (1)) = 0.5 × a n
2.
(under (4)).
48 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I Also, PROC defines the line spectrum asP 01j = n
2 (a2j + b2j )
and interpret P 01j as the contribution of the j th harmoniccycle to the total sum of squares in the decomposition processinto ”two degrees of freedom” components for each of theharmonic cycles.
I This definition and interpretation match exactly the definitionand interpretation of Pj , except when j = m − 1 = h = n/2,for which Pj = P 01j/2.
49 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I Consider the data set in our example. The program
data fourier1; input y @@; cards; 1.52 0.81 0.63 1.06 1.46 0.80 0.71 0.98 1.50 0.85 0.65 1.04 1.47 0.85 0.72 0.95 1.37 0.91 0.74 0.98 ; proc spectra coef data=fourier1 out=out2; var y; run; data out2; set out2; sq=p_01; if period=. then sq=0; if round (freq, .0001)=3.1416 then sq=.5*p_01; run; proc print data=out2; sum sq; run;
50 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I produces the following results, where cos 01 and sin 01 arethe estimates of aj and bj respectively:
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I Note that P 01 are the same as those on p.32 but thecoefficient estimates are not the same as those obtained byPROC REG on p.30;
I The difference is due to a redefinition of t, the time script byPROC SPECTRA;
I One can get around the problem by redefining the time scriptto start from 0 for the program on p.28 by replacing thecommandt + 1; bytt + 1;t = tt − 1;
I This results in the following output:
52 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
The REG Procedure Model: MODEL1 Dependent Variable: y Number of Observations Read 20 Number of Observations Used 20 Analysis of Variance Sum of Mean Source DF Squares Square F Value Pr > F Model 19 1.71700 0.09037 . . Error 0 0 . Corrected Total 19 1.71700 Root MSE . R-Square 1.0000 Dependent Mean 1.00000 Adj R-Sq . Coeff Var . Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept 1 1.00000 . . . s1 1 -0.00056597 . . . c1 1 -0.00046190 . . . s2 1 -0.00436 . . . c2 1 0.01176 . . . s3 1 -0.01778 . . . c3 1 0.00399 . . . s4 1 -0.01701 . . . c4 1 -0.02118 . . . s5 1 -0.07900 . . . c5 1 0.38700 . . . s6 1 0.01847 . . . c6 1 0.01624 . . . s7 1 0.00684 . . . c7 1 0.04237 . . . s8 1 0.01051 . . . c8 1 0.00118 . . . s9 1 -0.00638 . . . c9 1 0.00210 . . . c10 1 0.07700 . . .
53 / 54
1. Introduction2. Basics of Fourier Series
3. Fitting a single sine wave to a time series4. Fitting a set of sine waves to a time series
5. Real data example: U.S./New Zealand exchange rate forecast6. Caution with PROC SPECTRA in SAS
Caution with PROC SPECTRA in SAS
I The results are the same as those produced by PROCSPECTRA; specifically,
I µ = 1.0 = a0/2 = 2.0/2;
I The two procedures produce the same sine and cosinecoefficient estimates; note that for j = 10, a10 = 0.154 andζ10 = 1/2, hence the (correct) cosine coefficient estimate isζ10a10=1/2 × 0.154 = 0.077;
I P 0110 = 0.2372 = 202 (0.1542). The correct line spectrum is