# 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"
M <- 30
window <- "gauss"
J <- 3 #trunc(log2(N))-3
lmax <- 2
set.seed(140859)
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)
names(xx) <- c("DEM.USD","JPY.USD","rand")
# }
# NOT RUN {
# Note: WLMCC may take more than 10 seconds of CPU time on some systems
Lst <- wave.local.multiple.cross.correlation(xx, M, window=window, lag.max=lmax)
val <- Lst$val
low.ci <- Lst$lo
upp.ci <- Lst$up
YmaxR <- Lst$YmaxR
# ---------------------------
##Producing cross-correlation plot
xvar <- seq(1,N,M)
level.lab <- c(paste("Level",1:J),paste("Smooth",J))
ymin <- -0.1
if (length(xx)<3) ymin <- -1
for(j in 1:(J+1)) {
par(mfcol=c(lmax+1,2), las=1, pty="m", mar=c(2,3,1,0)+.1, oma=c(1.2,1.2,1.2,0))
# xaxt <- c(rep("n",lmax),"s",rep("n",lmax))
for(i in c(-lmax:0,lmax:1)+lmax+1) {
matplot(1:N,val[[j]][,i], type="l", lty=1, ylim=c(ymin,1), #xaxt=xaxt[i],
xlab="", ylab="", main=paste("Lag",i-lmax-1))
abline(h=0) ##Add Straight horiz
lines(low.ci[[j]][,i], lty=1, col=2) ##Add Connected Line Segments to a Plot
lines(upp.ci[[j]][,i], lty=1, col=2)
text(xvar,1, labels=names(xx)[YmaxR[[j]]][xvar], adj=0.25, cex=.8)
}
par(las=0)
mtext('time', side=1, outer=TRUE, adj=0.5)
mtext('Local Multiple Cross-Correlation', side=2, outer=TRUE, adj=0.5)
mtext(level.lab[j], side=3, outer=TRUE, adj=0.5)
}
# }
Run the code above in your browser using DataLab