I am trying to follow the example given in Section 3.2 of this paper on the use of the gmm
R
package. So I wish to estimate the parameters of a stable distribution. I am using the following code
library(gmm)
library(stabledist)
library(StableEstim)
g1 <- function(theta, x){
tau <- seq(1, 5, length.out = 10)
pm <- 1
x <- matrix(c(x), ncol = 1)
x_comp <- x%*%matrix(tau, nrow = 1)
x_comp <- matrix(complex(imaginary = x_comp), ncol = length(tau))
emp_car <- exp(x_comp)
the_car <- charStable(theta, tau, pm)
gt <- t(t(emp_car) - the_car)
gt <- cbind(Im(gt), Re(gt))
return(gt)
}
x1 <- returns$log.return[2:6966]
t0 <- McCullochParametersEstim(x1)
res1 <- gmm(g1, x1, t0, optfct = "nlminb",
lower = c(0, -1, 0, -Inf),
upper = c(2, 1, Inf, Inf))
summary(res1)
Note that the McCullochParametersEstim()
is a quantiles based method of parameter estimation used here to calculate starting values. When I run this code I receive the following error
Error in AA %*% t(X) : requires numeric/complex matrix/vector arguments
In addition: Warning message:
In ar.ols(x, aic = aic, order.max = order.max, na.action = na.action, :
model order: 1 singularities in the computation of the projection
matrix results are only valid up to model order 0
My data can be found here. In the data set I have prices, log prices, logarithmic returns, and non-logarithmic returns. When I run the code on data in the price
and return
columns, e.g. x1 <- returns.return[2:6966]
, there is no issue. The error message appears when I run the code using data from the log
or log.return
column. I am not sure if the logarithmic transform alters the data class in some way to lead to the error. Any help is appreciated.
The error does not come from gmm() itself, but from ar.ols() which is used to prewhite the moment matrix before computing the HAC covariance matrix. The error disappears if we set the prewhite option to 0 (see vcovHAC from the sandwich package for more info). For example, the following does not produce the error:
However, the error message hides a numerical problem while trying to minimize the objective function. First, NA's are produced when the first coefficient is equal to 2 or if the third one is equal to 0, and nlminb seems to reach the boundaries at least for the first coefficients which results in a singular covariance matrix.
A little work needs to be done to tune optim or nlminb correctly. Notice that the process can be speed up in that particular case, because the model is a minimum distance (MDE), which implies that the weighting matrix does not depend on the coefficients as long as we are willing to center them, which is recommended. The model can then be estimated using a one step GMM with fixed weighting matrix. There are two options
The moments are weakly dependent, so an HAC matrix is required. Following your code, you can proceed as follows:
If you're fine with the martingale difference sequence assumption, you can proceed this way instead:
You are left with the problem of tuning optim or nlminb. The function does not look too well behaved as the standard errors of the coefficients looks pretty high.