Skip to content

Commit a9517f7

Browse files
committed
Fix documentation for CRAN
1 parent 5b21bb2 commit a9517f7

15 files changed

Lines changed: 267 additions & 216 deletions

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
Package: timevarcorr
22
Title: Time Varying Correlation
3-
Version: 0.1.0
3+
Version: 0.1.1
44
Authors@R:
55
c(person("Alexandre", "Courtiol", email = "alexandre.courtiol@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0003-0637-2959")),
66
person("François", "Rousset", role = "aut", comment = c(ORCID = "0000-0003-4670-0371")))
77
Description:
88
Computes how the correlation between 2 time-series changes over time.
9-
To do so, the package performs a non-parametric kernel smoothing (using a common bandwidth) of all underlying components required for the computation of a correlation coefficient (i.e., x, y, x^2, y^2, xy).
9+
To do so, the package follows the method from Choi & Shin (2021) <doi:10.1007/s42952-020-00073-6>.
10+
It performs a non-parametric kernel smoothing (using a common bandwidth) of all underlying components required for the computation of a correlation coefficient (i.e., x, y, x^2, y^2, xy).
1011
An automatic selection procedure for the bandwidth parameter is implemented.
1112
Alternative kernels can be used (Epanechnikov, box and normal).
1213
Both Pearson and Spearman correlation coefficients can be estimated and change in correlation over time can be tested.

NEWS.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
# timevarcorr 0.1.1
2+
3+
New submission to CRAN after revisions.
4+
5+
* Add Choi & Shin (2021) in DESCRIPTION.
6+
* Improve documentation (returns more detailed and use of LaTeX).
7+
18
# timevarcorr 0.1.0
29

3-
* Initial CRAN submission.
10+
Initial CRAN submission (rejected).
411

512
# timevarcorr 0.0.0.9006 and earlier
613

7-
* Prepare package for CRAN release.
14+
Prepare package for CRAN release.

R/CI.R

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' Internal functions for the computation of confidence intervals
22
#'
3-
#' These functions compute the different terms required to compute the confidence
4-
#' interval around the time-varying correlation coefficient.
3+
#' These functions compute the different terms required for [`tcor()`] to compute the confidence
4+
#' interval around the time-varying correlation coefficient. These terms are defined in Choi & Shin (2021).
55
#'
6-
#' @seealso [`tcor`]
6+
#' @seealso [`tcor()`]
77
#' @name CI
88
#'
99
#' @references
@@ -13,6 +13,15 @@
1313
#' Andrews, D. W. K. Heteroskedasticity and autocorrelation consistent covariance matrix estimation.
1414
#' Econometrica: Journal of the Econometric Society, 817-858 (1991).
1515
#'
16+
#' @return
17+
#' - `calc_H()` returns a 5 x 5 x \eqn{t} array of elements of class numeric, which corresponds to \eqn{\hat{H_t}} in Choi & Shin (2021).
18+
#' - `calc_e()` returns a \eqn{t} x 5 matrix of elements of class numeric storing the residuals, which corresponds to \eqn{\hat{e}_t} in Choi & Shin (2021).
19+
#' - `calc_Gamma()` returns a 5 x 5 matrix of elements of class numeric, which corresponds to \eqn{\hat{\Gamma}_l} in Choi & Shin (2021).
20+
#' - `calc_GammaINF()` returns a 5 x 5 matrix of elements of class numeric, which corresponds to \eqn{\hat{\Gamma}^\infty} in Choi & Shin (2021).
21+
#' - `calc_L_And()` returns a scalar of class numeric, which corresponds to \eqn{L_{And}} in Choi & Shin (2021).
22+
#' - `calc_D()` returns a \eqn{t} x 5 matrix of elements of class numeric storing the residuals, which corresponds to \eqn{D_t} in Choi & Shin (2021).
23+
#' - `calc_SE()` returns a vector of length \eqn{t} of elements of class numeric, which corresponds to \eqn{se(\hat{\rho}_t(h))} in Choi & Shin (2021).
24+
#'
1625
#' @examples
1726
#' rho_obj <- with(na.omit(stockprice),
1827
#' calc_rho(x = SP500, y = FTSE100, t = DateID, h = 20, kernel = "box"))
@@ -21,18 +30,16 @@
2130
NULL
2231

2332

24-
#' @describeIn CI Internal function computing the `$\hat{H_t}$` array.
33+
#' @describeIn CI computes the \eqn{\hat{H_t}} array.
2534
#'
26-
#' `$\hat{H_t}$` is a component needed to compute confidence intervals;
27-
#' `$H_t$` is defined in eq. 6 from Choi & Shin, 2021.
28-
#' The function returns a 5 x 5 x `t` array.
35+
#' \eqn{\hat{H_t}} is a component needed to compute confidence intervals;
36+
#' \eqn{H_t} is defined in eq. 6 from Choi & Shin (2021).
2937
#'
3038
#' @export
3139
#' @param smoothed_obj an object created with [`calc_rho`].
3240
#'
3341
#' @examples
34-
#'
35-
#' ## Computing `$\hat{H_t}$`
42+
#' ## Computing \eqn{\hat{H_t}}
3643
#'
3744
#' H <- calc_H(smoothed_obj = rho_obj)
3845
#' H[, , 1:2] # H array for the first two time points
@@ -63,18 +70,15 @@ calc_H <- function(smoothed_obj) {
6370
}
6471

6572

66-
#' @describeIn CI Internal function computing `$\hat{e}_t$`.
73+
#' @describeIn CI computes \eqn{\hat{e}_t}.
6774
#'
68-
#' `$\hat{e}_t$` is a component needed to compute confidence intervals;
69-
#' it is defined in eq. 9 from Choi & Shin, 2021.
70-
#' The function returns a `t` x 5 matrix storing the residuals.
75+
#' \eqn{\hat{e}_t} is defined in eq. 9 from Choi & Shin (2021).
7176
#'
7277
#' @export
73-
#' @param H an object created with [`calc_H`].
78+
#' @param H an object created with `calc_H`.
7479
#'
7580
#' @examples
76-
#'
77-
#' ## Computing `$\hat{e}_t$`
81+
#' ## Computing \eqn{\hat{e}_t}
7882
#'
7983
#' e <- calc_e(smoothed_obj = rho_obj, H = H)
8084
#' head(e) # e matrix for the first six time points
@@ -91,19 +95,16 @@ calc_e <- function(smoothed_obj, H) {
9195
}
9296

9397

94-
#' @describeIn CI Internal function computing `$\hat{\Gamma}_l$`.
98+
#' @describeIn CI computes \eqn{\hat{\Gamma}_l}.
9599
#'
96-
#' `$\hat{\Gamma}_l$` is a component needed to compute confidence intervals;
97-
#' it is defined in eq. 9 from Choi & Shin, 2021.
98-
#' The function returns a 5 x 5 matrix.
100+
#' \eqn{\hat{\Gamma}_l} is defined in eq. 9 from Choi & Shin (2021).
99101
#'
100102
#' @export
101-
#' @param e an object created with [`calc_e`].
103+
#' @param e an object created with `calc_e`.
102104
#' @param l a scalar indicating a number of time points.
103105
#'
104106
#' @examples
105-
#'
106-
#' ## Computing `$\hat{\Gamma}_l$`
107+
#' ## Computing \eqn{\hat{\Gamma}_l}
107108
#'
108109
#' calc_Gamma(e = e, l = 3)
109110
#'
@@ -116,18 +117,15 @@ calc_Gamma <- function(e, l) {
116117
}
117118

118119

119-
#' @describeIn CI Internal function computing `$\hat{\Gamma}^\Inf$`.
120+
#' @describeIn CI computes \eqn{\hat{\Gamma}^\infty}.
120121
#'
121-
#' `$\hat{\Gamma}^\Inf$` is a component needed to compute confidence intervals (the long run variance estimator);
122-
#' it is defined in eq. 9 from Choi & Shin, 2021.
123-
#' The function returns a 5 x 5 matrix.
122+
#' \eqn{\hat{\Gamma}^\infty} is the long run variance estimator, defined in eq. 9 from Choi & Shin (2021).
124123
#'
125124
#' @export
126125
#' @param L a scalar indicating a bandwidth parameter.
127126
#'
128127
#' @examples
129-
#'
130-
#' ## Computing `$\hat{\Gamma}^\Inf$`
128+
#' ## Computing \eqn{\hat{\Gamma}^\infty}
131129
#'
132130
#' calc_GammaINF(e = e, L = 2)
133131
#'
@@ -145,19 +143,16 @@ calc_GammaINF <- function(e, L) {
145143
}
146144

147145

148-
#' @describeIn CI Internal function computing `$L_{And}$`.
146+
#' @describeIn CI computes \eqn{L_{And}}.
149147
#'
150-
#' `$L_{And}$` is a component needed to compute confidence intervals;
151-
#' it is defined in Choi & Shin, 2021, p 342.
152-
#' It also corresponds to `$S_T^*$`, eq 5.3 in Andrews 1991.
153-
#' The function returns a scalar which should be used as an input for `L` in [`calc_GammaINF`].
148+
#' \eqn{L_{And}} is defined in Choi & Shin (2021, p 342).
149+
#' It also corresponds to \eqn{S_T^*}, eq 5.3 in Andrews (1991).
154150
#'
155151
#' @export
156-
#' @param 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).
152+
#' @param AR.method character string specifying the method to fit the autoregressive model used to compute \eqn{\hat{\gamma}_1} in \eqn{L_{And}} (see [`stats::ar`] for details).
157153
#'
158154
#' @examples
159-
#'
160-
#' ## Computing `$L_{And}$`
155+
#' ## Computing \eqn{L_{And}}
161156
#'
162157
#' calc_L_And(e = e)
163158
#' sapply(c("yule-walker", "burg", "ols", "mle", "yw"),
@@ -171,17 +166,14 @@ calc_L_And <- function(e, AR.method = c("yule-walker", "burg", "ols", "mle", "yw
171166
}
172167

173168

174-
#' @describeIn CI Internal function computing `$D_t$`.
169+
#' @describeIn CI computes \eqn{D_t}.
175170
#'
176-
#' `$D_t$` is a component needed to compute confidence intervals;
177-
#' it is defined in Choi & Shin, 2021, p 338.
178-
#' The function returns a `t` x 5 matrix storing the residuals.
171+
#' \eqn{D_t} is defined in Choi & Shin (2021, p 338).
179172
#'
180173
#' @export
181174
#'
182175
#' @examples
183-
#'
184-
#' ## Computing `$D_t$`
176+
#' ## Computing \eqn{D_t}
185177
#'
186178
#' D <- calc_D(smoothed_obj = rho_obj)
187179
#' head(D) # D matrix for the first six time points
@@ -197,24 +189,22 @@ calc_D <- function(smoothed_obj) {
197189
}
198190

199191

200-
#' @describeIn CI Internal function computing `$se(\hat{rho}_t(h))$`.
192+
#' @describeIn CI computes \eqn{se(\hat{\rho}_t(h))}.
201193
#'
202-
#' The standard deviation of the time-varying correlation (`$se(\hat{rho}_t(h))$`) is defined in eq. 8 from Choi & Shin, 2021.
203-
#' It depends on `$D_{Lt}$`, `$D_{Mt}$` & `$D_{Ut}$`, themselves defined in Choi & Shin, 2021, p 337 & 339.
204-
#' The `$D_{Xt}$` terms are all computed within the function since they all rely on the same components.
205-
#' The function returns a vector of length `t`.
194+
#' The standard deviation of the time-varying correlation (\eqn{se(\hat{\rho}_t(h))}) is defined in eq. 8 from Choi & Shin (2021).
195+
#' It depends on \eqn{D_{Lt}}, \eqn{D_{Mt}} & \eqn{D_{Ut}}, themselves defined in Choi & Shin (2021, p 337 & 339).
196+
#' The \eqn{D_{Xt}} terms are all computed within the function since they all rely on the same components.
206197
#'
207198
#' @export
208199
#' @inheritParams kern_smooth
209200
#'
210201
#' @examples
202+
#' ## Computing \eqn{se(\hat{\rho}_t(h))}
203+
#' # nb: takes a few seconds to run
211204
#'
212205
#' run <- FALSE ## change to TRUE to run the example
213206
#' if (in_pkgdown() || run) {
214207
#'
215-
#' ## Computing `$se(\hat{rho}_t(h))$`
216-
#' # nb: takes a few seconds to run
217-
#'
218208
#' SE <- calc_SE(smoothed_obj = rho_obj, h = 50)
219209
#' head(SE) # SE vector for the first six time points
220210
#'

R/data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Daily Closing Prices of Major European Stock Indices, April 2000--December 2017
22
#'
33
#' A dataset containing the stockmarket returns between 2000-04-03 and 2017-12-05.
4-
#' This dataset is very close to the one used by Choi & Shin 2021, although not
4+
#' This dataset is very close to the one used by Choi & Shin (2021), although not
55
#' strictly identical. It has been produced by the Oxford-Man Institute of Quantitative Finance.
66
#'
77
#' @format A data frame with 4618 rows and 7 variables:
@@ -12,7 +12,7 @@
1212
#' \item{Nikkei}{a numeric vector of the stockmarket return for the Nikkei 225.}
1313
#' \item{DAX}{a numeric vector of the stockmarket return for the German stock index.}
1414
#' \item{NASDAQ}{a numeric vector of the stockmarket return for the Nasdaq Stock Market.}
15-
#' \item{Event}{a character string of particular events that have impacted the stockmarket, as in Choi & Shin 2021.}
15+
#' \item{Event}{a character string of particular events that have impacted the stockmarket, as in Choi & Shin (2021).}
1616
#' }
1717
#'
1818
#' @source

R/smoothers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#'
55
#' The function is essentially a wrapper that calls different underlying
66
#' functions depending on the kernel that is selected:
7-
#' - [`lpridge::lpepa`] for "epanechnikov".
8-
#' - [`stats::ksmooth`] for "normal" and "box".
7+
#' - [`lpridge::lpepa()`] for "epanechnikov".
8+
#' - [`stats::ksmooth()`] for "normal" and "box".
99
#' The argument `param_smoother` can be used to pass additional arguments to
1010
#' these functions.
1111
#'

0 commit comments

Comments
 (0)