In
this post, I use a wavelet analysis to further explore relationships between
oil prices, the Canadian dollar, and Canadian stock prices. Wavelet analysis is
a frequency – time domain approach with origins stemming from Fourier analysis
and spectral density analysis. Fourier analysis and spectral filtering methods
impose strong restrictions on the data structure and in doing so lose
information about the time dimension. By comparison, wavelets combine information
from the time dimension and frequency dimension. Wavelets do not make strong assumptions
about the data generating process. Gencay et al. (2002) and Ramsey (2002) are excellent
references on the application of wavelets to economic and financial data.
Below,
I apply a wavelet coherence approach to monthly returns on oil prices ($US/barrel)
and the $US/$C exchange rate which I denote as FX.
The stronger the relationship (coherence) between the two variables, the more red the colour. Both period and time are measured in months. The cone of influence is indicated by the dashed white line beyond which the estimates are unreliable. It is also, in some cases, possible to assign directionality to the relationship. This is done through the use of phase arrows. The phase arrows are interpreted as follows, where X is FX and Y is oil.
- right: in-phase
- left: anti-phase
- down: X leading Y by 90°
- up: Y leading X by 90°
The strongest coherence occurs on the time scale between months 250 (October 2006) and 300 (December 2012). Around 11 months on the period scale, the phase arrows are mostly pointing up. This indicates that oil is leading FX. Around month 23 on the period scale, however, the phase arrows are pointing down, indicating that FX is leading oil. The wavelet analysis shows the strongest relationship between FX and oil occurred relative recently with the directionality depending upon the month.
The wavelet coherence between oil prices and the TSX show several pockets of high coherence (around 50 months on the time scale (February 1990), 200 months (August 2002), and 250 - 300 months). All three regions show strong coherence between 8 and 11 periods (months). In the first two regions, the phase arrows are mostly down indicating that the TSX is leading oil. In the 250 to 300 month time period the phase arrows are up between period 8 and 11 indicating that oil leads the TSX.
This analysis presents further results that the relationship between FX and oil prices is complicated and that when using standard time series approaches one should not be surprised to fail to find strong linear relationships between these two variables.
References
Ramsey
JB. Wavelets in economics and finance: past and future. Studies in Nonlinear Dynamics
& Econometrics 2002;6(3):1–27.
Gencay R, Selcuk F, Whitcher B.
An introduction to wavelets and other filtering methods in finance and
economics. San Diego,London and Tokyo: Academic Press; 2002.
Here is the R script.
#########################################################
# Economic forecasting and analysis
# Perry Sadorsky
# February 2015
# wavelets between FXcan and oil prices
##########################################################
# load libraries
library(fpp)
library(quantmod)
library(biwavelet)
##########################################################
## read in data and prepare data
##########################################################
# load data from Yahoo
symbols <- c( "^GSPTSE" )
getSymbols(symbols, from="1986-01-01", src='yahoo')
tsx = GSPTSE[, "GSPTSE.Adjusted", drop=F]
nrow(tsx)
# load data from FRED into new environment
symbol.vec = c("DCOILWTICO" , "DEXCAUS")
data <- new.env()
getSymbols(symbol.vec, src="FRED", env = data)
# fix up FRED data
na.locf(data$DCOILWTICO["1986-01-01::"])-> oil
1/na.locf(data$DEXCAUS["1986-01-01::"])-> fx
fred.merged = merge(oil,fx,join = "inner")
View(fred.merged)
nrow(fred.merged)
series.merged <- merge(fred.merged,tsx,join = "inner")
tail(series.merged)
tail(tsx)
tail(fx)
colnames(series.merged) <- c("oil", "fx", "TSX")
##########################################################
## now convert to monthly data
##########################################################
series.merged.monthly <- series.merged[ endpoints(series.merged, on="months", k=1), ]
View(series.merged.monthly)
y.m = series.merged.monthly
# plot monthly data
par(mfrow=c(3,1))
plot(y.m[,1],main="Oil prices ($/bbl)")
plot(y.m[,2],main="$US/$C")
plot(y.m[,3],main="TSX")
par(mfrow=c(1,1))
##########################################################
# wavelet analysis
##########################################################
# wtc works better with numeric data
oil = as.numeric(y.m[,1])
fx = as.numeric(y.m[,2])
tsx = as.numeric(y.m[,3])
# compute returns
fx.ret = diff(log(fx)) * 100
oil.ret = diff(log(oil)) * 100
tsx.ret = diff(log(tsx)) * 100
lh = length(oil.ret)
tsdisplay(fx.ret)
tsdisplay(oil.ret)
tsdisplay(tsx.ret)
par(mfrow=c(1,1))
# bind in time dimension
x1 = cbind(1:lh,fx.ret)
x2 = cbind(1:lh,oil.ret)
x3 = cbind(1:lh,tsx.ret)
# wavelet coherence
wtc.fxoil = wtc(x1,x2, nrands=1000)
par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) + 0.1)
plot(wtc.fxoil, plot.cb=TRUE,plot.phase=TRUE,arrow.size.head=0.15,ylim=c(4,32),main="Wavelet coherence of FX and oil")
wtc.tsxoil = wtc(x3,x2, nrands=1000)
par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) + 0.1)
plot(wtc.tsxoil, plot.cb=TRUE,plot.phase=TRUE,arrow.size.head=0.15,ylim=c(4,32),main="Wavelet coherence of TSX and oil")
# Economic forecasting and analysis
# Perry Sadorsky
# February 2015
# wavelets between FXcan and oil prices
##########################################################
# load libraries
library(fpp)
library(quantmod)
library(biwavelet)
##########################################################
## read in data and prepare data
##########################################################
# load data from Yahoo
symbols <- c( "^GSPTSE" )
getSymbols(symbols, from="1986-01-01", src='yahoo')
tsx = GSPTSE[, "GSPTSE.Adjusted", drop=F]
nrow(tsx)
# load data from FRED into new environment
symbol.vec = c("DCOILWTICO" , "DEXCAUS")
data <- new.env()
getSymbols(symbol.vec, src="FRED", env = data)
# fix up FRED data
na.locf(data$DCOILWTICO["1986-01-01::"])-> oil
1/na.locf(data$DEXCAUS["1986-01-01::"])-> fx
fred.merged = merge(oil,fx,join = "inner")
View(fred.merged)
nrow(fred.merged)
series.merged <- merge(fred.merged,tsx,join = "inner")
tail(series.merged)
tail(tsx)
tail(fx)
colnames(series.merged) <- c("oil", "fx", "TSX")
##########################################################
## now convert to monthly data
##########################################################
series.merged.monthly <- series.merged[ endpoints(series.merged, on="months", k=1), ]
View(series.merged.monthly)
y.m = series.merged.monthly
# plot monthly data
par(mfrow=c(3,1))
plot(y.m[,1],main="Oil prices ($/bbl)")
plot(y.m[,2],main="$US/$C")
plot(y.m[,3],main="TSX")
par(mfrow=c(1,1))
##########################################################
# wavelet analysis
##########################################################
# wtc works better with numeric data
oil = as.numeric(y.m[,1])
fx = as.numeric(y.m[,2])
tsx = as.numeric(y.m[,3])
# compute returns
fx.ret = diff(log(fx)) * 100
oil.ret = diff(log(oil)) * 100
tsx.ret = diff(log(tsx)) * 100
lh = length(oil.ret)
tsdisplay(fx.ret)
tsdisplay(oil.ret)
tsdisplay(tsx.ret)
par(mfrow=c(1,1))
# bind in time dimension
x1 = cbind(1:lh,fx.ret)
x2 = cbind(1:lh,oil.ret)
x3 = cbind(1:lh,tsx.ret)
# wavelet coherence
wtc.fxoil = wtc(x1,x2, nrands=1000)
par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) + 0.1)
plot(wtc.fxoil, plot.cb=TRUE,plot.phase=TRUE,arrow.size.head=0.15,ylim=c(4,32),main="Wavelet coherence of FX and oil")
wtc.tsxoil = wtc(x3,x2, nrands=1000)
par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) + 0.1)
plot(wtc.tsxoil, plot.cb=TRUE,plot.phase=TRUE,arrow.size.head=0.15,ylim=c(4,32),main="Wavelet coherence of TSX and oil")
hi,,,how to download the data for the project? I'm new to R and would like to learn more. Is there any xls file for the data you used? thanks
ReplyDeleteDuring this website, you will see this shape, i highly recommend you learn this review. convert $100
ReplyDelete