I. Download monthly data for J.P.Morgan Chase (JPM) for the period January, 2014 to today. Use the data for the following tests:

#Import tidyquant to get stock prices
library(tidyquant)
## 필요한 패키지를 로딩중입니다: lubridate
## 
## 다음의 패키지를 부착합니다: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
## 필요한 패키지를 로딩중입니다: PerformanceAnalytics
## 필요한 패키지를 로딩중입니다: xts
## 필요한 패키지를 로딩중입니다: zoo
## 
## 다음의 패키지를 부착합니다: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 다음의 패키지를 부착합니다: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
## 필요한 패키지를 로딩중입니다: quantmod
## 필요한 패키지를 로딩중입니다: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
#Extracting stock prices using tidyquant package
jpm_data <- tq_get('JPM',
                   from = '2014-01-01',
                   to = '2023-04-24',
                   get='stock.prices',
                   periodicity='daily')

head(jpm_data)
## # A tibble: 6 x 8
##   symbol date        open  high   low close   volume adjusted
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
## 1 JPM    2014-01-02  58.3  58.5  58.0  58.2 15627600     45.0
## 2 JPM    2014-01-03  58.3  59.0  58.2  58.7 14214100     45.3
## 3 JPM    2014-01-06  59.2  59.5  58.8  59   17550700     45.6
## 4 JPM    2014-01-07  59.3  59.4  58.1  58.3 17851200     45.0
## 5 JPM    2014-01-08  58.5  58.9  58.3  58.9 14687400     45.5
## 6 JPM    2014-01-09  59.0  59    58.3  58.8 13242500     45.4
#Extract the close price
jpm <- tibble::tibble(date=jpm_data$date,jpm=jpm_data$close)
head(jpm)
## # A tibble: 6 x 2
##   date         jpm
##   <date>     <dbl>
## 1 2014-01-02  58.2
## 2 2014-01-03  58.7
## 3 2014-01-06  59  
## 4 2014-01-07  58.3
## 5 2014-01-08  58.9
## 6 2014-01-09  58.8

1. Test for the stationarity of the closing prices for JPM.

#We will conduct several methods to check the stationarity
# Method 1: Plot the stock price 
# According to the price graph, it seems that the closing price is not stationary
library(ggplot2)
jpm %>%
  ggplot(aes(x=date,y=jpm))+
  geom_line(color='#4373B6') +
  theme_bw() +
  ggtitle('JPM from 2014(M1) - 2023(M4)')+
  xlab('Date')+
  ylab('Close Price')

#Custome code for ACF and PACF Plot
ggplot.corr <- function(data, lag.max = 24, ci = 0.95, large.sample.size = TRUE, horizontal = TRUE,...) {
  options(dplyr.banner_expression = FALSE)
  
  require(ggplot2)
  require(dplyr)
  require(cowplot)
  
  if(horizontal == TRUE) {numofrow <- 1} else {numofrow <- 2}
  
  list.acf <- acf(data, lag.max = lag.max, type = "correlation", plot = FALSE)
  N <- as.numeric(list.acf$n.used)
  df1 <- data.frame(lag = list.acf$lag, acf = list.acf$acf)
  df1$lag.acf <- dplyr::lag(df1$acf, default = 0)
  df1$lag.acf[2] <- 0
  df1$lag.acf.cumsum <- cumsum((df1$lag.acf)^2)
  df1$acfstd <- sqrt(1/N * (1 + 2 * df1$lag.acf.cumsum))
  df1$acfstd[1] <- 0
  df1 <- dplyr::select(df1, lag, acf, acfstd)
  
  list.pacf <- acf(data, lag.max = lag.max, type = "partial", plot = FALSE)
  df2 <- data.frame(lag = list.pacf$lag,pacf = list.pacf$acf)
  df2$pacfstd <- sqrt(1/N)
  
  if(large.sample.size == TRUE) {
    plot.acf <- ggplot(data = df1, aes( x = lag, y = acf)) +
    geom_area(aes(x = lag, y = qnorm((1+ci)/2)*acfstd), fill = "#B9CFE7") +
    geom_area(aes(x = lag, y = -qnorm((1+ci)/2)*acfstd), fill = "#B9CFE7") +
    geom_col(fill = "#4373B6", width = 0.7) +
    scale_x_continuous(breaks = seq(0,max(df1$lag),6)) +
    scale_y_continuous(name = element_blank(), 
                       limits = c(min(df1$acf,df2$pacf),1)) +
    ggtitle("ACF") +
    theme_bw() +
      theme(plot.title = element_text(size=10)) 
    
    plot.pacf <- ggplot(data = df2, aes(x = lag, y = pacf)) +
    geom_area(aes(x = lag, y = qnorm((1+ci)/2)*pacfstd), fill = "#B9CFE7") +
    geom_area(aes(x = lag, y = -qnorm((1+ci)/2)*pacfstd), fill = "#B9CFE7") +
    geom_col(fill = "#4373B6", width = 0.7) +
    scale_x_continuous(breaks = seq(0,max(df2$lag, na.rm = TRUE),6)) +
    scale_y_continuous(name = element_blank(),
                       limits = c(min(df1$acf,df2$pacf),1)) +
    ggtitle("PACF") +
    theme_bw() +
      theme(plot.title = element_text(size=10)) 
  }
  else {
    plot.acf <- ggplot(data = df1, aes( x = lag, y = acf)) +
    geom_col(fill = "#4373B6", width = 0.7) +
    geom_hline(yintercept = qnorm((1+ci)/2)/sqrt(N), 
               colour = "sandybrown",
               linetype = "dashed",
               size=1) + 
    geom_hline(yintercept = - qnorm((1+ci)/2)/sqrt(N), 
               colour = "sandybrown",
               linetype = "dashed",
               size=1) + 
    scale_x_continuous(breaks = seq(0,max(df1$lag),6)) +
    scale_y_continuous(name = element_blank(), 
                       limits = c(min(df1$acf,df2$pacf),1)) +
    ggtitle("ACF") +
    theme_bw() +
      theme(plot.title = element_text(size=10)) 
    
    plot.pacf <- ggplot(data = df2, aes(x = lag, y = pacf)) +
    geom_col(fill = "#4373B6", width = 0.7) +
    geom_hline(yintercept = qnorm((1+ci)/2)/sqrt(N), 
               colour = "sandybrown",
               linetype = "dashed",
               size=1) + 
    geom_hline(yintercept = - qnorm((1+ci)/2)/sqrt(N), 
               colour = "sandybrown",
               linetype = "dashed",
               size=1) + 
    scale_x_continuous(breaks = seq(0,max(df2$lag, na.rm = TRUE),6)) +
    scale_y_continuous(name = element_blank(),
                       limits = c(min(df1$acf,df2$pacf),1)) +
    ggtitle("PACF") +
    theme_bw() +
      theme(plot.title = element_text(size=10)) 
  }
  cowplot::plot_grid(plot.acf, plot.pacf, nrow = numofrow)
}
# Method 2: ACF & PACF
# According to the ACF & PACF, the closing price is not stationary
ggplot.corr(jpm$jpm,large.sample.size = FALSE)
## 필요한 패키지를 로딩중입니다: dplyr
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:xts':
## 
##     first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 필요한 패키지를 로딩중입니다: cowplot
## 
## 다음의 패키지를 부착합니다: 'cowplot'
## The following object is masked from 'package:lubridate':
## 
##     stamp
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

# Method 3: adf test
# The p-value for adf test is 0.28, thus we conclude it's not stationary
library(tseries)

adf.test(jpm$jpm)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  jpm$jpm
## Dickey-Fuller = -2.7017, Lag order = 13, p-value = 0.2813
## alternative hypothesis: stationary

2. Test for the stationarity of the returns for JPM.

# Compute Daily return of JPM
jpm_return <- jpm_data %>%
  tq_transmute(select = close,
               mutate_fun = dailyReturn,
               type = 'log',
               col_rename = 'returns')

head(jpm_return)
## # A tibble: 6 x 2
##   date        returns
##   <date>        <dbl>
## 1 2014-01-02  0      
## 2 2014-01-03  0.00770
## 3 2014-01-06  0.00578
## 4 2014-01-07 -0.0116 
## 5 2014-01-08  0.00939
## 6 2014-01-09 -0.00187
# Stationarity test
# Method1: Plot the return
# We can tell from the graph that the return is stationary with conditional heteroskadasticity during COVID 
jpm_return %>%
  ggplot(aes(x=date,y=returns))+
  geom_line(color='#4373B6') +
  theme_bw() +
  ggtitle('JPM Returns from 2014(M1) - 2023(M4) ')+
  xlab('Date')+
  ylab('Returns')+
  scale_y_continuous(labels = scales::percent)

# Method 2: ACF & PACF
# According to the ACF & PACF, the return is stationary
ggplot.corr(jpm_return$returns,large.sample.size = FALSE)

# Method 3: adf test
# The p-value for adf test is lower than 0.05, thus we conclude it's stationary


adf.test(jpm_return$returns)
## Warning in adf.test(jpm_return$returns): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  jpm_return$returns
## Dickey-Fuller = -13.392, Lag order = 13, p-value = 0.01
## alternative hypothesis: stationary

3. Run the best ARIMA model for JPM returns.

# Convert return data to ts format
library(tseries)

ts_jpm_return <- jpm_return$returns %>%
  ts()

tail(ts_jpm_return)
## [1]  0.072794649  0.007897844  0.011165298 -0.001273746 -0.002907515
## [6] -0.001919354
#Custom code for ARIMA Model ACF PACF reisduals
library(dplyr)
library(rsample)

arima.order <- c(2,0,2)

p <- 0:arima.order[1]
d <- 0:arima.order[2] #Revise this part depending on how many differencing was conducted
q <- 0:arima.order[3]

df.arima.order <- data.frame(t(expand.grid(p=p,d=d,q=q)))
df.colnames <- data.frame(expand.grid(p=p,d=d,q=q))
df.colnames$type <- with(df.colnames,paste0
                         ("ARIMA(",p,",",d,",",q,")"))

list.arima.model <- lapply(df.arima.order, 
                           function(data, x, ...) { 
                             arima(x = data, order = x, ...)
                             }, 
                           data = ts_jpm_return) # Data has to be in ts format

df.arima.residual <- sapply(list.arima.model, 
                            function(x) {
                              x$residuals
                              })
df.arima.residual <- data.frame(df.arima.residual)
colnames(df.arima.residual) <- df.colnames$type
df.arima.residual$time <- time(ts_jpm_return) # Data has to be in ts format


df.arima.residual.plot <- gather(data = df.arima.residual, value = "residual", key = "type",-time)


df.acf <- sapply(subset(df.arima.residual, select = -time), 
       function(x, lag.max,...) {
         acf(x = x, lag.max = lag.max, plot = FALSE)$acf
       },
       lag.max = 24)
df.acf <- data.frame(df.acf)
colnames(df.acf) <- df.colnames$type

df.acf$lag <- 0:(dim(df.acf)[1]-1)
df.acf.plot <- gather(df.acf, 
                      value = "value", 
                      key = "Model",
                      -lag)


df.pacf <- sapply(subset(df.arima.residual, select = -time),
                  function(x, lag.max,...) {
                    acfvalue <- as.numeric(acf(x = x, 
                                               lag.max = lag.max,
                                               type = "partial",
                                               plot = FALSE)$acf)
                    return(c(1,acfvalue))
                    },
                  lag.max = 24)
df.pacf <- data.frame(df.pacf)
colnames(df.pacf) <- df.colnames$type

df.pacf$lag <- 0:(dim(df.pacf)[1]-1)
df.pacf.plot <- gather(df.pacf, 
                       value = "value", 
                       key = "Model",
                       -lag)

fig.acf <- ggplot(data = df.acf.plot, aes(x = lag, y = value)) +
  geom_col(width = 0.4, fill = "#667fa2") +
  geom_hline(yintercept = qnorm((1+0.95)/2)/sqrt(dim(df.acf.plot)[1]),
             linetype = "dashed",
             colour = "grey50") +
  geom_hline(yintercept = -qnorm((1+0.95)/2)/sqrt(dim(df.acf.plot)[1]),
             linetype = "dashed",
             colour = "grey50") +
  scale_y_continuous(name = element_blank()) +
  scale_x_continuous(breaks = seq(0,24,4)) +
  ggtitle("ACF of residuals") +
  facet_wrap(~Model) +
  theme_bw() +
  theme(panel.grid.minor = element_blank(),
        strip.background = element_rect(fill = "#f8ddc4"))

fig.pacf <- ggplot(data = df.pacf.plot, aes(x = lag, y = value)) +
  geom_col(width = 0.4, fill = "#667fa2") +
  geom_hline(yintercept = qnorm((1+0.95)/2)/sqrt(dim(df.pacf.plot)[1]),
             linetype = "dashed",
             colour = "grey50") +
  geom_hline(yintercept = -qnorm((1+0.95)/2)/sqrt(dim(df.pacf.plot)[1]),
             linetype = "dashed",
             colour = "grey50") +
  scale_y_continuous(name = element_blank()) +
  scale_x_continuous(breaks = seq(0,24,4)) +
  ggtitle("PACF of residuals") +
  facet_wrap(~Model) +
  theme_bw() +
  theme(panel.grid.minor = element_blank(),
        strip.background = element_rect(fill = "#f8ddc4"))

fig.residual <- ggplot(data = df.arima.residual.plot, aes(x = time, y = residual)) +
  geom_line(colour = "#667fa2") +
  ggtitle("Residuals") +
  facet_wrap(~type) +
  theme_bw() +
  theme(panel.grid.minor = element_blank(),
        strip.background = element_rect(fill = "#f8ddc4"))
# Plot ACF of residuals 
fig.acf

# Plot PACF of residuals 
fig.pacf

# Plot residuals 
fig.residual
## 
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

# Custom Code for AIC 
# From AIC we can tell that ARIMA (0,0,0) has the lowest AIC.
aic <- sapply(list.arima.model, function(X) {X$aic})
aic <- round(as.numeric(aic),2)
df.aic.plot <- data.frame(aic = aic, p = df.colnames$p, q = df.colnames$q)

ggplot(data = df.aic.plot, aes(x = p, y = q)) + 
  geom_raster(aes(fill = aic)) +
  geom_text(aes( label = aic), colour = "black") + 
  scale_x_continuous(expand = c(0.05,0.05)) +
  scale_color_continuous( high = "#FFA800", low = "#4AC200") +
  theme_bw() +
  theme(panel.grid.minor = element_blank()) + 
  scale_fill_distiller(palette = "Spectral", direction = -1) +
  ggtitle('Akaike Information Criterion (AIC)')

4. Test for the existence of heteroskedasticity on the residuals of the JPM’s ARIMA model.

library(forecast)

# Autoarima gives ARIMA(2,0,0)
jpm_arima <- auto.arima(jpm_return$returns)

jpm_arima
## Series: jpm_return$returns 
## ARIMA(2,0,0) with zero mean 
## 
## Coefficients:
##           ar1     ar2
##       -0.0897  0.0687
## s.e.   0.0206  0.0206
## 
## sigma^2 = 0.0002974:  log likelihood = 6186.8
## AIC=-12367.6   AICc=-12367.59   BIC=-12350.32
library(car)
## 필요한 패키지를 로딩중입니다: carData
## 
## 다음의 패키지를 부착합니다: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
# Null (H0): Heteroskedasticity is not present.
# Since the p-value < 0.05, there is heteroskedasticity
white.test(jpm_arima$residuals)
## 
##  White Neural Network Test
## 
## data:  jpm_arima$residuals
## X-squared = 50.828, df = 2, p-value = 9.18e-12

5. Find the historical measure of the volatility of the JPM’s returns.

# Calculate historical standard deviation
# Annualize
sd(jpm_return$returns)*sqrt(252)
## [1] 0.2755784

6. Find the Exponentially Weighted Moving Average (EWMA) measure of the volatility of JPM’s returns.

library(timetk)
library(quantmod)
library(DT)
# Change the data format to xts to calculate rolling volaitlity
jpm_return_xts <- jpm_return %>% tk_xts()
## Warning: Non-numeric columns being dropped: date
## Using column `date` for date_var.
realized_vol <- rollapply(jpm_return_xts,width=22,FUN=sd.annualized)
realized_vol_df <- realized_vol %>% tk_tbl()
datatable(realized_vol_df)
# Plot the Rolling Volatility
realized_vol_df %>%
  ggplot(aes(x=index,y=returns))+
  geom_line(color='#4373B6')+
  theme_bw()+
  labs(x='Date',y='Volatility',title='JPM Rolling Volatility')+
  scale_y_continuous(labels = scales::percent)
## Warning: Removed 21 rows containing missing values (`geom_line()`).

7. Test whether the two measures of the volatility, historical and EWMA, are statistically the same.

# Test whether the rolling vollatility and historical volaitility is the same 
# Rolling Vollatility and the historical volatility is not the same
library(stats)
t.test(realized_vol_df$returns,mu=sd(jpm_return$returns)*sqrt(252))
## 
##  One Sample t-test
## 
## data:  realized_vol_df$returns
## t = -12.797, df = 2320, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0.2755784
## 95 percent confidence interval:
##  0.2322638 0.2437746
## sample estimates:
## mean of x 
## 0.2380192

8. Estimate an auto-regression model of the volatility for JPM’s returns using r2 and log(High/low) as measures of volatility. Use the model to forecast next three-periods conditional variance.

# Compute Error^2
error2 <- ts((jpm_arima$residuals)^2)
# Plot error^2
autoplot(error2,color='#4373B6')+
  theme_bw()+
  labs(x='Time',y='Volatility',title='Error^2')+
  scale_y_continuous(labels = scales::percent)

# Test for Stationarity
adf.test(error2)
## Warning in adf.test(error2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  error2
## Dickey-Fuller = -8.3374, Lag order = 13, p-value = 0.01
## alternative hypothesis: stationary
# Plot acf and pacf of error^2
# Implies Autocorrelation
ggplot.corr(error2,large.sample.size = FALSE)

# Conduct ARIMA on error^2
varianceq <- auto.arima(error2)
varianceq
## Series: error2 
## ARIMA(2,1,3) 
## 
## Coefficients:
##           ar1      ar2      ma1     ma2      ma3
##       -0.6526  -0.6842  -0.0155  0.0286  -0.5818
## s.e.   0.0521   0.0727   0.0525  0.0800   0.0496
## 
## sigma^2 = 8.991e-07:  log likelihood = 12975.69
## AIC=-25939.39   AICc=-25939.35   BIC=-25904.84
fore <- forecast(varianceq,h=50)

# Plot the error^2 forecast
autoplot(fore$x %>% tail(300))+
  autolayer(fore,color='red')+
  theme_bw()+
  labs(y='Error2',title='Error2 Forecast ARIMA (2,1,3)')

9. Use the auto-regressive variance model to estimate the long-run or unconditional variance of the JPM’s returns.

# 0.0004228115 is the long-run forecast
fore
##      Point Forecast         Lo 80       Hi 80        Lo 95       Hi 95
## 2343   0.0003097112 -0.0009054868 0.001524909 -0.001548774 0.002168196
## 2344   0.0007409376 -0.0005394588 0.002021334 -0.001217260 0.002699135
## 2345   0.0002925830 -0.0009950668 0.001580233 -0.001676707 0.002261873
## 2346   0.0002901513 -0.0010072799 0.001587583 -0.001694098 0.002274401
## 2347   0.0005984802 -0.0007395009 0.001936461 -0.001447785 0.002644746
## 2348   0.0003989313 -0.0009542008 0.001752063 -0.001670506 0.002468368
## 2349   0.0003182117 -0.0010453866 0.001681810 -0.001767232 0.002403655
## 2350   0.0005074100 -0.0008838121 0.001898632 -0.001620281 0.002635101
## 2351   0.0004391653 -0.0009707229 0.001849053 -0.001717073 0.002595403
## 2352   0.0003542611 -0.0010678559 0.001776378 -0.001820679 0.002529201
## 2353   0.0004563584 -0.0009869066 0.001899623 -0.001750925 0.002663642
## 2354   0.0004478179 -0.0010146287 0.001910264 -0.001788801 0.002684437
## 2355   0.0003835414 -0.0010927307 0.001859814 -0.001874222 0.002641305
## 2356   0.0004313306 -0.0010629034 0.001925565 -0.001853903 0.002716564
## 2357   0.0004441186 -0.0010685448 0.001956782 -0.001869300 0.002757538
## 2358   0.0004030783 -0.0011244235 0.001930580 -0.001933034 0.002739191
## 2359   0.0004211119 -0.0011227833 0.001965007 -0.001940072 0.002782296
## 2360   0.0004374211 -0.0011238533 0.001998695 -0.001950342 0.002825184
## 2361   0.0004144402 -0.0011621096 0.001990990 -0.001996685 0.002825565
## 2362   0.0004182794 -0.0011738580 0.002010417 -0.002016685 0.002853243
## 2363   0.0004314964 -0.0011770584 0.002040051 -0.002028576 0.002891569
## 2364   0.0004202445 -0.0012036129 0.002044102 -0.002063231 0.002903720
## 2365   0.0004185450 -0.0012204279 0.002057518 -0.002088048 0.002925138
## 2366   0.0004273520 -0.0012272609 0.002081965 -0.002103160 0.002957864
## 2367   0.0004227674 -0.0012469390 0.002092474 -0.002130828 0.002976363
## 2368   0.0004197339 -0.0012647443 0.002104212 -0.002156453 0.002995921
## 2369   0.0004248501 -0.0012746598 0.002124360 -0.002174326 0.003024026
## 2370   0.0004235867 -0.0012906972 0.002137870 -0.002198184 0.003045358
## 2371   0.0004209109 -0.0013078408 0.002149663 -0.002222987 0.003064808
## 2372   0.0004235215 -0.0013197788 0.002166822 -0.002242626 0.003089669
## 2373   0.0004236485 -0.0013340711 0.002181368 -0.002264552 0.003111848
## 2374   0.0004217796 -0.0013501124 0.002193672 -0.002288095 0.003131654
## 2375   0.0004229123 -0.0013631294 0.002208954 -0.002308603 0.003154427
## 2376   0.0004234517 -0.0013766576 0.002223561 -0.002329578 0.003176481
## 2377   0.0004223247 -0.0013916637 0.002236313 -0.002351931 0.003196581
## 2378   0.0004226912 -0.0014051028 0.002250485 -0.002372678 0.003218061
## 2379   0.0004232230 -0.0014183059 0.002264752 -0.002393152 0.003239598
## 2380   0.0004226253 -0.0014324942 0.002277745 -0.002414535 0.003259786
## 2381   0.0004226515 -0.0014459651 0.002291268 -0.002435151 0.003280454
## 2382   0.0004230433 -0.0014589989 0.002305086 -0.002455292 0.003301379
## 2383   0.0004227697 -0.0014725830 0.002318122 -0.002475922 0.003321461
## 2384   0.0004226802 -0.0014858861 0.002331246 -0.002496220 0.003341580
## 2385   0.0004229258 -0.0014987794 0.002344631 -0.002516069 0.003361920
## 2386   0.0004228267 -0.0015119204 0.002357574 -0.002536114 0.003381767
## 2387   0.0004227233 -0.0015249725 0.002370419 -0.002556020 0.003401467
## 2388   0.0004228586 -0.0015377095 0.002383427 -0.002575572 0.003421289
## 2389   0.0004228411 -0.0015505134 0.002396196 -0.002595144 0.003440826
## 2390   0.0004227600 -0.0015632937 0.002408814 -0.002614647 0.003460167
## 2391   0.0004228249 -0.0015758518 0.002421502 -0.002633887 0.003479537
## 2392   0.0004228380 -0.0015883828 0.002434059 -0.002653059 0.003498735

10. Test whether the volatility measures derived from alternative methods are statistically the same.

11. Run an ARCH and/or GARCH model on JPM’s returns data.

library(FinTS)
## 
## 다음의 패키지를 부착합니다: 'FinTS'
## The following object is masked from 'package:forecast':
## 
##     Acf
# Arch Test reveals that there is an ARCH(1) effect
ArchTest(jpm_return$returns,lags=1)
## 
##  ARCH LM-test; Null hypothesis: no ARCH effects
## 
## data:  jpm_return$returns
## Chi-squared = 473.98, df = 1, p-value < 2.2e-16
library(rugarch)
## 필요한 패키지를 로딩중입니다: parallel
## 
## 다음의 패키지를 부착합니다: 'rugarch'
## The following object is masked from 'package:stats':
## 
##     sigma
garch1 <- ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1, 0)), mean.model=list(armaOrder=c(0, 0)), distribution.model="std")

ugarchfit(spec=garch1,data=jpm_return_xts)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,0)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000644    0.000253   2.5452  0.01092
## omega   0.000171    0.000013  13.4880  0.00000
## alpha1  0.454146    0.061317   7.4066  0.00000
## shape   4.110240    0.390873  10.5155  0.00000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000644    0.000230   2.8013 0.005091
## omega   0.000171    0.000013  13.0294 0.000000
## alpha1  0.454146    0.106729   4.2551 0.000021
## shape   4.110240    0.374248  10.9827 0.000000
## 
## LogLikelihood : 6597.133 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.6303
## Bayes        -5.6205
## Shibata      -5.6303
## Hannan-Quinn -5.6268
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                   0.001147  0.9730
## Lag[2*(p+q)+(p+q)-1][2]  0.678463  0.6154
## Lag[4*(p+q)+(p+q)-1][5]  1.858697  0.6522
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic   p-value
## Lag[1]                       2.33 1.269e-01
## Lag[2*(p+q)+(p+q)-1][2]      6.09 2.082e-02
## Lag[4*(p+q)+(p+q)-1][5]     17.69 8.304e-05
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale   P-Value
## ARCH Lag[2]     7.507 0.500 2.000 6.148e-03
## ARCH Lag[4]    16.830 1.397 1.611 8.600e-05
## ARCH Lag[6]    28.129 2.222 1.500 2.467e-07
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  5.3756
## Individual Statistics:              
## mu     0.03711
## omega  4.32872
## alpha1 2.49304
## shape  3.94609
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.07 1.24 1.6
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           1.0614 0.28860    
## Negative Sign Bias  0.9777 0.32835    
## Positive Sign Bias  0.4514 0.65174    
## Joint Effect        6.5382 0.08817   *
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     15.49       0.6910
## 2    30     22.67       0.7914
## 3    40     32.72       0.7506
## 4    50     38.27       0.8656
## 
## 
## Elapsed time : 0.253016
garch2 <- ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1, 1)), mean.model=list(armaOrder=c(0, 0)), distribution.model="std")

ugarchfit(spec=garch2,data=jpm_return_xts)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000722    0.000243   2.9735 0.002944
## omega   0.000010    0.000002   5.7214 0.000000
## alpha1  0.133806    0.010263  13.0382 0.000000
## beta1   0.834375    0.014624  57.0567 0.000000
## shape   4.955312    0.366224  13.5308 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000722    0.000213   3.3831 0.000717
## omega   0.000010    0.000003   3.5481 0.000388
## alpha1  0.133806    0.016427   8.1454 0.000000
## beta1   0.834375    0.022798  36.5986 0.000000
## shape   4.955312    0.669793   7.3983 0.000000
## 
## LogLikelihood : 6675.427 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.6964
## Bayes        -5.6841
## Shibata      -5.6964
## Hannan-Quinn -5.6919
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2807  0.5962
## Lag[2*(p+q)+(p+q)-1][2]    1.3119  0.4072
## Lag[4*(p+q)+(p+q)-1][5]    2.6393  0.4769
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.016  0.3134
## Lag[2*(p+q)+(p+q)-1][5]     1.829  0.6594
## Lag[4*(p+q)+(p+q)-1][9]     3.264  0.7146
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.6072 0.500 2.000  0.4358
## ARCH Lag[5]    1.7379 1.440 1.667  0.5321
## ARCH Lag[7]    2.8438 2.315 1.543  0.5435
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  28.0299
## Individual Statistics:              
## mu     0.03278
## omega  2.37494
## alpha1 1.21644
## beta1  1.19288
## shape  1.44379
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.28 1.47 1.88
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           0.7637 0.44510    
## Negative Sign Bias  1.9526 0.05099   *
## Positive Sign Bias  0.3858 0.69969    
## Joint Effect       10.1030 0.01771  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     11.36       0.9113
## 2    30     16.96       0.9628
## 3    40     28.42       0.8944
## 4    50     36.18       0.9131
## 
## 
## Elapsed time : 0.2624319
garch3 <- ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(2, 1)), mean.model=list(armaOrder=c(0, 0)), distribution.model="std")

ugarchfit(spec=garch3,data=jpm_return_xts)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(2,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu      0.000722    0.000243  2.972965 0.002949
## omega   0.000010    0.000002  6.051201 0.000000
## alpha1  0.133412    0.031566  4.226422 0.000024
## alpha2  0.000001    0.032798  0.000027 0.999979
## beta1   0.834975    0.016608 50.276500 0.000000
## shape   4.949455    0.374397 13.219820 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu      0.000722    0.000213  3.390875 0.000697
## omega   0.000010    0.000003  3.723701 0.000196
## alpha1  0.133412    0.033253  4.012064 0.000060
## alpha2  0.000001    0.033740  0.000026 0.999979
## beta1   0.834975    0.022275 37.484223 0.000000
## shape   4.949455    0.669373  7.394168 0.000000
## 
## LogLikelihood : 6675.332 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.6954
## Bayes        -5.6807
## Shibata      -5.6954
## Hannan-Quinn -5.6900
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2822  0.5953
## Lag[2*(p+q)+(p+q)-1][2]    1.3234  0.4043
## Lag[4*(p+q)+(p+q)-1][5]    2.6600  0.4726
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                       1.049  0.3057
## Lag[2*(p+q)+(p+q)-1][8]      2.993  0.6868
## Lag[4*(p+q)+(p+q)-1][14]     4.457  0.8332
## d.o.f=3
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[4]    0.5009 0.500 2.000  0.4791
## ARCH Lag[6]    1.9684 1.461 1.711  0.4978
## ARCH Lag[8]    2.8781 2.368 1.583  0.5665
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  28.0603
## Individual Statistics:              
## mu     0.03298
## omega  2.31977
## alpha1 1.21783
## alpha2 1.64630
## beta1  1.19158
## shape  1.44956
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.49 1.68 2.12
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           0.7579 0.44858    
## Negative Sign Bias  1.9661 0.04940  **
## Positive Sign Bias  0.3807 0.70344    
## Joint Effect       10.1385 0.01742  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     11.34       0.9119
## 2    30     17.01       0.9620
## 3    40     28.11       0.9021
## 4    50     36.82       0.8999
## 
## 
## Elapsed time : 0.228688
# GARCH(1,1) with ARMA(0,0) had the lowest AIC
jpm_garch <- ugarchfit(spec=garch2,data=jpm_return_xts)
jpm_garch@fit$coef
##           mu        omega       alpha1        beta1        shape 
## 7.222633e-04 1.042146e-05 1.338062e-01 8.343754e-01 4.955312e+00

12. Do a three-period ahead forecast of the conditional variance.

jpm_var <- jpm_garch@fit$var %>% ts()
jpm_var_fore <- ugarchforecast(jpm_garch,n.ahead = 30)
jpm_var_f <- jpm_var_fore@forecast$sigmaFor %>%ts()
jpm_var_t <- c(tail(jpm_var,50),rep(NA,50)) %>% ts() 

jpm_var_f <- c(rep(NA,50),(jpm_var_f)^2) %>% ts()


autoplot(jpm_var_t)+
  autolayer(jpm_var_f,series = 'Forecast')+
  autolayer(jpm_var_t,series = 'Actual Variance')+
  scale_colour_manual(name='Series', values=c('#4373B6','red'))+
  theme_bw()+
  labs(x='Period',title='JPM Conditional Variance and Forecast')+
   theme(legend.position=c(0.98, 0.98),
        legend.justification=c('right', 'top'))
## Warning: Removed 50 rows containing missing values (`geom_line()`).
## Removed 50 rows containing missing values (`geom_line()`).

Download monthly data from January 3, 2004 to today for S&P 500, DOW, Hang Seng Index(^HIS), Brazil (^BVSP), FTS 100, and10-year bond (^TNX).

# Aggregate symbols
symbols <- c("^GSPC", "^DJI", "^HSI", "^BVSP", "^FTSE", "^TNX")

start_date <- "2004-01-03"
end_date <- '2023-03-31'

data <- sp500_data <- tq_get(symbols, 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
all <- data$adjusted

sp500_data <- tq_get('^GSPC', 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
sp500 <- sp500_data$adjusted

dji_data <- tq_get('^DJI', 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
dji <- dji_data$adjusted


hsi_data <- tq_get('^HSI', 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
hsi <- hsi_data$adjusted

bvsp_data <- tq_get('^BVSP', 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
bvsp <- bvsp_data$adjusted

ftse_data <- tq_get('^FTSE', 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
ftse <- ftse_data$adjusted

tnx_data <- tq_get('^TNX', 
               from = start_date, 
               to = end_date, 
               periodicity = "monthly")
tnx <- tnx_data$adjusted
head(data)
## # A tibble: 6 x 8
##   symbol date        open  high   low close      volume adjusted
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>       <dbl>    <dbl>
## 1 ^GSPC  2004-02-01 1131. 1159. 1124. 1145. 27985600000    1145.
## 2 ^GSPC  2004-03-01 1145. 1163. 1087. 1126. 33597900000    1126.
## 3 ^GSPC  2004-04-01 1126. 1151. 1107. 1107. 31611900000    1107.
## 4 ^GSPC  2004-05-01 1107. 1128. 1076. 1121. 29326400000    1121.
## 5 ^GSPC  2004-06-01 1121. 1146. 1113. 1141. 27529500000    1141.
## 6 ^GSPC  2004-07-01 1141. 1141. 1079. 1102. 29285600000    1102.
# Plot all the data in one grid
# Need to test for stationarity using adf.test but already proved that they are all non-stationary
data %>%
  ggplot(aes(x = date, y = adjusted)) +
  geom_line(color='#4373B6') +
  facet_wrap(~symbol, scales = "free_y") +  # facet_wrap is used to make diff frames
  theme_bw() +       # using a new theme
  labs(x = "Date", y = "Price") +
  ggtitle("Price chart for stocks")

1. U.S. Indexes: Use Engel-Granger cointegration test to test for cointegration between S&P 500 and DOW.

library(lmtest)
# residual is non-stationary, no cointegration
reg1 <- lm(sp500~dji)
summary(reg1)
## 
## Call:
## lm(formula = sp500 ~ dji)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -293.18  -47.71   14.53   56.39  400.70 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.153e+02  1.834e+01  -11.73   <2e-16 ***
## dji          1.271e-01  9.370e-04  135.60   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 112.4 on 228 degrees of freedom
## Multiple R-squared:  0.9878, Adjusted R-squared:  0.9877 
## F-statistic: 1.839e+04 on 1 and 228 DF,  p-value: < 2.2e-16
adf.test(reg1$residuals)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  reg1$residuals
## Dickey-Fuller = -2.5808, Lag order = 6, p-value = 0.3319
## alternative hypothesis: stationary

2. U.S. and Europe: Use Engel-Granger cointegration test to test for cointegration between S&P 500 and FTSE 100.

# Residual is non-stationary
reg2 <- lm(sp500~ftse)
summary(reg2)
## 
## Call:
## lm(formula = sp500 ~ ftse)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -914.1 -508.4 -207.6  286.3 1831.0 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.958e+03  2.979e+02  -9.929   <2e-16 ***
## ftse         8.066e-01  4.735e-02  17.034   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 673.5 on 228 degrees of freedom
## Multiple R-squared:   0.56,  Adjusted R-squared:  0.5581 
## F-statistic: 290.2 on 1 and 228 DF,  p-value: < 2.2e-16
adf.test(reg2$residuals)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  reg2$residuals
## Dickey-Fuller = -2.5763, Lag order = 6, p-value = 0.3338
## alternative hypothesis: stationary

3. Emerging Nations: Use Engel-Granger cointegration test to test for cointegration between HIS and BVSP.

# Non-stationary
reg3 <- lm(hsi~bvsp)
summary(reg3)
## 
## Call:
## lm(formula = hsi ~ bvsp)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -13078.5  -2436.4    215.4   2100.8   9372.8 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.453e+04  6.130e+02   23.70   <2e-16 ***
## bvsp        1.141e-01  8.721e-03   13.08   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3484 on 228 degrees of freedom
## Multiple R-squared:  0.4287, Adjusted R-squared:  0.4262 
## F-statistic: 171.1 on 1 and 228 DF,  p-value: < 2.2e-16
adf.test(reg3$residuals)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  reg3$residuals
## Dickey-Fuller = -2.0995, Lag order = 6, p-value = 0.5341
## alternative hypothesis: stationary

4. Use Engel-Granger cointegration test to test for cointegration among all indices above.

# Non-stationary
reg4 <- lm(sp500~dji+hsi+bvsp+hsi+tnx)
summary(reg4)
## 
## Call:
## lm(formula = sp500 ~ dji + hsi + bvsp + hsi + tnx)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -251.49  -59.19   18.56   52.78  333.67 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 75.6739767 49.3713683   1.533    0.127    
## dji          0.1320781  0.0017118  77.159  < 2e-16 ***
## hsi         -0.0157094  0.0019215  -8.176 2.14e-14 ***
## bvsp        -0.0001439  0.0005496  -0.262    0.794    
## tnx         -9.3135423  7.0053060  -1.329    0.185    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 97.12 on 225 degrees of freedom
## Multiple R-squared:  0.991,  Adjusted R-squared:  0.9908 
## F-statistic:  6173 on 4 and 225 DF,  p-value: < 2.2e-16
adf.test(reg4$residuals)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  reg4$residuals
## Dickey-Fuller = -3.1632, Lag order = 6, p-value = 0.09494
## alternative hypothesis: stationary

5. Repeat 1-4 above using Johansen & Juselius cointegration methodology.

library(vars)
## 필요한 패키지를 로딩중입니다: MASS
## 
## 다음의 패키지를 부착합니다: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## 필요한 패키지를 로딩중입니다: strucchange
## 필요한 패키지를 로딩중입니다: sandwich
## 필요한 패키지를 로딩중입니다: urca
## 
## 다음의 패키지를 부착합니다: 'vars'
## The following object is masked from 'package:tidyquant':
## 
##     VAR
library(urca)

# If test > critical value reject null, cointegration exist
# No cointegration
jo1 <- ca.jo(cbind(sp500,dji),type='trace',ecdet='const')
summary(jo1)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , without linear trend and constant in cointegration 
## 
## Eigenvalues (lambda):
## [1] 3.745250e-02 1.559686e-02 2.081668e-17
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  3.58  7.52  9.24 12.97
## r = 0  | 12.29 17.85 19.96 24.60
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##             sp500.l2      dji.l2      constant
## sp500.l2   1.0000000   1.0000000    1.00000000
## dji.l2    -0.1336403  -0.1280365   -0.08752148
## constant 262.3364876 416.2129121 -541.23694094
## 
## Weights W:
## (This is the loading matrix)
## 
##            sp500.l2     dji.l2      constant
## sp500.d -0.09343496 0.04729566  5.029518e-16
## dji.d   -0.42175489 0.47404556 -1.897130e-15
# If test > critical value reject null, cointegration exist
# No cointegration
jo2 <- ca.jo(cbind(sp500,ftse),type='trace',ecdet='const')
summary(jo2)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , without linear trend and constant in cointegration 
## 
## Eigenvalues (lambda):
## [1] 3.316519e-02 2.602277e-02 2.775558e-17
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  6.01  7.52  9.24 12.97
## r = 0  | 13.70 17.85 19.96 24.60
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##             sp500.l2       ftse.l2    constant
## sp500.l2    1.000000     1.0000000   1.0000000
## ftse.l2    -1.851815     0.4946558  -0.3981879
## constant 9715.170642 -2256.4918921 114.5972949
## 
## Weights W:
## (This is the loading matrix)
## 
##            sp500.l2     ftse.l2      constant
## sp500.d 0.008350039 0.004610306 -7.600404e-17
## ftse.d  0.034075609 0.001824970 -2.601655e-16
# If test > critical value reject null, cointegration exist
# No cointegration
jo3 <- ca.jo(cbind(hsi,bvsp),type='trace',ecdet='const')
summary(jo3)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , without linear trend and constant in cointegration 
## 
## Eigenvalues (lambda):
## [1] 3.267944e-02 1.428419e-02 6.938894e-18
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  3.28  7.52  9.24 12.97
## r = 0  | 10.86 17.85 19.96 24.60
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                 hsi.l2     bvsp.l2      constant
## hsi.l2    1.000000e+00   1.0000000     1.0000000
## bvsp.l2  -2.501033e-02  -0.2875398    -0.3424396
## constant -2.060711e+04 543.2906867 -9657.4947437
## 
## Weights W:
## (This is the loading matrix)
## 
##             hsi.l2     bvsp.l2     constant
## hsi.d  -0.05679140 0.003756743 8.346140e-18
## bvsp.d -0.06443431 0.076617327 2.602571e-17
# If test > critical value reject null, cointegration exist
# No cointegration
jo4 <- ca.jo(cbind(sp500,dji,bvsp,tnx,hsi),type='trace',ecdet='const')
summary(jo4)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , without linear trend and constant in cointegration 
## 
## Eigenvalues (lambda):
## [1] 7.076518e-02 6.057222e-02 5.586582e-02 2.951695e-02 1.261789e-02
## [6] 2.775558e-17
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 4 |  2.90  7.52  9.24 12.97
## r <= 3 |  9.73 17.85 19.96 24.60
## r <= 2 | 22.83 32.00 34.91 41.07
## r <= 1 | 37.08 49.65 53.12 60.16
## r = 0  | 53.81 71.86 76.07 84.45
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##               sp500.l2        dji.l2       bvsp.l2        tnx.l2        hsi.l2
## sp500.l2  1.000000e+00    1.00000000  1.000000e+00    1.00000000  1.000000e+00
## dji.l2   -1.300651e-01   -0.09116724 -1.327631e-01   -0.26272386 -1.823078e-01
## bvsp.l2  -9.653227e-04   -0.01153499  5.220252e-04    0.06539474  5.641564e-03
## tnx.l2   -9.866922e+01 -141.48535224  7.059068e+01 -229.79200407 -4.292124e+01
## hsi.l2    3.465135e-02   -0.03686229  2.424940e-02   -0.15853576  4.551314e-03
## constant -7.362176e+01 1495.07214266 -4.975603e+02 2348.21505235  1.046397e+03
##               constant
## sp500.l2  1.000000e+00
## dji.l2   -3.972568e-02
## bvsp.l2   5.257231e-03
## tnx.l2    5.233085e+02
## hsi.l2   -5.834642e-02
## constant -1.368342e+03
## 
## Weights W:
## (This is the loading matrix)
## 
##             sp500.l2       dji.l2       bvsp.l2        tnx.l2        hsi.l2
## sp500.d  0.073831772 0.0045963490 -1.458907e-01 -2.806556e-04  1.588974e-02
## dji.d    0.566699640 0.0937051140 -8.293700e-01 -2.279338e-03  1.957688e-01
## bvsp.d   0.930725134 2.0758267589 -3.477402e+00 -5.929877e-01  4.375427e-01
## tnx.d    0.000108652 0.0001672563  9.367085e-05  1.649583e-05 -5.535620e-06
## hsi.d   -0.709177243 0.4873733990 -1.671248e+00  3.923067e-02  1.694572e-01
##              constant
## sp500.d -5.080127e-17
## dji.d   -2.407774e-16
## bvsp.d   2.136949e-15
## tnx.d    9.314697e-20
## hsi.d   -1.033257e-15

6. Write a bi-variate VAR model using S&P 500 and FTSE and estimate the model. Graph the impulse response functions showing the effects of one standard deviation shock to S&P 500 on FTSE and vise versa.

#Conver to ts format
library(timetk)
df <- tibble(date=sp500_data$date,sp500=sp500,ftse=ftse,dji=dji,bvsp=bvsp,hsi=hsi,tnx=tnx) %>% tk_xts()
## Warning: Non-numeric columns being dropped: date
## Using column `date` for date_var.
head(df)
##              sp500   ftse      dji  bvsp      hsi   tnx
## 2004-02-01 1144.94 4492.2 10583.92 21755 13907.03 3.984
## 2004-03-01 1126.21 4385.7 10357.70 22142 12681.67 3.837
## 2004-04-01 1107.30 4489.7 10225.57 19607 11942.96 4.501
## 2004-05-01 1120.68 4430.7 10188.45 19545 12198.24 4.655
## 2004-06-01 1140.84 4464.1 10435.48 21149 12285.75 4.617
## 2004-07-01 1101.72 4413.1 10139.71 22337 12238.03 4.475
q6 <- df[,c(1,2)] %>% ts(start=c(2004,2),frequency = 12)
VARselect(q6, lag.max=8,type="const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      2      1      2
q6var1 <- VAR(q6,p=1,type='const')
summary(q6var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sp500, ftse 
## Deterministic variables: const 
## Sample size: 229 
## Log Likelihood: -2898.018 
## Roots of the characteristic polynomial:
## 1.003 0.9457
## Call:
## VAR(y = q6, p = 1, type = "const")
## 
## 
## Estimation results for equation sp500: 
## ====================================== 
## sp500 = sp500.l1 + ftse.l1 + const 
## 
##          Estimate Std. Error t value Pr(>|t|)    
## sp500.l1  1.01027    0.01051  96.145   <2e-16 ***
## ftse.l1  -0.01229    0.01128  -1.090    0.277    
## const    68.26952   56.36099   1.211    0.227    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 106.4 on 226 degrees of freedom
## Multiple R-Squared: 0.9891,  Adjusted R-squared: 0.989 
## F-statistic: 1.023e+04 on 2 and 226 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation ftse: 
## ===================================== 
## ftse = sp500.l1 + ftse.l1 + const 
## 
##           Estimate Std. Error t value Pr(>|t|)    
## sp500.l1   0.03675    0.02221   1.655  0.09938 .  
## ftse.l1    0.93868    0.02384  39.370  < 2e-16 ***
## const    319.47516  119.13291   2.682  0.00787 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 224.9 on 226 degrees of freedom
## Multiple R-Squared: 0.9426,  Adjusted R-squared: 0.9421 
## F-statistic:  1856 on 2 and 226 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##       sp500  ftse
## sp500 11325 15081
## ftse  15081 50600
## 
## Correlation matrix of residuals:
##       sp500 ftse
## sp500  1.00 0.63
## ftse   0.63 1.00
serial.test(q6var1, lags.pt=10, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object q6var1
## Chi-squared = 60.782, df = 36, p-value = 0.006049
q6fore <- forecast(q6var1)

autoplot(q6fore,color='red')+
  theme_bw()+
  labs(x='Date',title='FTSE and S&P500 VAR Forecast')

q6irf <- irf(q6var1, impulse.variable = 1, response.variable = 2,  t = NULL, nhor = 20, scenario = 2, draw.plot = TRUE)

q6irf
## 
## Impulse response coefficients
## $sp500
##          sp500     ftse
##  [1,] 106.4196 141.7133
##  [2,] 105.7709 136.9341
##  [3,] 105.1743 132.4242
##  [4,] 104.6270 128.1688
##  [5,] 104.1264 124.1544
##  [6,] 103.6700 120.3677
##  [7,] 103.2554 116.7964
##  [8,] 102.8805 113.4289
##  [9,] 102.5431 110.2542
## [10,] 102.2413 107.2617
## [11,] 101.9731 104.4416
## 
## $ftse
##            sp500      ftse
##  [1,]   0.000000 174.69172
##  [2,]  -2.147149 163.97909
##  [3,]  -4.184684 153.84449
##  [4,]  -6.118584 144.25648
##  [5,]  -7.954501 135.18537
##  [6,]  -9.697782 126.60305
##  [7,] -11.353485 118.48296
##  [8,] -12.926390 110.79997
##  [9,] -14.421020 103.53031
## [10,] -15.841650  96.65152
## [11,] -17.192326  90.14235
## 
## 
## Lower Band, CI= 0.95 
## $sp500
##          sp500      ftse
##  [1,] 91.88232 107.66483
##  [2,] 87.64094 102.08921
##  [3,] 84.51505  97.54345
##  [4,] 80.99761  92.79794
##  [5,] 76.02615  85.44468
##  [6,] 71.45041  76.98597
##  [7,] 66.40387  72.60299
##  [8,] 61.90716  67.60419
##  [9,] 57.75767  61.57217
## [10,] 53.92498  56.05671
## [11,] 50.38163  50.33667
## 
## $ftse
##            sp500      ftse
##  [1,]   0.000000 157.60661
##  [2,]  -8.191781 138.63553
##  [3,] -15.366374 116.00250
##  [4,] -21.655085  95.69602
##  [5,] -27.168590  78.20649
##  [6,] -32.004179  63.14467
##  [7,] -36.440322  50.17517
##  [8,] -40.417696  39.00900
##  [9,] -43.961166  29.39520
## [10,] -47.117912  21.09782
## [11,] -49.929980  13.49718
## 
## 
## Upper Band, CI= 0.95 
## $sp500
##          sp500     ftse
##  [1,] 122.3030 171.9154
##  [2,] 120.0786 164.2598
##  [3,] 118.0337 158.5180
##  [4,] 117.4533 154.1863
##  [5,] 117.3091 148.3791
##  [6,] 116.7536 144.5951
##  [7,] 115.8756 140.9774
##  [8,] 115.7651 138.1844
##  [9,] 115.9826 135.5754
## [10,] 116.2195 133.0724
## [11,] 116.5170 131.1907
## 
## $ftse
##           sp500     ftse
##  [1,]  0.000000 187.2824
##  [2,]  2.820378 174.5713
##  [3,]  5.416809 166.9521
##  [4,]  7.805030 160.5668
##  [5,]  9.999705 156.3306
##  [6,] 12.014494 151.7798
##  [7,] 13.862129 147.3719
##  [8,] 15.554468 143.1019
##  [9,] 17.102559 138.9654
## [10,] 18.516696 134.9580
## [11,] 19.813848 131.0755
plot(q6irf)

7. Write a bi-variate VAR model using S&P 500 and 10-year bond and estimate the model. Graph the impulse response functions showing the effects of one standard deviation shock to S&P 500 on FTSE and vise versa.

q7 <- df[,c(1,6)] %>% ts(start=c(2004,2),frequency = 12)
VARselect(q7, lag.max=8,type="const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      2      1      2
q7var1 <- VAR(q7,p=1,type='const')
summary(q7var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sp500, tnx 
## Deterministic variables: const 
## Sample size: 229 
## Log Likelihood: -1392.094 
## Roots of the characteristic polynomial:
## 0.9872 0.9872
## Call:
## VAR(y = q7, p = 1, type = "const")
## 
## 
## Estimation results for equation sp500: 
## ====================================== 
## sp500 = sp500.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1   0.993344   0.008085 122.864   <2e-16 ***
## tnx.l1   -14.747935   7.230327  -2.040   0.0425 *  
## const     68.307900  32.972904   2.072   0.0394 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 105.7 on 226 degrees of freedom
## Multiple R-Squared: 0.9892,  Adjusted R-squared: 0.9891 
## F-statistic: 1.036e+04 on 2 and 226 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation tnx: 
## ==================================== 
## tnx = sp500.l1 + tnx.l1 + const 
## 
##           Estimate Std. Error t value Pr(>|t|)    
## sp500.l1 1.370e-05  1.873e-05   0.731    0.465    
## tnx.l1   9.808e-01  1.675e-02  58.542   <2e-16 ***
## const    2.404e-02  7.640e-02   0.315    0.753    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.245 on 226 degrees of freedom
## Multiple R-Squared: 0.9529,  Adjusted R-squared: 0.9524 
## F-statistic:  2284 on 2 and 226 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##           sp500     tnx
## sp500 1.118e+04 0.23171
## tnx   2.317e-01 0.06002
## 
## Correlation matrix of residuals:
##          sp500      tnx
## sp500 1.000000 0.008945
## tnx   0.008945 1.000000
serial.test(q7var1, lags.pt=10, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object q7var1
## Chi-squared = 57.542, df = 36, p-value = 0.01275
q7fore <- forecast(q7var1)

autoplot(q7fore,color='red')+
  theme_bw()+
  labs(x='Date',title='TNX and S&P500 VAR Forecast')

q7irf <- irf(q7var1, impulse.variable = 1, response.variable = 2,  t = NULL, nhor = 20, scenario = 2, draw.plot = TRUE)

q7irf
## 
## Impulse response coefficients
## $sp500
##           sp500         tnx
##  [1,] 105.72998 0.002191497
##  [2,] 104.99392 0.003597965
##  [3,] 104.24202 0.004967354
##  [4,] 103.47492 0.006300159
##  [5,] 102.69328 0.007596873
##  [6,] 101.89771 0.008857992
##  [7,] 101.08884 0.010084006
##  [8,] 100.26728 0.011275407
##  [9,]  99.43361 0.012432686
## [10,]  98.58842 0.013556331
## [11,]  97.73228 0.014646832
## 
## $tnx
##            sp500       tnx
##  [1,]   0.000000 0.2449833
##  [2,]  -3.612998 0.2402813
##  [3,]  -7.132603 0.2356201
##  [4,] -10.560038 0.2310001
##  [5,] -13.896524 0.2264218
##  [6,] -17.143283 0.2218857
##  [7,] -20.301533 0.2173922
##  [8,] -23.372491 0.2129416
##  [9,] -26.357372 0.2085344
## [10,] -29.257388 0.2041709
## [11,] -32.073749 0.1998514
## 
## 
## Lower Band, CI= 0.95 
## $sp500
##          sp500         tnx
##  [1,] 89.23732 -0.03450441
##  [2,] 87.88507 -0.03361104
##  [3,] 85.28329 -0.03086265
##  [4,] 83.39621 -0.02823806
##  [5,] 81.16519 -0.02939165
##  [6,] 77.38986 -0.03159370
##  [7,] 73.62559 -0.03357528
##  [8,] 69.97972 -0.03555865
##  [9,] 65.96889 -0.03540385
## [10,] 62.10992 -0.03518621
## [11,] 58.39953 -0.03491499
## 
## $tnx
##            sp500        tnx
##  [1,]   0.000000 0.21349398
##  [2,]  -8.402169 0.19830912
##  [3,] -16.033887 0.18339944
##  [4,] -23.072317 0.16836720
##  [5,] -29.521811 0.15348271
##  [6,] -35.426021 0.13996092
##  [7,] -40.123665 0.12539651
##  [8,] -44.632582 0.11187012
##  [9,] -48.822746 0.10082838
## [10,] -53.308638 0.09130210
## [11,] -58.353670 0.08284054
## 
## 
## Upper Band, CI= 0.95 
## $sp500
##          sp500        tnx
##  [1,] 117.1695 0.04632685
##  [2,] 115.5315 0.04717272
##  [3,] 114.1114 0.04797549
##  [4,] 113.8140 0.04989845
##  [5,] 113.5348 0.05220921
##  [6,] 113.2059 0.05602182
##  [7,] 112.8320 0.06000680
##  [8,] 111.8925 0.06321491
##  [9,] 110.9128 0.06715177
## [10,] 109.9586 0.07075707
## [11,] 109.0230 0.07404482
## 
## $tnx
##           sp500       tnx
##  [1,]  0.000000 0.2666460
##  [2,] -1.226235 0.2577423
##  [3,] -2.347785 0.2523163
##  [4,] -3.375712 0.2471897
##  [5,] -4.304407 0.2409386
##  [6,] -5.099592 0.2358753
##  [7,] -5.803790 0.2308190
##  [8,] -6.425801 0.2258300
##  [9,] -6.973529 0.2217289
## [10,] -7.454083 0.2188695
## [11,] -7.873859 0.2169686
plot(q7irf)

  1. Write a bi-variate VAR model using S&P 500 and HIS and estimate the model. Graph the impulse response functions showing the effects of one standard deviation shock to S&P 500 on HIS and vise versa.
q8 <- df[,c(1,5)] %>% ts(start=c(2004,2),frequency = 12)
VARselect(q8, lag.max=1,type="const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1
q8var1 <- VAR(q8,p=1,type='const')
summary(q8var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sp500, hsi 
## Deterministic variables: const 
## Sample size: 229 
## Log Likelihood: -3334.614 
## Roots of the characteristic polynomial:
##     1 0.9528
## Call:
## VAR(y = q8, p = 1, type = "const")
## 
## 
## Estimation results for equation sp500: 
## ====================================== 
## sp500 = sp500.l1 + hsi.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1  1.0001962  0.0083206 120.208   <2e-16 ***
## hsi.l1    0.0006271  0.0018168   0.345    0.730    
## const    -1.2353304 34.6854912  -0.036    0.972    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 106.7 on 226 degrees of freedom
## Multiple R-Squared: 0.989,   Adjusted R-squared: 0.9889 
## F-statistic: 1.018e+04 on 2 and 226 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation hsi: 
## ==================================== 
## hsi = sp500.l1 + hsi.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1 -4.025e-03  1.022e-01  -0.039   0.9686    
## hsi.l1    9.528e-01  2.232e-02  42.679   <2e-16 ***
## const     1.075e+03  4.262e+02   2.521   0.0124 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1311 on 226 degrees of freedom
## Multiple R-Squared: 0.9187,  Adjusted R-squared: 0.918 
## F-statistic:  1278 on 2 and 226 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##       sp500     hsi
## sp500 11379   62418
## hsi   62418 1717994
## 
## Correlation matrix of residuals:
##        sp500    hsi
## sp500 1.0000 0.4464
## hsi   0.4464 1.0000
serial.test(q8var1, lags.pt=10, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object q8var1
## Chi-squared = 74.36, df = 36, p-value = 0.0001767
q8fore <- forecast(q8var1)

autoplot(q8fore,color='red')+
  theme_bw()+
  labs(x='Date',title='HSI and S&P500 VAR Forecast')

q8irf <- irf(q8var1, impulse.variable = 1, response.variable = 2,  t = NULL, nhor = 20, scenario = 2, draw.plot = TRUE)

q8irf
## 
## Impulse response coefficients
## $sp500
##          sp500      hsi
##  [1,] 106.6706 585.1501
##  [2,] 107.0585 557.0750
##  [3,] 107.4289 530.3247
##  [4,] 107.7825 504.8368
##  [5,] 108.1203 480.5517
##  [6,] 108.4428 457.4126
##  [7,] 108.7509 435.3654
##  [8,] 109.0453 414.3586
##  [9,] 109.3265 394.3431
## [10,] 109.5953 375.2721
## [11,] 109.8521 357.1010
## 
## $hsi
##           sp500       hsi
##  [1,] 0.0000000 1172.8571
##  [2,] 0.7355119 1117.4447
##  [3,] 1.4364184 1064.6474
##  [4,] 2.1043526 1014.3416
##  [5,] 2.7408705  966.4099
##  [6,] 3.3474548  920.7402
##  [7,] 3.9255181  877.2258
##  [8,] 4.4764064  835.7649
##  [9,] 5.0014022  796.2606
## [10,] 5.5017274  758.6207
## [11,] 5.9785463  722.7570
## 
## 
## Lower Band, CI= 0.95 
## $sp500
##          sp500       hsi
##  [1,] 92.89031 406.77292
##  [2,] 92.12394 364.03098
##  [3,] 91.34103 324.31801
##  [4,] 89.41860 289.91000
##  [5,] 85.46231 258.46919
##  [6,] 82.23606 217.66047
##  [7,] 78.69942 175.16423
##  [8,] 75.28345 140.73877
##  [9,] 72.04074 108.34626
## [10,] 68.96900  76.27547
## [11,] 66.05677  42.57278
## 
## $hsi
##            sp500       hsi
##  [1,]   0.000000 1006.2140
##  [2,]  -3.948155  891.3505
##  [3,]  -7.451760  808.5091
##  [4,] -10.557468  729.3172
##  [5,] -13.304990  641.3936
##  [6,] -15.730504  546.5949
##  [7,] -17.866506  468.6671
##  [8,] -19.780602  408.0196
##  [9,] -21.495445  355.1580
## [10,] -22.959719  309.0521
## [11,] -24.248420  269.0140
## 
## 
## Upper Band, CI= 0.95 
## $sp500
##          sp500      hsi
##  [1,] 121.4450 755.7184
##  [2,] 121.3326 713.0292
##  [3,] 121.6013 672.0646
##  [4,] 121.8085 629.8078
##  [5,] 121.3764 599.7017
##  [6,] 121.4718 568.9401
##  [7,] 122.6888 549.7225
##  [8,] 123.4472 532.7077
##  [9,] 124.1428 518.0021
## [10,] 124.7790 505.4093
## [11,] 125.3588 491.3933
## 
## $hsi
##           sp500       hsi
##  [1,]  0.000000 1355.1015
##  [2,]  4.876778 1230.6609
##  [3,]  9.307043 1153.2169
##  [4,] 13.324943 1092.3192
##  [5,] 16.974321 1042.1166
##  [6,] 20.282280  994.0624
##  [7,] 23.357748  950.0936
##  [8,] 26.353819  912.4781
##  [9,] 29.127336  875.1275
## [10,] 31.689587  841.3840
## [11,] 34.051336  808.9051
plot(q8irf)

  1. Write a bi-variate VAR model using all market indices and estimate the model. Graph the impulse response functions showing the effects of one standard deviation shock to S&P 500 on other indices.
q9 <- df[,] %>% ts(start=c(2004,2),frequency = 12)
VARselect(q9, lag.max=8,type="const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      1      1      2
q9var1 <- VAR(q9,p=1,type='const')
summary(q9var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sp500, ftse, dji, bvsp, hsi, tnx 
## Deterministic variables: const 
## Sample size: 229 
## Log Likelihood: -8590.422 
## Roots of the characteristic polynomial:
## 0.9798 0.9798 0.9556 0.9556 0.8887 0.8887
## Call:
## VAR(y = q9, p = 1, type = "const")
## 
## 
## Estimation results for equation sp500: 
## ====================================== 
## sp500 = sp500.l1 + ftse.l1 + dji.l1 + bvsp.l1 + hsi.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1  9.161e-01  7.361e-02  12.445   <2e-16 ***
## ftse.l1  -2.624e-02  1.751e-02  -1.498   0.1356    
## dji.l1    1.355e-02  1.037e-02   1.306   0.1928    
## bvsp.l1  -5.168e-04  6.636e-04  -0.779   0.4370    
## hsi.l1    1.417e-03  3.136e-03   0.452   0.6519    
## tnx.l1   -1.164e+01  8.241e+00  -1.412   0.1593    
## const     1.418e+02  6.546e+01   2.166   0.0314 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 105.9 on 222 degrees of freedom
## Multiple R-Squared: 0.9894,  Adjusted R-squared: 0.9891 
## F-statistic:  3441 on 6 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation ftse: 
## ===================================== 
## ftse = sp500.l1 + ftse.l1 + dji.l1 + bvsp.l1 + hsi.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1  -0.029389   0.156844  -0.187  0.85154    
## ftse.l1    0.941825   0.037319  25.237  < 2e-16 ***
## dji.l1     0.011982   0.022093   0.542  0.58812    
## bvsp.l1   -0.001438   0.001414  -1.017  0.31016    
## hsi.l1    -0.002399   0.006682  -0.359  0.71991    
## tnx.l1   -15.940464  17.559983  -0.908  0.36498    
## const    413.095142 139.482367   2.962  0.00339 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 225.7 on 222 degrees of freedom
## Multiple R-Squared: 0.9432,  Adjusted R-squared: 0.9417 
## F-statistic: 614.9 on 6 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation dji: 
## ==================================== 
## dji = sp500.l1 + ftse.l1 + dji.l1 + bvsp.l1 + hsi.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1  -0.125629   0.608943  -0.206    0.837    
## ftse.l1   -0.100152   0.144890  -0.691    0.490    
## dji.l1     1.023399   0.085777  11.931   <2e-16 ***
## bvsp.l1   -0.001942   0.005489  -0.354    0.724    
## hsi.l1     0.002830   0.025944   0.109    0.913    
## tnx.l1   -93.108255  68.176226  -1.366    0.173    
## const    889.243431 541.537058   1.642    0.102    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 876.4 on 222 degrees of freedom
## Multiple R-Squared: 0.9881,  Adjusted R-squared: 0.9878 
## F-statistic:  3072 on 6 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation bvsp: 
## ===================================== 
## bvsp = sp500.l1 + ftse.l1 + dji.l1 + bvsp.l1 + hsi.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1   -3.47977    3.17932  -1.095   0.2749    
## ftse.l1    -1.23513    0.75648  -1.633   0.1039    
## dji.l1      0.71505    0.44785   1.597   0.1118    
## bvsp.l1     0.92369    0.02866  32.229   <2e-16 ***
## hsi.l1      0.08565    0.13546   0.632   0.5278    
## tnx.l1   -227.91190  355.95142  -0.640   0.5226    
## const    6131.21375 2827.39156   2.169   0.0312 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 4576 on 222 degrees of freedom
## Multiple R-Squared: 0.9705,  Adjusted R-squared: 0.9697 
## F-statistic:  1218 on 6 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation hsi: 
## ==================================== 
## hsi = sp500.l1 + ftse.l1 + dji.l1 + bvsp.l1 + hsi.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1 -2.142e+00  9.011e-01  -2.377   0.0183 *  
## ftse.l1   2.067e-01  2.144e-01   0.964   0.3361    
## dji.l1    2.597e-01  1.269e-01   2.046   0.0420 *  
## bvsp.l1   2.461e-03  8.123e-03   0.303   0.7622    
## hsi.l1    8.816e-01  3.839e-02  22.963   <2e-16 ***
## tnx.l1   -1.647e+02  1.009e+02  -1.633   0.1039    
## const     1.412e+03  8.013e+02   1.762   0.0795 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1297 on 222 degrees of freedom
## Multiple R-Squared: 0.9219,  Adjusted R-squared: 0.9198 
## F-statistic: 436.6 on 6 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation tnx: 
## ==================================== 
## tnx = sp500.l1 + ftse.l1 + dji.l1 + bvsp.l1 + hsi.l1 + tnx.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## sp500.l1  4.798e-04  1.671e-04   2.872  0.00448 ** 
## ftse.l1   6.313e-05  3.975e-05   1.588  0.11371    
## dji.l1   -6.616e-05  2.353e-05  -2.811  0.00538 ** 
## bvsp.l1   5.801e-07  1.506e-06   0.385  0.70046    
## hsi.l1   -7.999e-06  7.118e-06  -1.124  0.26233    
## tnx.l1    9.610e-01  1.870e-02  51.375  < 2e-16 ***
## const     5.012e-02  1.486e-01   0.337  0.73619    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.2404 on 222 degrees of freedom
## Multiple R-Squared: 0.9554,  Adjusted R-squared: 0.9542 
## F-statistic: 792.4 on 6 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##           sp500      ftse       dji      bvsp       hsi       tnx
## sp500 1.122e+04  15135.64 8.789e+04 2.475e+05 6.153e+04   0.66986
## ftse  1.514e+04  50952.19 1.310e+05 5.504e+05 1.734e+05  10.15755
## dji   8.789e+04 131042.16 7.680e+05 2.163e+06 5.104e+05  21.68695
## bvsp  2.475e+05 550370.71 2.163e+06 2.094e+07 2.839e+06 213.46260
## hsi   6.153e+04 173424.97 5.104e+05 2.839e+06 1.682e+06  36.25017
## tnx   6.699e-01     10.16 2.169e+01 2.135e+02 3.625e+01   0.05781
## 
## Correlation matrix of residuals:
##        sp500   ftse    dji   bvsp    hsi    tnx
## sp500 1.0000 0.6329 0.9467 0.5107 0.4478 0.0263
## ftse  0.6329 1.0000 0.6624 0.5329 0.5924 0.1872
## dji   0.9467 0.6624 1.0000 0.5394 0.4491 0.1029
## bvsp  0.5107 0.5329 0.5394 1.0000 0.4785 0.1940
## hsi   0.4478 0.5924 0.4491 0.4785 1.0000 0.1163
## tnx   0.0263 0.1872 0.1029 0.1940 0.1163 1.0000
serial.test(q9var1, lags.pt=10, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object q9var1
## Chi-squared = 497.44, df = 324, p-value = 1.803e-09
q9fore <- forecast(q9var1)

autoplot(q9fore,color='red')+
  theme_bw()+
  labs(x='Date',title='VAR Forecast')

q9irf <- irf(q9var1, impulse.variable = 1, response.variable = 2,  t = NULL, nhor = 20, scenario = 2, draw.plot = TRUE)

q9irf
## 
## Impulse response coefficients
## $sp500
##           sp500      ftse      dji     bvsp      hsi         tnx
##  [1,] 105.93978 142.87022 829.6474 2336.624 580.7686 0.006323012
##  [2,] 104.08642 136.53173 817.9586 2254.752 534.7661 0.007745091
##  [3,] 102.35704 130.68184 806.7603 2180.783 493.3995 0.008916103
##  [4,] 100.74048 125.27587 796.0208 2113.885 456.1433 0.009871226
##  [5,]  99.22653 120.27359 785.7100 2053.306 422.5332 0.010641916
##  [6,]  97.80584 115.63874 775.7999 1998.370 392.1583 0.011256216
##  [7,]  96.46986 111.33863 766.2642 1948.466 364.6554 0.011739058
##  [8,]  95.21079 107.34374 757.0780 1903.046 339.7033 0.012112530
##  [9,]  94.02146 103.62741 748.2180 1861.617 317.0183 0.012396139
## [10,]  92.89533 100.16556 739.6622 1823.735 296.3494 0.012607043
## [11,]  91.82642  96.93639 731.3898 1789.002 277.4748 0.012760275
## 
## $ftse
##            sp500      ftse        dji       bvsp      hsi        tnx
##  [1,]   0.000000 174.75782  71.586181 1239.06774 517.5759 0.05295433
##  [2,]  -4.138568 161.58109  49.886320 1012.11616 505.3216 0.05376161
##  [3,]  -7.787749 149.37547  29.849285  816.40906 494.3325 0.05312193
##  [4,] -10.989054 138.06509  11.432862  648.28698 484.3585 0.05128587
##  [5,] -13.780473 127.58110  -5.410271  504.49912 475.1907 0.04847221
##  [6,] -16.196810 117.86088 -20.731520  382.15843 466.6563 0.04487150
##  [7,] -18.269970 108.84739 -34.585475  278.70159 458.6123 0.04064935
##  [8,] -20.029234 100.48857 -47.029125  191.85337 450.9415 0.03594924
##  [9,] -21.501491  92.73686 -58.121174  119.59482 443.5487 0.03089510
## [10,] -22.711457  85.54870 -67.921445   60.13501 436.3569 0.02559361
## [11,] -23.681868  78.88411 -76.490363   11.88582 429.3046 0.02013618
## 
## $dji
##           sp500      ftse      dji      bvsp       hsi          tnx
##  [1,]  0.000000  0.000000 273.1206  496.9534 -30.93781  0.046317564
##  [2,]  2.860088  1.893837 274.1460  641.1211  37.23575  0.026975476
##  [3,]  5.691700  3.543150 276.3601  772.9764  95.40967  0.009350743
##  [4,]  8.491952  4.991570 279.6547  893.4621 144.77400 -0.006658581
##  [5,] 11.257973  6.276388 283.9258 1003.4530 186.38401 -0.021150894
##  [6,] 13.986935  7.429344 289.0741 1103.7594 221.17528 -0.034220834
##  [7,] 16.676079  8.477324 295.0051 1195.1313 249.97701 -0.045959145
##  [8,] 19.322732  9.442976 301.6290 1278.2618 273.52392 -0.056452596
##  [9,] 21.924332 10.345259 308.8609 1353.7910 292.46683 -0.065783961
## [10,] 24.478434 11.199922 316.6205 1422.3097 307.38206 -0.074032027
## [11,] 26.982730 12.019931 324.8323 1484.3623 318.77976 -0.081271643
## 
## $bvsp
##           sp500       ftse        dji     bvsp       hsi         tnx
##  [1,]  0.000000   0.000000   0.000000 3700.548 231.38191 0.029740572
##  [2,] -1.930584  -6.351303  -9.302223 3431.204 208.18873 0.028875548
##  [3,] -3.542229 -11.931039 -17.405398 3188.535 187.62832 0.027361770
##  [4,] -4.868190 -16.813440 -24.382770 2969.674 169.34919 0.025341383
##  [5,] -5.938647 -21.065616 -30.306342 2772.063 153.04782 0.022936334
##  [6,] -6.780992 -24.748290 -35.246541 2593.425 138.46235 0.020250803
##  [7,] -7.420086 -27.916446 -39.271931 2431.729 125.36698 0.017373358
##  [8,] -7.878494 -30.619908 -42.448994 2285.165 113.56715 0.014378876
##  [9,] -8.176690 -32.903861 -44.841945 2152.119 102.89529 0.011330241
## [10,] -8.333256 -34.809308 -46.512605 2031.153  93.20722 0.008279862
## [11,] -8.365044 -36.373482 -47.520292 1920.988  84.37889 0.005271008
## 
## $hsi
##          sp500       ftse       dji      bvsp       hsi           tnx
##  [1,] 0.000000   0.000000  0.000000   0.00000 1010.9899 -0.0002753636
##  [2,] 1.435576  -2.421164  2.886469  86.65198  891.3179 -0.0083514830
##  [3,] 2.733037  -4.417849  6.147614 158.34160  784.5350 -0.0147598359
##  [4,] 3.904486  -6.042189  9.677293 217.15869  689.2842 -0.0197415676
##  [5,] 4.960750  -7.340822 13.385137 264.91870  604.3499 -0.0235068030
##  [6,] 5.911528  -8.355414 17.194568 303.19762  528.6431 -0.0262384586
##  [7,] 6.765535  -9.123153 21.041061 333.36259  461.1885 -0.0280955953
##  [8,] 7.530620  -9.677179 24.870604 356.59858  401.1128 -0.0292163672
##  [9,] 8.213869 -10.046992 28.638346 373.93184  347.6341 -0.0297206156
## [10,] 8.821697 -10.258809 32.307402 386.25036  300.0524 -0.0297121485
## [11,] 9.359926 -10.335897 35.847804 394.32175  257.7412 -0.0292807440
## 
## $tnx
##            sp500       ftse        dji       bvsp        hsi       tnx
##  [1,]   0.000000   0.000000    0.00000    0.00000    0.00000 0.2279005
##  [2,]  -2.652468  -3.632839  -21.21941  -51.94123  -37.54200 0.2190039
##  [3,]  -5.197404  -6.924056  -41.41528 -102.56264  -69.88054 0.2106267
##  [4,]  -7.638278  -9.907081  -60.64756 -151.70190  -97.60802 0.2027132
##  [5,]  -9.978482 -12.611941  -78.97066 -199.23661 -121.25217 0.1952148
##  [6,] -12.221317 -15.065606  -96.43403 -245.07788 -141.28299 0.1880894
##  [7,] -14.369989 -17.292299 -113.08272 -289.16478 -158.11902 0.1813002
##  [8,] -16.427609 -19.313775 -128.95791 -331.45964 -172.13284 0.1748151
##  [9,] -18.397186 -21.149578 -144.09729 -371.94402 -183.65609 0.1686062
## [10,] -20.281630 -22.817260 -158.53550 -410.61527 -192.98385 0.1626490
## [11,] -22.083751 -24.332592 -172.30440 -447.48362 -200.37865 0.1569224
## 
## 
## Lower Band, CI= 0.95 
## $sp500
##          sp500      ftse      dji      bvsp          hsi         tnx
##  [1,] 87.67180 105.64198 686.0356 1251.9335  333.2026607 -0.02976849
##  [2,] 84.65657  94.32346 639.5962 1199.1924  276.8532546 -0.03007894
##  [3,] 80.07412  86.40567 600.4351 1082.0904  236.1338955 -0.03175331
##  [4,] 75.28874  74.78711 547.3156  973.8835  177.6128020 -0.03225624
##  [5,] 68.95142  65.46827 491.5602  889.9030  107.5109460 -0.03406852
##  [6,] 63.18020  56.68092 444.5086  850.9414   49.2339478 -0.03457948
##  [7,] 58.07716  48.84237 410.6664  816.4226    0.6297687 -0.03277463
##  [8,] 53.55643  41.69330 379.9431  785.2380  -40.0416628 -0.03485847
##  [9,] 49.67954  35.71793 351.8715  704.1735  -74.1888593 -0.03760500
## [10,] 46.80171  31.09442 326.0167  623.7618 -102.9531587 -0.04022502
## [11,] 44.27302  27.28015 306.2387  565.7693 -123.6969272 -0.04232599
## 
## $ftse
##           sp500       ftse        dji        bvsp       hsi           tnx
##  [1,]   0.00000 150.644697   21.64159   621.58589 350.66848  0.0182813626
##  [2,] -11.20649 125.306059  -24.23746   320.92333 320.61449  0.0266761060
##  [3,] -20.64604 100.722771  -98.26229    24.00224 268.76063  0.0216863929
##  [4,] -28.84036  77.963711 -151.46345  -237.87090 207.59362  0.0101872814
##  [5,] -36.21444  58.729783 -195.24535  -459.80948 158.28889  0.0002537744
##  [6,] -42.44968  42.722374 -231.84773  -595.35187 121.86392 -0.0112019729
##  [7,] -46.96749  29.416801 -264.70541  -709.70660 103.02499 -0.0227357324
##  [8,] -50.89463  18.299094 -298.86763  -792.43383  71.78615 -0.0335189082
##  [9,] -55.06818   7.599071 -328.99834  -875.37347  51.53981 -0.0408121122
## [10,] -58.64871  -1.463944 -355.36600  -971.61259  40.03140 -0.0478119534
## [11,] -61.68229  -7.289060 -378.23414 -1048.37657  32.25971 -0.0551742828
## 
## $dji
##            sp500      ftse        dji         bvsp        hsi         tnx
##  [1,]   0.000000   0.00000 209.076660 -122.4822324 -190.48762  0.01799766
##  [2,]  -4.855642 -15.35153 154.087529   -0.9496938 -125.33442 -0.01569596
##  [3,]  -8.516714 -27.10758 105.671356   43.8932063  -91.88812 -0.03966044
##  [4,] -11.155434 -35.54330  66.192426  -10.6292663  -53.39123 -0.05933611
##  [5,] -12.841336 -41.01861  31.642641  -64.6050234  -56.61622 -0.07742430
##  [6,] -13.744752 -43.97659   6.055385  -68.5292022  -39.06965 -0.09355937
##  [7,] -13.989539 -44.86775 -12.049654  -42.7866663  -23.46237 -0.10494319
##  [8,] -13.680165 -44.11640 -23.949027    4.3871388  -22.23522 -0.11464937
##  [9,] -12.908303 -42.10313 -30.739474  107.6133026  -21.46526 -0.12207481
## [10,] -11.754306 -40.19242 -33.422987  221.4832800  -21.06200 -0.12757322
## [11,] -11.547529 -38.11630 -32.766876  279.6991279  -20.96703 -0.13122034
## 
## $bvsp
##            sp500      ftse        dji      bvsp        hsi           tnx
##  [1,]   0.000000   0.00000    0.00000 3006.0319   87.44999  0.0008255821
##  [2,]  -6.139792 -16.57176  -43.28404 2625.6217   40.75040 -0.0052158932
##  [3,] -11.438883 -28.27866  -76.90476 2278.0058  -25.82050 -0.0207498270
##  [4,] -16.031866 -36.02776 -104.44734 1955.0826  -73.10441 -0.0346483210
##  [5,] -19.411020 -43.28577 -126.24200 1631.4859 -105.45361 -0.0458968011
##  [6,] -21.724616 -50.13202 -145.95558 1357.7656 -130.94397 -0.0519318310
##  [7,] -23.836671 -55.72630 -164.11999 1088.5714 -151.48915 -0.0545535975
##  [8,] -25.615449 -60.21151 -179.49905  891.1746 -166.12900 -0.0569140559
##  [9,] -27.219238 -62.71661 -194.29254  718.4362 -175.71426 -0.0626666259
## [10,] -29.342766 -63.70600 -209.95064  544.5980 -181.73775 -0.0699788407
## [11,] -31.244311 -64.05893 -224.04536  421.8984 -189.20839 -0.0780948774
## 
## $hsi
##            sp500      ftse        dji      bvsp       hsi         tnx
##  [1,]   0.000000   0.00000    0.00000    0.0000 837.34163 -0.02961213
##  [2,]  -7.264443 -18.93141  -68.56619 -209.5260 674.11909 -0.04383044
##  [3,] -12.524131 -33.50787 -113.67718 -344.6241 506.90813 -0.05580803
##  [4,] -16.189541 -44.45403 -145.05706 -423.8774 355.75323 -0.06589676
##  [5,] -18.753572 -52.35488 -168.22735 -486.2266 238.97778 -0.07630683
##  [6,] -20.622533 -57.72762 -187.32222 -527.4898 155.45722 -0.08728362
##  [7,] -21.429503 -59.87447 -200.71794 -575.1395  79.41640 -0.09361654
##  [8,] -21.838922 -60.86421 -209.01606 -610.8735  25.07763 -0.09538740
##  [9,] -21.973050 -61.97440 -212.44890 -637.3400 -13.12655 -0.09536783
## [10,] -21.916752 -62.24722 -211.99210 -657.0662 -42.77202 -0.09472278
## [11,] -21.729880 -61.57116 -212.24450 -660.8228 -77.18601 -0.09645192
## 
## $tnx
##           sp500      ftse        dji       bvsp       hsi        tnx
##  [1,]   0.00000   0.00000    0.00000     0.0000    0.0000 0.19416860
##  [2,] -10.24176 -16.82601  -89.58682  -341.5191 -113.7900 0.18189941
##  [3,] -18.58195 -30.08263 -163.11684  -592.8652 -199.5260 0.16594326
##  [4,] -26.16732 -40.82105 -224.43977  -780.0936 -262.9469 0.14730594
##  [5,] -33.68966 -49.68201 -283.15968  -960.3194 -312.3256 0.13185333
##  [6,] -40.17912 -57.45079 -336.60779 -1097.6967 -351.8164 0.11941682
##  [7,] -45.46118 -62.63409 -384.23320 -1176.9920 -383.1918 0.10889765
##  [8,] -50.14997 -66.81902 -423.21132 -1267.4880 -405.7145 0.09986120
##  [9,] -54.60663 -71.65989 -457.92083 -1345.4348 -424.9675 0.09198432
## [10,] -59.11739 -75.75507 -489.03615 -1352.9922 -438.5061 0.08413648
## [11,] -63.28548 -79.19915 -517.10747 -1378.6468 -448.3196 0.07672959
## 
## 
## Upper Band, CI= 0.95 
## $sp500
##          sp500     ftse      dji     bvsp      hsi        tnx
##  [1,] 119.6597 172.6755 950.9377 3384.915 778.8430 0.04477837
##  [2,] 113.3780 154.3565 914.7410 3166.184 701.8810 0.04499446
##  [3,] 110.2472 142.5439 888.6201 3013.147 643.8135 0.04412766
##  [4,] 108.5778 135.9250 871.3634 2890.730 593.1874 0.04656846
##  [5,] 107.5361 129.8102 862.1892 2789.596 554.9868 0.05172351
##  [6,] 106.5043 123.8501 851.6781 2741.828 526.1834 0.05506807
##  [7,] 105.5028 118.1527 841.6447 2721.342 496.5713 0.06087521
##  [8,] 104.8535 113.5311 834.6530 2662.190 469.8179 0.06592114
##  [9,] 104.2277 109.7099 827.6371 2596.401 448.6633 0.07026264
## [10,] 103.6673 107.1597 820.6470 2530.055 428.4261 0.07395631
## [11,] 103.1391 104.0225 813.7158 2468.128 408.6183 0.07705751
## 
## $ftse
##          sp500      ftse       dji     bvsp      hsi        tnx
##  [1,] 0.000000 192.45716 120.73556 1878.170 638.5888 0.08228283
##  [2,] 1.027686 173.76879  99.49177 1571.382 638.3527 0.08318912
##  [3,] 1.782284 157.88573 102.51185 1466.413 649.7811 0.08191914
##  [4,] 1.463685 149.80842  99.85379 1306.137 656.0481 0.08129638
##  [5,] 1.333453 139.82417 100.27234 1168.670 647.0255 0.07847607
##  [6,] 1.024221 131.28990  97.03973 1105.569 631.8196 0.07524108
##  [7,] 1.430829 123.14246 100.93837 1089.683 624.9321 0.07216659
##  [8,] 1.837527 115.41190 106.24479 1074.484 626.4180 0.07000426
##  [9,] 2.327127 108.11437 111.50082 1059.765 621.5624 0.06806073
## [10,] 2.968588 101.41890 116.78681 1045.411 616.9993 0.06616314
## [11,] 3.740237  96.19659 123.83758 1031.369 617.6860 0.06405521
## 
## $dji
##           sp500     ftse      dji     bvsp      hsi          tnx
##  [1,]  0.000000  0.00000 312.2080 1171.889 196.9285  0.069195898
##  [2,]  9.342699 15.09875 330.1115 1310.633 262.1508  0.048455129
##  [3,] 17.184416 26.56466 363.1327 1447.247 355.0215  0.035212636
##  [4,] 23.703731 35.33218 394.6647 1630.952 441.3061  0.024662211
##  [5,] 29.481197 42.31133 414.8126 1794.397 496.1968  0.014313616
##  [6,] 34.323026 46.65686 428.0566 1917.924 529.9665  0.007331119
##  [7,] 38.752516 49.35030 441.3063 2102.507 547.9911  0.002222698
##  [8,] 42.125456 50.92546 462.0419 2244.079 554.8507 -0.001662238
##  [9,] 45.927024 51.67076 471.8063 2354.734 553.4188 -0.003617977
## [10,] 50.526274 51.81423 481.9598 2446.228 551.9142 -0.004905251
## [11,] 54.686255 51.55907 499.2104 2521.281 554.6342 -0.006549749
## 
## $bvsp
##           sp500      ftse       dji     bvsp      hsi        tnx
##  [1,]  0.000000  0.000000   0.00000 4185.715 375.1736 0.06134950
##  [2,]  5.144479  8.982425  52.06230 3770.612 335.8491 0.05998792
##  [3,]  9.397079 15.264771  94.57603 3477.562 360.7801 0.05885006
##  [4,] 12.984473 19.646906 129.32680 3268.982 359.5562 0.06302035
##  [5,] 15.998684 22.608441 158.24310 3088.970 357.6332 0.06630883
##  [6,] 18.441661 24.488441 182.75431 2946.032 354.3004 0.06862535
##  [7,] 20.351245 25.539880 204.32137 2827.779 342.5685 0.06826260
##  [8,] 22.511062 26.668727 223.36565 2718.260 334.8997 0.06658588
##  [9,] 24.682095 27.376960 241.63143 2632.723 329.0051 0.06518962
## [10,] 26.910232 27.733423 260.63906 2556.432 324.3251 0.06461031
## [11,] 29.259053 27.830766 277.78046 2486.717 319.3537 0.06566614
## 
## $hsi
##           sp500      ftse       dji      bvsp       hsi        tnx
##  [1,]  0.000000  0.000000   0.00000    0.0000 1097.0850 0.03150080
##  [2,]  8.358342  7.772935  64.42824  311.8290  944.3498 0.02444410
##  [3,] 15.095141 13.809914 116.82078  545.6761  841.0200 0.02162538
##  [4,] 21.059418 18.341758 159.47912  745.5842  773.6054 0.02100084
##  [5,] 26.164894 21.591951 194.53453  889.2416  695.7292 0.02451468
##  [6,] 30.532026 24.353195 227.46910  972.2291  623.0315 0.02997827
##  [7,] 33.888894 26.171850 256.76201 1042.6697  569.9917 0.03218251
##  [8,] 36.391406 26.482212 282.30930 1099.7014  515.3543 0.03337670
##  [9,] 39.433443 26.243715 304.60530 1134.6940  464.3783 0.03508578
## [10,] 42.126006 25.670551 324.06697 1156.9852  425.1174 0.03654166
## [11,] 44.397454 25.814348 340.72243 1167.4267  389.9914 0.03819547
## 
## $tnx
##           sp500     ftse       dji     bvsp       hsi       tnx
##  [1,] 0.0000000  0.00000  0.000000   0.0000  0.000000 0.2484856
##  [2,] 1.3331076  4.04493  5.091220 111.6228 -1.930731 0.2373161
##  [3,] 2.2623472  7.35084  7.598049 177.9423 -5.956234 0.2268524
##  [4,] 2.8781254 10.02740  8.431823 211.3077 -7.584207 0.2168197
##  [5,] 2.6858765 12.16577 10.278922 225.4307 -8.425700 0.2110014
##  [6,] 2.0557893 13.84230 11.739242 237.3949 -6.536527 0.2034759
##  [7,] 1.1846028 15.12149 12.847018 243.2798 -4.083612 0.1957063
##  [8,] 0.4455795 15.64742 15.072230 261.7184 -3.694883 0.1878344
##  [9,] 0.1922414 15.65785 18.539219 278.0198  1.274616 0.1815783
## [10,] 0.4663877 16.20961 21.406126 285.1721  6.613124 0.1764238
## [11,] 0.7496845 16.52239 23.653635 259.0520 11.405612 0.1713822
plot(q9irf)