Problem 1

a)

library(MTS)
C=matrix(c(0.8,-0.3,0.4,0.6), nrow = 2)
S=matrix(c(2,0.5,0.5,1.0), nrow = 2)
m1 = VARMAsim(300, arlags = c(1), phi = C, sigma = S)
yt = m1$series
plot(yt)

b)

ccm(yt, lags = 5)
## [1] "Covariance matrix:"
##         [,1]    [,2]
## [1,]  5.8253 -0.0456
## [2,] -0.0456  2.7397
## CCM at lag:  0 
##         [,1]    [,2]
## [1,]  1.0000 -0.0114
## [2,] -0.0114  1.0000
## Simplified matrix: 
## CCM at lag:  1 
## + + 
## - + 
## CCM at lag:  2 
## + + 
## - + 
## CCM at lag:  3 
## + + 
## - + 
## CCM at lag:  4 
## . + 
## - . 
## CCM at lag:  5 
## - + 
## - -

## Hit Enter for p-value plot of individual ccm:

c)

mq(yt, lag=10)
## Ljung-Box Statistics:  
##         m       Q(m)     df    p-value
##  [1,]     1       381       4        0
##  [2,]     2       652       8        0
##  [3,]     3       856      12        0
##  [4,]     4      1005      16        0
##  [5,]     5      1114      20        0
##  [6,]     6      1188      24        0
##  [7,]     7      1248      28        0
##  [8,]     8      1292      32        0
##  [9,]     9      1328      36        0
## [10,]    10      1357      40        0

We can see all p-value is 0, so we can reject \(H_0\) of no cross-correlations with 5% significance level.

d)

m2 = VARMAsim(200,malags = c(1),theta = C,sigma = S);
zt = m2$series
ccm(zt, lags = 2)
## [1] "Covariance matrix:"
##       [,1]  [,2]
## [1,] 4.430 0.233
## [2,] 0.233 1.332
## CCM at lag:  0 
##        [,1]   [,2]
## [1,] 1.0000 0.0961
## [2,] 0.0961 1.0000
## Simplified matrix: 
## CCM at lag:  1 
## - . 
## . - 
## CCM at lag:  2 
## + . 
## . .

## Hit Enter for p-value plot of individual ccm:

mq(zt, lag=10)
## Ljung-Box Statistics:  
##         m       Q(m)     df    p-value
##  [1,]     1       109       4        0
##  [2,]     2       120       8        0
##  [3,]     3       126      12        0
##  [4,]     4       132      16        0
##  [5,]     5       133      20        0
##  [6,]     6       136      24        0
##  [7,]     7       137      28        0
##  [8,]     8       139      32        0
##  [9,]     9       143      36        0
## [10,]    10       152      40        0

Problem 2

The file q-fdebt.txt contains the U.S. quarterly federal debts held by (a)foreign and international investors, (b) federal reserve banks, and (c) the public.The data are from the Federal Reserve Bank of St. Louis, from 1970 to 2012 for 171 observations, and not seasonally adjusted. The debts are in billions of dollars. Take the log transformation and the first difference for each time series. Let zt be the differenced log series.

a) Plot the time series \(z_t\).

library(MTS)
da=read.table("q-fdebt.txt",header=T)
debt=log(da[,3:5])
tdx=da[,1]+da[,2]/12
#MTSplot(debt,tdx);
zt=diffM(debt);
MTSplot(zt,tdx[-1])

b) Obtain the first five lags of sample CCMs of \(z_t\).

ccm(zt, lags = 5)
## [1] "Covariance matrix:"
##            hbfin    hbfrbn    hbpun
## hbfin   0.002745 -0.000175 0.000350
## hbfrbn -0.000175  0.002709 0.000104
## hbpun   0.000350  0.000104 0.000488
## CCM at lag:  0 
##         [,1]    [,2]   [,3]
## [1,]  1.0000 -0.0642 0.3027
## [2,] -0.0642  1.0000 0.0906
## [3,]  0.3027  0.0906 1.0000
## Simplified matrix: 
## CCM at lag:  1 
## + . . 
## . + . 
## + . + 
## CCM at lag:  2 
## + . . 
## . . + 
## . . + 
## CCM at lag:  3 
## + . . 
## . . + 
## . . + 
## CCM at lag:  4 
## + . . 
## . . . 
## . . + 
## CCM at lag:  5 
## . . . 
## . - . 
## . . +

## Hit Enter for p-value plot of individual ccm:

c) Use a VAR model to fit the data \(z_t\), with an appropriate order selection. Justify your order choice. Interpret the fitted model.

VARorder(zt)
## selected order: aic =  6 
## selected order: bic =  1 
## selected order: hq =  5 
## Summary table:  
##        p      AIC      BIC       HQ    M(p) p-value
##  [1,]  0 -20.2022 -20.2022 -20.2022  0.0000  0.0000
##  [2,]  1 -20.6589 -20.4929 -20.5915 85.7893  0.0000
##  [3,]  2 -20.6950 -20.3630 -20.5603 21.2235  0.0117
##  [4,]  3 -20.7588 -20.2607 -20.5567 24.8554  0.0031
##  [5,]  4 -21.0911 -20.4271 -20.8216 62.8856  0.0000
##  [6,]  5 -21.2401 -20.4100 -20.9033 35.8101  0.0000
##  [7,]  6 -21.2942 -20.2981 -20.8900 21.9979  0.0089
##  [8,]  7 -21.2443 -20.0822 -20.7727  7.5246  0.5827
##  [9,]  8 -21.2225 -19.8944 -20.6836 11.0615  0.2715
## [10,]  9 -21.2600 -19.7659 -20.6537 18.4248  0.0306
## [11,] 10 -21.1983 -19.5382 -20.5246  5.5442  0.7845
## [12,] 11 -21.2105 -19.3844 -20.4695 14.4641  0.1067
## [13,] 12 -21.2087 -19.2166 -20.4003 12.4426  0.1895
## [14,] 13 -21.2025 -19.0443 -20.3267 11.6032  0.2366
v=VAR(zt,p=6)
## Constant term: 
## Estimates:  0.0128167 -0.002779114 0.006766811 
## Std.Error:  0.005855736 0.00658421 0.002145951 
## AR coefficient matrix 
## AR( 1 )-matrix 
##        [,1]    [,2]   [,3]
## [1,] 0.1108 -0.0809 0.2687
## [2,] 0.0518  0.4170 0.0199
## [3,] 0.0251 -0.0849 0.3841
## standard error 
##        [,1]   [,2]   [,3]
## [1,] 0.0863 0.0709 0.2459
## [2,] 0.0970 0.0797 0.2765
## [3,] 0.0316 0.0260 0.0901
## AR( 2 )-matrix 
##           [,1]    [,2]    [,3]
## [1,]  0.119139  0.0637 -0.3936
## [2,]  0.056577  0.0576  0.2447
## [3,] -0.000517 -0.0512  0.0929
## standard error 
##        [,1]   [,2]   [,3]
## [1,] 0.0835 0.0790 0.2477
## [2,] 0.0939 0.0888 0.2785
## [3,] 0.0306 0.0289 0.0908
## AR( 3 )-matrix 
##         [,1]    [,2]   [,3]
## [1,] 0.04859 -0.0830 0.0328
## [2,] 0.03783 -0.0854 0.5337
## [3,] 0.00947  0.0431 0.0409
## standard error 
##        [,1]   [,2]   [,3]
## [1,] 0.0815 0.0771 0.1913
## [2,] 0.0916 0.0867 0.2151
## [3,] 0.0299 0.0283 0.0701
## AR( 4 )-matrix 
##         [,1]    [,2]    [,3]
## [1,]  0.1351 -0.0978  0.3302
## [2,] -0.2165 -0.0268 -0.0845
## [3,] -0.0124 -0.0465  0.7027
## standard error 
##        [,1]   [,2]   [,3]
## [1,] 0.0809 0.0765 0.1945
## [2,] 0.0909 0.0860 0.2187
## [3,] 0.0296 0.0280 0.0713
## AR( 5 )-matrix 
##         [,1]    [,2]    [,3]
## [1,] -0.1806  0.0837  0.0546
## [2,] -0.0330 -0.2288 -0.1699
## [3,] -0.0825  0.0151 -0.2283
## standard error 
##        [,1]   [,2]   [,3]
## [1,] 0.0799 0.0751 0.2531
## [2,] 0.0899 0.0845 0.2846
## [3,] 0.0293 0.0275 0.0927
## AR( 6 )-matrix 
##        [,1]     [,2]    [,3]
## [1,] 0.0558 0.000863  0.1647
## [2,] 0.1469 0.321765  0.0126
## [3,] 0.0221 0.003439 -0.1248
## standard error 
##        [,1]   [,2]  [,3]
## [1,] 0.0780 0.0724 0.240
## [2,] 0.0877 0.0814 0.270
## [3,] 0.0286 0.0265 0.088
##   
## Residuals cov-mtx: 
##               [,1]          [,2]         [,3]
## [1,]  0.0013575684 -0.0002676928 0.0001986357
## [2,] -0.0002676928  0.0017163512 0.0000364333
## [3,]  0.0001986357  0.0000364333 0.0001823216
##   
## det(SSE) =  3.383589e-10 
## AIC =  -21.17162 
## BIC =  -20.17554 
## HQ  =  -20.76742

d) Is the fitted model adequate? Draw the conclusion using the 5% significance level.

resi=v$residuals
mq(resi,adj=18)
## Ljung-Box Statistics:  
##           m       Q(m)     df    p-value
##  [1,]   1.000     0.662  -9.000     1.00
##  [2,]   2.000     1.803   0.000     1.00
##  [3,]   3.000     5.426   9.000     0.80
##  [4,]   4.000     9.182  18.000     0.96
##  [5,]   5.000    13.157  27.000     0.99
##  [6,]   6.000    16.077  36.000     1.00
##  [7,]   7.000    22.219  45.000     1.00
##  [8,]   8.000    31.981  54.000     0.99
##  [9,]   9.000    36.715  63.000     1.00
## [10,]  10.000    40.591  72.000     1.00
## [11,]  11.000    53.223  81.000     0.99
## [12,]  12.000    62.088  90.000     0.99
## [13,]  13.000    73.361  99.000     0.97
## [14,]  14.000    77.671 108.000     0.99
## [15,]  15.000    82.331 117.000     0.99
## [16,]  16.000    97.883 126.000     0.97
## [17,]  17.000   105.248 135.000     0.97
## [18,]  18.000   110.913 144.000     0.98
## [19,]  19.000   115.581 153.000     0.99
## [20,]  20.000   121.451 162.000     0.99
## [21,]  21.000   129.525 171.000     0.99
## [22,]  22.000   131.996 180.000     1.00
## [23,]  23.000   137.719 189.000     1.00
## [24,]  24.000   141.346 198.000     1.00