Title: | Dynamic Multiple Quantile (DMQ) Model |
---|---|
Description: | Perform estimation, prediction, and simulations using the Dynamic Multiple Quantile model of Catania and Luati (2023) <doi:10.1016/j.jeconom.2022.11.002>. Can be used to estimate a set of conditional time-varying quantiles of a time series that do not cross. |
Authors: | Leopoldo Catania [cre, aut] , Alessandra Luati [ctb] |
Maintainer: | Leopoldo Catania <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2 |
Built: | 2024-12-21 06:43:52 UTC |
Source: | CRAN |
The DMQ package allows us to simulate, estimate and forecast using the Dynamic Multiple Quantile (DMQ) model of Catania, L., & Luati, A. (2022). Semiparametric modeling of multiple quantiles. Journal of Econometrics, see doi:10.1016/j.jeconom.2022.11.002.
Please cite Catania and Luati (2022) in working papers and published papers that use DMQ
. Use citation("DMQ")
.
Leopoldo Catania [aut,cre], Alessandra Luati [aut]
Maintainer: Leopoldo Catania <[email protected]>
Catania, L, and Luati, A. (2023).
"Semiparametric modeling of multiple quantiles."
Journal of Econometrics
doi:10.1016/j.jeconom.2022.11.002.
Estimate the parameters of the DMQ model using the estimator detailed in Catania and Luati (2023).
EstimateDMQ(vY, vTau, iTau_star = NULL, vPn_Starting = NULL, FixReference = FALSE, FixOthers = FALSE, ScalingType = "InvSqrt", vQ_0 = NULL, fn.optimizer = fn.DEoptim, cluster = NULL, smooth = NULL, ...)
EstimateDMQ(vY, vTau, iTau_star = NULL, vPn_Starting = NULL, FixReference = FALSE, FixOthers = FALSE, ScalingType = "InvSqrt", vQ_0 = NULL, fn.optimizer = fn.DEoptim, cluster = NULL, smooth = NULL, ...)
vY |
|
vTau |
|
iTau_star |
Integer indicating the position in |
vPn_Starting |
|
FixReference |
|
FixOthers |
|
ScalingType |
|
vQ_0 |
|
fn.optimizer |
|
cluster |
A |
smooth |
|
... |
Additional arguments to be passed to |
Starting values for the optimizer are by default set as c("phi" = 0.94, "gamma" = 0.10, "alpha" = 0.05, "beta" = 0.95)
.
The user is free to employ his/her own optimization routine via the fn.optimizer
argument. fn.optimizer
accepts a function
object. The user provided optimizer has to satisfy strict requirements. The arguments of the fn.optimizer
are:
par0
a vector of starting values,
vY
the data provided,
FUN
the objective function,
LB
vector of lower bounds for the parameters,
UB
vector of upper bounds for the parameters.
...
additional arguments.
The output of fn.optimizer
has to be an object of the class list
with four named elements:
pars
a numeric
vector where the estimated parameters are stored,
value
a numeric
containing the value of the objective function evaluated at its minimum,
hessian
a numeric
matrix containing the Hessian matrix evaluated at
the minimum of the objective function, this is used for inferential purposes,
convergence
a numeric
variable reporting information about the convergence of the optimization. convergence = 0
has to indicate successful completion.
The user is allowed to not include the last two elements of the output of the fn.optimizer
function, that is, the values hessian = NULL
and convergence = NULL
are admissible. In the case of hessian = NULL
, no standard errors will be computed.
A list
with, among others, elements:
lFilter |
A |
vPn |
|
optimizer |
A |
Inference |
A |
Leopoldo Catania
Catania, L, and Luati, A. (2023). "Semiparametric modeling of multiple quantiles." Journal of Econometrics doi:10.1016/j.jeconom.2022.11.002.
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Deciles vTau = seq(0.1, 0.9, 0.1) # Reference quantile to the median iTau_star = 5 # Fix the reference quantile to a constant FixReference = TRUE # Estimate DMQ Fit_solnp = EstimateDMQ(vY = vY, vTau = vTau, iTau_star = iTau_star, FixReference = FixReference, fn.optimizer = fn.solnp, cluster = cluster) Fit_solnp$vPn Fit_solnp$optimizer$value ## Not run: #### Estimate DMQ using different optimizers # With the DEoptim optimizer # parallel computation iG = 7 cluster = makeCluster(iG) set.seed(123) # Estimate DMQ Fit_DEoptim = EstimateDMQ(vY = vY, vTau = vTau, iTau_star = iTau_star, FixReference = FixReference, fn.optimizer = fn.DEoptim, cluster = cluster) Fit_DEoptim$vPn Fit_DEoptim$optimizer$value # Estimate the model with a user defined optimizer. # Let's use the gosolnp() optimizer from the Rsolnp package. library("Rsolnp") fn.gosolnp <- function(par0, vY, FUN, LB, UB, ...) { foo = list(...) if (!is.null(foo$cluster)) { cluster = foo$cluster clusterEvalQ(cluster, library(DMQ)) } optimiser = gosolnp( pars = par0, fun = FUN, vY = vY, n.sim = 1000, n.restarts = 5, LB = LB, UB = UB, control = list(trace = 1), ...) out = list(pars = optimiser$pars, value = tail(optimiser$values, 1), hessian = optimiser$hessian, convergence = optimiser$convergence) return(out) } set.seed(123) # Estimate DMQ Fit_gosolnp = EstimateDMQ(vY = vY, vTau = vTau, iTau_star = iTau_star, FixReference = FixReference, fn.optimizer = fn.gosolnp, cluster = cluster, smooth = TRUE) Fit_gosolnp$vPn Fit_gosolnp$optimizer$value stopCluster(cluster) ## End(Not run)
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Deciles vTau = seq(0.1, 0.9, 0.1) # Reference quantile to the median iTau_star = 5 # Fix the reference quantile to a constant FixReference = TRUE # Estimate DMQ Fit_solnp = EstimateDMQ(vY = vY, vTau = vTau, iTau_star = iTau_star, FixReference = FixReference, fn.optimizer = fn.solnp, cluster = cluster) Fit_solnp$vPn Fit_solnp$optimizer$value ## Not run: #### Estimate DMQ using different optimizers # With the DEoptim optimizer # parallel computation iG = 7 cluster = makeCluster(iG) set.seed(123) # Estimate DMQ Fit_DEoptim = EstimateDMQ(vY = vY, vTau = vTau, iTau_star = iTau_star, FixReference = FixReference, fn.optimizer = fn.DEoptim, cluster = cluster) Fit_DEoptim$vPn Fit_DEoptim$optimizer$value # Estimate the model with a user defined optimizer. # Let's use the gosolnp() optimizer from the Rsolnp package. library("Rsolnp") fn.gosolnp <- function(par0, vY, FUN, LB, UB, ...) { foo = list(...) if (!is.null(foo$cluster)) { cluster = foo$cluster clusterEvalQ(cluster, library(DMQ)) } optimiser = gosolnp( pars = par0, fun = FUN, vY = vY, n.sim = 1000, n.restarts = 5, LB = LB, UB = UB, control = list(trace = 1), ...) out = list(pars = optimiser$pars, value = tail(optimiser$values, 1), hessian = optimiser$hessian, convergence = optimiser$convergence) return(out) } set.seed(123) # Estimate DMQ Fit_gosolnp = EstimateDMQ(vY = vY, vTau = vTau, iTau_star = iTau_star, FixReference = FixReference, fn.optimizer = fn.gosolnp, cluster = cluster, smooth = TRUE) Fit_gosolnp$vPn Fit_gosolnp$optimizer$value stopCluster(cluster) ## End(Not run)
DEoptim
package of Mullen et al. (2011).
This function is a wrapper to the DEoptim function of the DEoptim
package of Mullen et al. (2011).
fn.DEoptim(par0, vY, FUN, LB, UB, ...)
fn.DEoptim(par0, vY, FUN, LB, UB, ...)
par0 |
|
vY |
|
FUN |
A function to optimize. |
LB |
A vector of lower bounds for the parameters. |
UB |
A vector of upper bounds for the parameters. |
... |
Additional arguments to provide to DEoptim. |
The following control parameters are used: trace = 0
, rho = 1
, outer.iter = 400
,
inner.iter = 1800
, delta = 1e-08
, tol = 1e-08
. See the documentation of DEoptim.
It returns a named list with four elements: i) pars
: a numeric
vector where the estimated parameters are stored, ii) value
: a numeric
containing the value of the objective function evaluated at its minumum, iii) hessian
, a numeric
matrix containing the Hessian matrix evaluated at the minimum of the objective function, and iv) convergence
a numeric
element indicating the convergence (convergence is always reached by DEoptim, i.e. convergence = 1
).
Leopoldo Catania
Katharine Mullen, David Ardia, David Gil, Donald Windover, James Cline (2011).
'DEoptim': An R Package for Global Optimization by Differential Evolution. Journal of
Statistical Software, 40(6), 1-26. doi:10.18637/jss.v040.i06.
Ardia, D., Boudt, K., Carl, P., Mullen, K.M., Peterson, B.G. (2010). Differential Evolution with 'DEoptim': An Application to Non-Convex Portfolio Optimization. R Journal, 3(1), 27-34. doi:10.32614/RJ-2011-005.
help(DEoptim)
This function is a wrapper to the standard optim optimizer with method = "BFGS"
.
fn.optim(par0, vY, FUN, LB, UB, ...)
fn.optim(par0, vY, FUN, LB, UB, ...)
par0 |
|
vY |
|
FUN |
A function to optimize. |
LB |
A vector of lower bounds for the parameters. |
UB |
A vector of upper bounds for the parameters. |
... |
Additional arguments to provide to optim. |
The following control parameters are used for control
:
trace = 0
abstol = 1e-8
See the documentation of optim.
It returns a named list with four elements: i) pars
: a numeric
vector where the estimated parameters are stored, ii) value
: a numeric
containing the value of the objective function evaluated at its minumum, iii) hessian
, a numeric
matrix containing the Hessian matrix evaluated at the minimum of objective function, iv) convergence
a numeric
element indicating the convergence results of optim.
Leopoldo Catania
help(optim)
Rsolnp
package of Ghalanos and Theussl (2016).
This function is a wrapper to the solnp function of the Rsolnp
package of Ghalanos and Theussl (2016).
fn.solnp(par0, vY, FUN, LB, UB, ...)
fn.solnp(par0, vY, FUN, LB, UB, ...)
par0 |
|
vY |
|
FUN |
A function to optimize. |
LB |
A vector of lower bounds for the parameters. |
UB |
A vector of upper bounds for the parameters. |
... |
Additional arguments to provide to solnp. |
The following control parameters are used: trace = 0
, rho = 1
, outer.iter = 400
,
inner.iter = 1800
, delta = 1e-08
, tol = 1e-08
. See the documentation of solnp.
It returns a named list with four elements: i) pars
: a numeric
vector where the estimated parameters are stored, ii) value
: a numeric
containing the value of the objective function evaluated at its minumum, iii) hessian
, a numeric
matrix containing the Hessian matrix evaluated at the minimum of the objective function, and iv) convergence
a numeric
element indicating the convergence results of solnp.
Leopoldo Catania
Alexios Ghalanos and Stefan Theussl (2015).
"Rsolnp: General Non-linear Optimization Using Augmented Lagrange
Multiplier Method". R package version 1.16.
help(solnp)
Compute the H-steap ahead prediction of the quantile processes.
ForecastDMQ(Fit, H)
ForecastDMQ(Fit, H)
Fit |
The output of the function EstimateDMQ. |
H |
|
A numeric
matrix of dimension HxJ, where J is the number of quantiles.
Leopoldo Catania
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Estimate DMQ at tau_j = 0.05, 0.10, ..., 0.95 # with fixed median as reference quantile. Fit = EstimateDMQ(vY = vY, vTau = seq(0.05, 0.95, 0.05), iTau_star = 10, FixReference = TRUE, fn.optimizer = fn.solnp) # Compute 20-step ahead predictions mQ_pred = ForecastDMQ(Fit, H = 20) mQ_pred
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Estimate DMQ at tau_j = 0.05, 0.10, ..., 0.95 # with fixed median as reference quantile. Fit = EstimateDMQ(vY = vY, vTau = seq(0.05, 0.95, 0.05), iTau_star = 10, FixReference = TRUE, fn.optimizer = fn.solnp) # Compute 20-step ahead predictions mQ_pred = ForecastDMQ(Fit, H = 20) mQ_pred
Compute DMQ implied conditional moments. At each point in time moments are computed using the discretized distribution implied by the estimated conditional quantiles.
MomentsDMQ(Fit)
MomentsDMQ(Fit)
Fit |
The output of the function EstimateDMQ or UpdateDMQ. |
Moments are computed using the following approximation:
with , where
are estimated quantiles.
A list
of four elements:
mMoments |
a Tx4 |
mCenterdMoments |
a Tx4 |
vSkew |
a |
vKurt |
a |
Leopoldo Catania
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Estimate DMQ on the in sample period Fit = EstimateDMQ(vY = vY, vTau = seq(0.01, 0.99, 0.01), iTau_star = 50, FixReference = TRUE, fn.optimizer = fn.solnp) # Compute estimated moments Moments = MomentsDMQ(Fit)
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Estimate DMQ on the in sample period Fit = EstimateDMQ(vY = vY, vTau = seq(0.01, 0.99, 0.01), iTau_star = 50, FixReference = TRUE, fn.optimizer = fn.solnp) # Compute estimated moments Moments = MomentsDMQ(Fit)
This dataset is the one used in Catania and Luati (2023).
Dow Jones 30 Constituents closing value log returns from 1987-03-16 to 2009-02-03 from Yahoo Finance. Note that AIG was replaced by KFT (Kraft Foods) on September 22, 2008. This is not reflected in this data set as that would bring the starting date of the data to 2001.
data("MSFT")
data("MSFT")
An xts
object of 2000 logarithmic percentage returns.
Yahoo Finance
Catania, L, and Luati, A. (2023). "Semiparametric modeling of multiple quantiles." Journal of Econometrics doi:10.1016/j.jeconom.2022.11.002.
Approximate simulation from the DMQ model. Allows to simulate quantiles and observations.
SimulateDMQ(iT, vQ_0, vTau, iTau_star, vPn, ScalingType = "InvSqrt", fSim = NULL)
SimulateDMQ(iT, vQ_0, vTau, iTau_star, vPn, ScalingType = "InvSqrt", fSim = NULL)
iT |
Number of observations to simulate. |
vQ_0 |
|
vTau |
|
iTau_star |
Integer indicating the position in |
vPn |
|
ScalingType |
|
fSim |
|
Given a set of simulated quantiles a Uniform variable drawn. The discretized quantile function is linearly interpoled at the simulated Uniform draw to obtain an observations. When the Uniform draw is outside the range spanned by vTau
a Gaussian quantile function is used. The mean and variance of the Gaussian quantile distribution are set to those implied by the simulated quantiles using the same scheme of MomentsDMQ.
A list
with two elements:
vY |
A |
mQ |
A |
Leopoldo Catania
set.seed(123) # Simulate 500 observations from the DMQ model. # Use the percentiles vTau = seq(0.01, 0.99, 0.01) # Median as reference quantile iTau_star = 50 # Standard Gaussian limiting distribution vQ_0 = qnorm(vTau) # vector of parameters vPn = c("phi" = 0.95, "gamma" = 0.10, "alpha" = 0.01, "beta" = 0.7) lSim = SimulateDMQ(iT = 500, vQ_0, vTau, iTau_star, vPn) plot.ts(lSim$vY) plot.ts(lSim$mQ, plot.type = "single")
set.seed(123) # Simulate 500 observations from the DMQ model. # Use the percentiles vTau = seq(0.01, 0.99, 0.01) # Median as reference quantile iTau_star = 50 # Standard Gaussian limiting distribution vQ_0 = qnorm(vTau) # vector of parameters vPn = c("phi" = 0.95, "gamma" = 0.10, "alpha" = 0.01, "beta" = 0.7) lSim = SimulateDMQ(iT = 500, vQ_0, vTau, iTau_star, vPn) plot.ts(lSim$vY) plot.ts(lSim$mQ, plot.type = "single")
Filter dynamic quantiles using an estimated model and an updated dataset.
UpdateDMQ(Fit, vY)
UpdateDMQ(Fit, vY)
Fit |
The output of the function EstimateDMQ. |
vY |
|
The function can be used to compute a sequence of one-step-ahead rolling predictions, without updating the parameters of the model, see Examples.
An output like the one of EstimateDMQ with updated quantile estimated.
Leopoldo Catania
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") # Divide the sample in two equal parts vY_is = vY[1:1000] ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Estimate DMQ over the deciles on the in sample period Fit = EstimateDMQ(vY = vY_is, vTau = seq(0.1, 0.9, 0.1), iTau_star = 5, FixReference = TRUE, fn.optimizer = fn.solnp) # compute a sequence of one-step-ahead rolling predictions over the out of sample Roll = UpdateDMQ(Fit, vY) # one steap ahead predictions from time t = 1001 to 2001 are mForecast = t(Roll$lFilter$mQ)[1001:2001, ]
# Load Microsoft Corporation logarithmic percentage returns from December 8, # 2010 to November 15, 2018 for a total of T = 2000 observation data("MSFT") # Divide the sample in two equal parts vY_is = vY[1:1000] ############################################################## ######################## Estimate DMQ ######################## ############################################################## # Estimate DMQ over the deciles on the in sample period Fit = EstimateDMQ(vY = vY_is, vTau = seq(0.1, 0.9, 0.1), iTau_star = 5, FixReference = TRUE, fn.optimizer = fn.solnp) # compute a sequence of one-step-ahead rolling predictions over the out of sample Roll = UpdateDMQ(Fit, vY) # one steap ahead predictions from time t = 1001 to 2001 are mForecast = t(Roll$lFilter$mQ)[1001:2001, ]