set.seed(1)
x <- rpar(1000, 0.8, 1, 0.5) # Generate a random PAR sequence
fit.par(x) # Estimate its parameters
plot(fit.par(x) # Plot the estimate
test.par(x) # Test the goodness of fit
# An example involving European stock market data
data(EuStockMarkets) # European Stock Markets 1991-1998
# Check for cointegration between German DAX and Swiss SMI
egcm(log(EuStockMarkets[,c("DAX", "SMI")]))
# The series are not found to be cointegrated.
# Perhaps they are partially cointegrated? Check the residuals
# of the cointegration fit for partial autoregression:
fit.par(egcm(EuStockMarkets[,c("DAX", "SMI")])$residuals)
# A plot of the model looks promising:
\dontrun{plot(fit.par(egcm(EuStockMarkets[,c("DAX", "SMI")])$residuals))}
# 74 # AR(1) process. However, it is important to check whether this is
# a better explanation than a simple random walk:
test.par(egcm(EuStockMarkets[,c("DAX", "SMI")])$residuals)
# The p-value is found to be 0.36, so the random walk hypothesis
# cannot be rejected.
# Another example involving a potential pairs trade between
# Coca-Cola and Pepsi.
# Fetch the price series for Coca-Cola (KO) and Pepsi (PEP) in 2014
library(TTR)
KO <- getYahooData("KO", 20140101, 20141231)$Close
PEP <- getYahooData("PEP", 20140101, 20141231)$Close
# Check whether they were cointegrated
library(egcm)
egcm(KO,PEP)
# It turns out that they are not cointegrated. Perhaps a better
# fit can be obtained with the partially autoregressive model:
fit.par(egcm(KO,PEP)$residuals)
# The mean-reverting component of the above fit explains 90 # the variance of the daily returns. Thus, it appears that the
# two series are close to being cointegrated. A plot further
# confirms this:
plot(fit.par(egcm(KO,PEP)$residuals))
# Still, it is important to check whether or not the residual
# series is simply a random walk:
test.par(egcm(KO,PEP)$residuals)
# In this case, the p-value associated with the hypothesis that
# the series is partially autoregressive is 0.12. Thus, the
# evidence of partial autoregression is marginal. The random walk
# may be a better explanation.
Run the code above in your browser using DataLab