# NOT RUN {
## Based on data from Figure 7.9 in Gencay, Selcuk and Whitcher (2001)
## plus one random series.
library(wavemulcor)
data(exchange)
returns <- diff(log(exchange))
returns <- ts(returns, start=1970, freq=12)
N <- dim(returns)[1]
wf <- "d4"
J <- trunc(log2(N))-3
lmax <- 36
n <- dim(returns)[1]
demusd.modwt <- brick.wall(modwt(returns[,"DEM.USD"], wf, J), wf)
jpyusd.modwt <- brick.wall(modwt(returns[,"JPY.USD"], wf, J), wf)
rand.modwt <- brick.wall(modwt(rnorm(length(returns[,"DEM.USD"])), wf, J), wf)
##xx <- list(demusd.modwt.bw, jpyusd.modwt.bw)
xx <- list(demusd.modwt, jpyusd.modwt, rand.modwt)
Lst <- wave.multiple.cross.correlation(xx, lmax)
returns.cross.cor <- Lst$xy.mulcor[1:J,]
returns.lower.ci <- Lst$ci.mulcor$lower[1:J,]
returns.upper.ci <- Lst$ci.mulcor$upper[1:J,]
YmaxR <- Lst$YmaxR
# ---------------------------
##Producing correlation plot
rownames(returns.cross.cor) <- rownames(returns.cross.cor, do.NULL = FALSE, prefix = "Level ")
par(mfrow=c(3,2), las=1, pty="m", mar=c(2,3,1,0)+.1, oma=c(1.2,1.2,0,0))
ymin <- -0.1
if (length(xx)<3) ymin <- -1
for(i in J:1) {
matplot((1:(2*lmax+1)),returns.cross.cor[i,], type="l", lty=1, ylim=c(ymin,1), xaxt="n",
xlab="", ylab="", main=rownames(returns.cross.cor)[[i]][1])
if(i<3) {axis(side=1, at=seq(1, 2*lmax+1, by=12), labels=seq(-lmax, lmax, by=12))}
#axis(side=2, at=c(-.2, 0, .5, 1))
abline(h=0,v=lmax+1) ##Add Straight horiz and vert Lines to a Plot
lines(returns.lower.ci[i,], lty=1, col=2) ##Add Connected Line Segments to a Plot
lines(returns.upper.ci[i,], lty=1, col=2)
text(1,1, labels=names(xx)[YmaxR[i]], adj=0.25, cex=.8)
}
par(las=0)
mtext('Lag (months)', side=1, outer=TRUE, adj=0.5)
mtext('Wavelet Multiple Cross-Correlation', side=2, outer=TRUE, adj=0.5)
# }
Run the code above in your browser using DataLab