{"word_count": 600, "character_count": 4992}
Following Michael's idea (here), I wanted to go further, based on his intuition (and dataset that he kindly sent me, there). If we consider the two series of Nikkei index and SP500 index in euros, we have to following graph,the code is simply the following (the merging function is simply here to avoid problem with different trading days: since we look at the index and not the return, it is the simplest way to deal with it).&#62; library(RODBC)&#62; base = odbcConnectExcel(+ "https://perso.univ-rennes1.fr/arthur.charpentier/spx_nky_eurusd.xls", + readOnly = TRUE)&#62; series1 = sqlQuery(base,query="select * from [Tabelle1$A2:B8837]") # SPX&#62; series2 = sqlQuery(base,query="select * from [Tabelle1$D2:E8631]") # NKY&#62; series3 = sqlQuery(base,query="select * from [Tabelle1$G2:H8945]") # EURUSD&#62; odbcCloseAll()&#62; series4=merge(series1,series3)&#62; series4$SPEUR=series4$SPX/series4$EURUSD&#62; series5=merge(series4,series2)&#62; x=(as.Date(series5[,1])-as.Date("01/01/0000","%d/%m/%Y"))/365.25&#62; yl=range(series5[,4])&#62; xl=c(1975,2010)&#62; plot(x,series5[,4],axes=FALSE,xlab="",ylab="",type="l",+ lwd=3,col="red",xlim=xl,ylim=yl)&#62; axis(1)&#62; axis(2, col="red")&#62; par(new=TRUE)&#62; yl=range(series5[,5])&#62; plot(x,series5[,5],axes=FALSE,xlab="",ylab="",type="l",+ lwd=3,col="blue",xlim=xl,ylim=yl)&#62; axis(4, col="blue")&#62; mtext("SP500 in Euros", 2, line=2, col="red", cex=1.2)&#62; mtext("NKY", 4, line=2, col="blue", cex=1.2)Those two series series seem to have a similar pattern, so an idea can be translate the SP500 on the left,Interesting isn't it ? Suppose that we want to forecast (or forsee ?) the SP500 in euro for the next 10 years...People who enjoy charts would have here a nice tool...Those two series are extremely correlated, with a correlation of 0.9572,&#62; X1=series5[2501:n,4]&#62; X2=series5[1:(n-2500),5]&#62; cor(X1,X2)[1] 0.9572484But are the two series cointegrated (see here, here or therefor material on cointegration) ? Well, using standard procedure, we first have to prove that the two series are integrated. First, let us look at the autocorrelograms,At first sight, we confirm the economic intuition that those indices should be integrated. Standard tests confirm that intuition,&#62; acf(X2,lag=1000,col="light green")&#62; acf(X1,lag=1000,col="light green")&#62; library(tseries)&#62; adf.test(X1)        Augmented Dickey-Fuller Testdata:  X1 Dickey-Fuller = -1.0768, Lag order = 17, p-value = 0.9264alternative hypothesis: stationary &#62; adf.test(X2)        Augmented Dickey-Fuller Testdata:  X2 Dickey-Fuller = -1.2905, Lag order = 17, p-value = 0.8788alternative hypothesis: stationaryBut if we want to go further, we have to find the cointegration relationship between the two series. From an heuristic point of view, a linear regression should be a good proxy,&#62; reg=lm(X1~X2)&#62; plot(residuals(reg))&#62; acf(residuals(reg),lag=1000,col="light green")&#62; adf.test(residuals(reg))        Augmented Dickey-Fuller Testdata:  residuals(reg) Dickey-Fuller = -5.176, Lag order = 17, p-value = 0.01alternative hypothesis: stationary Message d'avis :In adf.test(residuals(reg)) : p-value smaller than printed p-value&#62; pp.test(residuals(reg))        Phillips-Perron Unit Root Testdata:  residuals(reg) Dickey-Fuller Z(alpha) = -46.9775, Truncation lag parameter = 11,p-value = 0.01alternative hypothesis: stationary Message d'avis :In pp.test(residuals(reg)) : p-value smaller than printed p-valueWhen we look at the autocorrelation function, it looks like we do have a stationary series.This idea is - more or less - the idea of Engle-Granger two step procedure. But actually, we can not directly use Dickey-Fuller's test to see if residuals are integrated. This was proved in Phillips and Ouliaris (1990), who also proposed a test (see e.g. here),&#62; library(tseries); po.test(cbind(X1,X2))        Phillips-Ouliaris Cointegration Testdata:  cbind(X1, X2) Phillips-Ouliaris demeaned = -53.1766, Truncation lag parameter = 57,p-value = 0.01Message d'avis :In po.test(cbind(X1, X2)) : p-value smaller than printed p-valueAnother similar function can be found in R&#62; library(urca)&#62; summary(ca.po(cbind(X1,X2)))######################################## # Phillips and Ouliaris Unit Root Test # ######################################## Test of type Pu detrending of series none Call:lm(formula = z[, 1] ~ z[, -1] - 1)Value of test-statistic is: 45.2032 Critical values of Pu are:                  10pct    5pct    1pctcritical values 20.3933 25.9711 38.3413Thus, we has to admit that those series are cointegrated.Based on that idea, it is possible to model the stationary component, and forecast it for the next ten years, based on the assumption that we know the behavior of one time series. Hence, if we add the confidence interval due to the stationary component uncertainty, we have the following graph, Of course, again, only uncertainty related to the stationary process is considered here....