forked from rjdverse/rjd3toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_td.R
80 lines (77 loc) · 3.12 KB
/
tests_td.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#' @include protobuf.R jd2r.R
NULL
#' Residual Trading Days Test
#'
#' @param nyears \code{integer} that corresponds to the length of the sub series, starting from the end of the series, to be used for the test:
#' in number of periods (positive value) or years (negative values).
#' By default (\code{nyears = 0}), the entire sample is used.
#' @param s a \code{ts} object that corresponds to the input time series to test.
#' @param model the model to use for the residuals. See details.
#'
#' @details
#' The function performs a residual seasonality test that is a joint F-Test on the coefficients of trading days regressors.
#' Several specifications can be used on the model:
#' \itemize{
#' \item \code{model = "WN"} the following model is used:
#' \deqn{
#' y_t - \bar y =\beta TD_t + \varepsilon_t
#' }
#' \item \code{model = "D1"} (the default) the following model is used:
#' \deqn{
#' \Delta y_t - \overline{\Delta y} =\beta \Delta TD_t + \varepsilon_t
#' }
#' \item \code{model = "DY"} the following model is used:
#' \deqn{
#' \Delta_s y_t - \overline{\Delta_s y} =\beta \Delta_s TD_t + \varepsilon_t
#' }
#' \item \code{model = "DYD1"} the following model is used:
#' \deqn{
#' \Delta_s\Delta y_t - \overline{\Delta_s \Delta y} =\beta \Delta_s \Delta TD_t + \varepsilon_t
#' }
#' \item \code{model = "AIRLINE"} the following model is used:
#' \deqn{
#' y_t =\beta TD_t + \varepsilon_t \text{ with }\varepsilon_t \sim ARIMA(0,1,1)(0,1,1)
#' }
#' \item \code{model = "R011"} the following model is used:
#' \deqn{
#' y_t =\beta TD_t + \varepsilon_t \text{ with }\varepsilon_t \sim ARIMA(0,1,1)
#' }
#' \item \code{model = "R100"} the following model is used:
#' \deqn{
#' y_t =\alpha_0 + \alpha_1 y_{t-1} + \beta TD_t + \varepsilon_t
#' }
#' }
#'
#' @examples
#' td_f(ABS$X0.2.09.10.M)
#' @export
td_f<-function(s, model=c("D1", "DY", "DYD1", "WN", "AIRLINE", "R011", "R100"), nyears=0){
model<-match.arg(model)
jts<-.r2jd_tsdata(s)
jtest<-.jcall("jdplus/toolkit/base/r/modelling/TradingDaysTests", "Ljdplus/toolkit/base/api/stats/StatisticalTest;", "fTest",
jts, model, as.integer(nyears))
return(.jd2r_test(jtest))
}
#' Canova-Hansen test for stable trading days
#'
#' @inheritParams td_f
#' @param differencing Differencing lags.
#' @param kernel Kernel used to compute the robust covariance matrix.
#' @param order The truncation parameter used to compute the robust covariance matrix.
#'
#' @return list with the ftest on td, the joint test and the details for the stability of the different days (starting with Mondays).
#' @export
#'
#' @examples
#' s<-log(ABS$X0.2.20.10.M)
#' td_canovahansen(s, c(1,12))
td_canovahansen<-function(s, differencing, kernel=c("Bartlett", "Square", "Welch", "Tukey", "Hamming", "Parzen"),
order=NA){
kernel<-match.arg(kernel)
if (is.na(order)) order<--1
jts<-.r2jd_tsdata(s)
q<-.jcall("jdplus/toolkit/base/r/modelling/TradingDaysTests", "[D", "canovaHansen",
jts, .jarray(as.integer(differencing)), kernel, as.integer(order))
last<-length(q)
return(list(td=list(value=q[last-1], pvalue=q[last]), joint=q[last-2], details=q[-c(last-2, last-1, last)]))
}