Skip to contents

These functions compute the different terms required for tcor() to compute the confidence interval around the time-varying correlation coefficient. These terms are defined in Choi & Shin (2021).

Usage

calc_H(smoothed_obj)

calc_e(smoothed_obj, H)

calc_Gamma(e, l)

calc_GammaINF(e, L)

calc_L_And(e, AR.method = c("yule-walker", "burg", "ols", "mle", "yw"))

calc_D(smoothed_obj)

calc_SE(
  smoothed_obj,
  h,
  AR.method = c("yule-walker", "burg", "ols", "mle", "yw")
)

Arguments

smoothed_obj

an object created with calc_rho.

H

an object created with calc_H.

e

an object created with calc_e.

l

a scalar indicating a number of time points.

L

a scalar indicating a bandwidth parameter.

AR.method

character string specifying the method to fit the autoregressive model used to compute \(\hat{\gamma}_1\) in \(L_{And}\) (see stats::ar for details).

h

a scalar indicating the bandwidth used by the smoothing function.

Value

  • calc_H() returns a 5 x 5 x \(t\) array of elements of class numeric, which corresponds to \(\hat{H_t}\) in Choi & Shin (2021).

  • calc_e() returns a \(t\) x 5 matrix of elements of class numeric storing the residuals, which corresponds to \(\hat{e}_t\) in Choi & Shin (2021).

  • calc_Gamma() returns a 5 x 5 matrix of elements of class numeric, which corresponds to \(\hat{\Gamma}_l\) in Choi & Shin (2021).

  • calc_GammaINF() returns a 5 x 5 matrix of elements of class numeric, which corresponds to \(\hat{\Gamma}^\infty\) in Choi & Shin (2021).

  • calc_L_And() returns a scalar of class numeric, which corresponds to \(L_{And}\) in Choi & Shin (2021).

  • calc_D() returns a \(t\) x 5 matrix of elements of class numeric storing the residuals, which corresponds to \(D_t\) in Choi & Shin (2021).

  • calc_SE() returns a vector of length \(t\) of elements of class numeric, which corresponds to \(se(\hat{\rho}_t(h))\) in Choi & Shin (2021).

Functions

  • calc_H(): computes the \(\hat{H_t}\) array.

    \(\hat{H_t}\) is a component needed to compute confidence intervals; \(H_t\) is defined in eq. 6 from Choi & Shin (2021).

  • calc_e(): computes \(\hat{e}_t\).

    \(\hat{e}_t\) is defined in eq. 9 from Choi & Shin (2021).

  • calc_Gamma(): computes \(\hat{\Gamma}_l\).

    \(\hat{\Gamma}_l\) is defined in eq. 9 from Choi & Shin (2021).

  • calc_GammaINF(): computes \(\hat{\Gamma}^\infty\).

    \(\hat{\Gamma}^\infty\) is the long run variance estimator, defined in eq. 9 from Choi & Shin (2021).

  • calc_L_And(): computes \(L_{And}\).

    \(L_{And}\) is defined in Choi & Shin (2021, p 342). It also corresponds to \(S_T^*\), eq 5.3 in Andrews (1991).

  • calc_D(): computes \(D_t\).

    \(D_t\) is defined in Choi & Shin (2021, p 338).

  • calc_SE(): computes \(se(\hat{\rho}_t(h))\).

    The standard deviation of the time-varying correlation (\(se(\hat{\rho}_t(h))\)) is defined in eq. 8 from Choi & Shin (2021). It depends on \(D_{Lt}\), \(D_{Mt}\) & \(D_{Ut}\), themselves defined in Choi & Shin (2021, p 337 & 339). The \(D_{Xt}\) terms are all computed within the function since they all rely on the same components.

References

Choi, JE., Shin, D.W. Nonparametric estimation of time varying correlation coefficient. J. Korean Stat. Soc. 50, 333–353 (2021). doi:10.1007/s42952-020-00073-6

Andrews, D. W. K. Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica: Journal of the Econometric Society, 817-858 (1991).

See also

Examples

rho_obj <- with(na.omit(stockprice),
                calc_rho(x = SP500, y = FTSE100, t = DateID, h = 20, kernel = "box"))
head(rho_obj)
#>              x            y           x2           y2            xy          t
#> 1  0.004361280 -0.010096362 1.902076e-05 1.019365e-04 -4.403306e-05 2000-04-03
#> 2 -0.007980069 -0.003332639 6.368150e-05 1.110648e-05  2.659469e-05 2000-04-04
#> 3 -0.004479051 -0.007449493 2.006189e-05 5.549494e-05  3.336666e-05 2000-04-05
#> 4  0.008375645  0.011874107 7.015143e-05 1.409944e-04  9.945331e-05 2000-04-06
#> 5  0.009697455  0.015107515 9.404064e-05 2.282370e-04  1.465045e-04 2000-04-07
#> 6 -0.007420214 -0.004377977 5.505958e-05 1.916668e-05  3.248553e-05 2000-04-10
#>     x_smoothed   y_smoothed  x2_smoothed  y2_smoothed  xy_smoothed
#> 1 -0.002369705 -0.003425687 7.493522e-05 0.0001296218 4.822802e-05
#> 2 -0.008177062 -0.005608043 4.327807e-04 0.0001804120 1.960199e-04
#> 3 -0.008177062 -0.005608043 4.327807e-04 0.0001804120 1.960199e-04
#> 4 -0.008177062 -0.005608043 4.327807e-04 0.0001804120 1.960199e-04
#> 5 -0.004666980 -0.006882863 4.776387e-04 0.0001990454 1.238864e-04
#> 6 -0.002107705 -0.003205704 4.367050e-04 0.0001841147 1.015342e-04
#>   sd_x_smoothed sd_y_smoothed rho_smoothed
#> 1   0.008325846    0.01085755    0.4437047
#> 2   0.019128940    0.01220499    0.6431811
#> 3   0.019128940    0.01220499    0.6431811
#> 4   0.019128940    0.01220499    0.6431811
#> 5   0.021350832    0.01231550    0.3489847
#> 6   0.020790924    0.01318477    0.3457474

## Computing \eqn{\hat{H_t}}

H <- calc_H(smoothed_obj = rho_obj)
H[, , 1:2] # H array for the first two time points
#> , , 1
#> 
#>               [,1]          [,2]        [,3]        [,4]          [,5]
#> [1,] -3.945960e-05 -3.300682e-05 0.008325846 0.004817547 -3.993791e-05
#> [2,]  0.000000e+00 -6.666556e-05 0.000000000 0.009730246 -2.305781e-05
#> [3,]  6.931972e-05  2.320876e-05 0.000000000 0.000000000  4.011015e-05
#> [4,]  0.000000e+00 -9.467769e-05 0.000000000 0.000000000  0.000000e+00
#> [5,]  0.000000e+00  9.375183e-05 0.000000000 0.000000000  8.101253e-05
#> 
#> , , 2
#> 
#>               [,1]          [,2]       [,3]        [,4]          [,5]
#> [1,] -0.0003128371 -8.804651e-05 0.01912894 0.007850022 -1.714660e-04
#> [2,]  0.0000000000 -1.048203e-04 0.00000000 0.009345535 -7.641902e-05
#> [3,]  0.0003659163  6.162284e-05 0.00000000 0.000000000  1.501626e-04
#> [4,]  0.0000000000 -8.733903e-05 0.00000000 0.000000000  0.000000e+00
#> [5,]  0.0000000000  1.467253e-04 0.00000000 0.000000000  1.787702e-04
#> 

## Computing \eqn{\hat{e}_t}

e <- calc_e(smoothed_obj = rho_obj, H = H)
head(e) # e matrix for the first six time points
#>         x2_resid      y2_resid    x_resid    y_resid      xy_resid
#> [1,]  0.80844454 -1.0858300496 -0.3464174 -0.1790269 -0.8778333739
#> [2,]  0.01029819  0.2348247345 -0.9998939  0.9448573  0.0024182690
#> [3,]  0.19332027 -0.3594249430 -0.9626273  0.8708137 -0.0694841264
#> [4,]  0.86532278  1.1437918620 -0.2512165 -0.3082598  0.9897491561
#> [5,]  0.67278103  1.6548373386 -0.5473657 -1.7384866  1.1133431705
#> [6,] -0.25552057 -0.0006027114 -0.9347092  0.9999996  0.0001540051

## Computing \eqn{\hat{\Gamma}_l}

calc_Gamma(e = e, l = 3)
#>             x2_resid    y2_resid      x_resid       y_resid     xy_resid
#> x2_resid -0.08426588  0.00120430 -0.016571795 -0.0486144700 -0.028603802
#> y2_resid  0.02366280 -0.09087723 -0.036021416 -0.0104226203  0.003046219
#> x_resid   0.03505289  0.02239173 -0.130886043  0.0113781767  0.008721415
#> y_resid  -0.00935183 -0.01810924 -0.002669087 -0.1306788327 -0.026723552
#> xy_resid -0.01353423 -0.01153453 -0.009324456 -0.0003183333 -0.059677907

## Computing \eqn{\hat{\Gamma}^\infty}

calc_GammaINF(e = e, L = 2)
#>             x2_resid    y2_resid      x_resid    y_resid     xy_resid
#> x2_resid  0.89131796  0.03994933 -0.045481299 0.01885230  0.022464392
#> y2_resid  0.03994933  0.87487207 -0.016957014 0.04726965 -0.013540548
#> x_resid  -0.04548130 -0.01695701  1.574267210 0.07364551  0.003709538
#> y_resid   0.01885230  0.04726965  0.073645507 1.61624702  0.036153472
#> xy_resid  0.02246439 -0.01354055  0.003709538 0.03615347  0.819391952

## Computing \eqn{L_{And}}

calc_L_And(e = e)
#> [1] 6.097187
sapply(c("yule-walker", "burg", "ols", "mle", "yw"),
       function(m) calc_L_And(e = e, AR.method = m)) ## comparing AR.methods
#> yule-walker        burg         ols         mle          yw 
#>    6.097187    6.097427    6.097239    6.096643    6.097187 

## Computing \eqn{D_t}

D <- calc_D(smoothed_obj = rho_obj)
head(D) # D matrix for the first six time points
#>            [,1]       [,2]      [,3]      [,4]      [,5]
#> [1,] -3200.4218 -1881.9156 22.727368 13.320330 11062.153
#> [2,]  -878.8636 -2158.8784  9.647499 10.810085  4283.231
#> [3,]  -878.8636 -2158.8784  9.647499 10.810085  4283.231
#> [4,]  -878.8636 -2158.8784  9.647499 10.810085  4283.231
#> [5,]  -382.7778 -1150.4619 22.603106  1.911857  3803.059
#> [6,]  -399.9275  -994.4519 10.008519  1.313051  3647.990

## Computing \eqn{se(\hat{\rho}_t(h))}
# nb: takes a few seconds to run

run <- FALSE ## change to TRUE to run the example
if (in_pkgdown() || run) {

SE <- calc_SE(smoothed_obj = rho_obj, h = 50)
head(SE) # SE vector for the first six time points

}
#> [1] 0.09718916 0.07043209 0.06966624 0.06889940 0.10133594 0.10045678