# NOT RUN {
## Based on Figure 4 showing correlation structural breaks in Fernandez-Macho (2018).
library(wavemulcor)
data(exchange)
returns <- diff(log(as.matrix(exchange)))
returns <- ts(returns, start=1970, freq=12)
N <- dim(returns)[1]
M <- 30
window <- "gauss"
lmax <- 1
demusd <- returns[,"DEM.USD"]
jpyusd <- returns[,"JPY.USD"]
set.seed(140859)
xrand <- rnorm(N)
xx <- data.frame(demusd, jpyusd, xrand)
##exchange.names <- c(colnames(returns), "RAND")
Lst <- local.multiple.cross.correlation(xx, M, window=window, lag.max=lmax)
val <- Lst$vals
low.ci <- Lst$lower
upp.ci <- Lst$upper
YmaxR <- Lst$YmaxR
# ---------------------------
##Producing correlation plot
colnames(val) <- paste("Lag",-lmax:lmax)
xvar <- seq(1,N,M)
par(mfcol=c(lmax+1,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 c(-lmax:0,lmax:1)+lmax+1) {
matplot(1:N,val[,i], type="l", lty=1, ylim=c(ymin,1), #xaxt="n",
xlab="", ylab="", main=colnames(val)[i])
# if(i==lmax+1) {axis(side=1, at=seq(0,N+50,50))}
#axis(side=2, at=c(-.2, 0, .5, 1))
abline(h=0) ##Add Straight horiz
lines(low.ci[,i], lty=1, col=2) ##Add Connected Line Segments to a Plot
lines(upp.ci[,i], lty=1, col=2)
text(xvar,1, labels=names(xx)[YmaxR][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)
# }
Run the code above in your browser using DataLab