Title: | Specify Reserve Demand Curves |
---|---|
Description: | Automatic specification and estimation of reserve demand curves for central bank operations. The package can help to choose the best demand curve and identify additional explanatory variables. Various plot and predict options are included. For more details, see Chen et al. (2023) <https://www.imf.org/en/Publications/WP/Issues/2023/09/01/Modeling-the-Reserve-Demand-to-Facilitate-Central-Bank-Operations-538754>. |
Authors: | Nikolaos Kourentzes [aut, cre], Zhuohui Chen [aut], Romain Veyrune [aut] |
Maintainer: | Nikolaos Kourentzes <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2 |
Built: | 2024-11-23 03:31:43 UTC |
Source: | https://github.com/trnnick/curvir |
Fits the reserve demand curve between excess reserves and normalised rates
curve(x, y, type = "logistic", dummy = NULL, q = NULL, ...)
curve(x, y, type = "logistic", dummy = NULL, q = NULL, ...)
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
type |
The type of the reserve demand curve. This can be any of |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
q |
Target interval. This is a scalar below 1, for example 0.9 is the 90% interval. If |
... |
Additional arguments passed to optimiser |
For a description of the parametric curves, see the provided reference. Below we list their functions:
logisitc
(Logistic)
redLogistic
(Reduced logistic)
fixLogistic
(Fixed logistic)
doubleExp
(Double exponential)
exponential
(Exponential)
fixExponential
(Fixed exponential)
arctan
(Arctangent)
linear
(Linear)
And , where
,
,
,
are curve parameters,
is a constant togglable by
constant
, are the regressors including the excess reserves.
their coefficients, and finally
is the error term of the curve.
Returns a model of class curvir
. This includes
type
the type of the curve.
constant
a logical indicating the use of a constant.
w
a list including: mean
the curve parameters for the mean of the curve, upper
and lower
the parameters for the curve at the upper and lower intervals.
data
a list including the y
, x
, and dummy
used for the fitting of the curve.
mse
the MSE from the fitting of the curve (the mean only).
q
the interval used in the fitting of the curve.
An additional column for the constant is automatically generated, unless requested otherwise.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
predict.curvir
, plot.curvir
, and curveopt
.
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] curve(x,rate) # An arctangent curve curve(x,rate,type="arctan")
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] curve(x,rate) # An arctangent curve curve(x,rate,type="arctan")
Finds optimal curve parameters.
curveopt( x, y, type = "logistic", constant = c(TRUE, FALSE), reps = 3, sign = NULL, q = NULL, winit = NULL, yhat = NULL, wsel = c("select", "combine"), dummy = NULL, sameSign = c(TRUE, FALSE) )
curveopt( x, y, type = "logistic", constant = c(TRUE, FALSE), reps = 3, sign = NULL, q = NULL, winit = NULL, yhat = NULL, wsel = c("select", "combine"), dummy = NULL, sameSign = c(TRUE, FALSE) )
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
type |
The type of the reserve demand curve. This can be any of |
constant |
A logical ( |
reps |
Number of repetitions for the particle swarm optimisation. |
sign |
A vector of equal length to the number of additional regressors in |
q |
The desired quantile to optimise for. Use |
winit |
A vector of initial values for the optimisation. This will also carry over to sign restrictions if |
yhat |
Useful when estimating quantiles. Supply here the predicted values for the conditional expectation to add restrictions for the quantiles to not cross the conditional expectation. Use |
wsel |
Use the minimum error set of parameters ( |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
sameSign |
Used if |
Returns a list of
w
The optimal parameters
mse
The Mean Squared Error of the fitted curve.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
Kourentzes, N., Barrow, D., & Petropoulos, F. (2019). Another look at forecast selection and combination: Evidence from forecast pooling. International Journal of Production Economics, 209, 226-235.
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] curveopt(x,rate)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] curveopt(x,rate)
Provides the predicted values for the reserve demand curve of choice. For general use prefer the predict() function, which handles the constant internally.
curvepred(x, w, type = "logistic", dummy = NULL)
curvepred(x, w, type = "logistic", dummy = NULL)
x |
A matrix with the inputs. If there is a constant in the estimated curve, then the first column in |
w |
The vector of weights for the desired curve. Estimated using the |
type |
The type of the reserve demand curve. This can be any of |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
For a description of the parametric curves, see the provided reference. Below we list their functions:
logisitc
(Logistic)
redLogistic
(Reduced logistic)
fixLogistic
(Fixed logistic)
doubleExp
(Double exponential)
exponential
(Exponential)
fixExponential
(Fixed exponential)
arctan
(Arctangent)
linear
(Linear)
And , where
,
,
,
are curve parameters,
is a constant togglable by
constant
, are the regressors including the excess reserves.
their coefficients, and finally
is the error term of the curve.
Returns a vector of the predicted values.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
The curvir package provides tools for building reserve demand curves for central bank operations.
npcurve
- fit a non-parametric curve
cvfit
- Joint automatic specification of curve type and regressors
varselect
- Automatic specification of regressors
cvnpcurve
- Provide cross-validated errors for non-paramteric curves
ecb
ECB dataset from Chen et al. (2023)
Nikolaos Kourentzes, [email protected], Zhuohui Chen, [email protected], Romain R. Veyrune.
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
Using cross-validation automatically select explanatory variables jointly with curve type.
When running cvfit
there is no need to use varselect
separately.
cvfit( x, y, folds = 10, constant = c(TRUE, FALSE), sign = NULL, reps = 3, parallel = c(FALSE, TRUE), usepbapply = c(FALSE, TRUE), alltype = c("logistic", "redLogistic", "doubleExp", "exponential", "arctan", "linear"), search = c("backward", "forward"), wsel = c("select", "combine"), dummy = NULL )
cvfit( x, y, folds = 10, constant = c(TRUE, FALSE), sign = NULL, reps = 3, parallel = c(FALSE, TRUE), usepbapply = c(FALSE, TRUE), alltype = c("logistic", "redLogistic", "doubleExp", "exponential", "arctan", "linear"), search = c("backward", "forward"), wsel = c("select", "combine"), dummy = NULL )
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
folds |
Folds to use for cross-validation. |
constant |
A logical ( |
sign |
A vector of equal length to the number of additional regressors in |
reps |
Number of repetitions for the particle swarm optimisation. |
parallel |
Initialise and use parallel processing for the cross-validation. Note that the maximum number of cores that will be used is equal to the alternative types of curves that are evaluated ( |
usepbapply |
A logical to indicate whether to use pbapply to report on the parallel calculation progress. Note that pbapply does not support load balancing. |
alltype |
A vector of the curve types to consider in the selection process. |
search |
Search strategy for variable inclusion. With |
wsel |
Use the minimum error set of parameters ( |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
Returns a list with the recommended variable selection choice:
type
the type of selected curve.
keep
a logical vector with which variables to keep.
varRes
the result from varselect
for each evaluated curve type.
cvIndex
a matrix detailing how the sample was split for the cross-validation. First column is the fold number and second column is the index of the observation.
Use cvfitplot
to visualise the output.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
cvfitplot
, curve
, and varselect
.
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE) # Print result print(cvKeep) # Fit curve with the selected variables curve(x[,cvKeep$keep,drop=FALSE],rate,type=cvKeep$type)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE) # Print result print(cvKeep) # Fit curve with the selected variables curve(x[,cvKeep$keep,drop=FALSE],rate,type=cvKeep$type)
Plot summarised error of different curves specification from cvfit
.
Assuming normal errors, plot the mean cross-validated error and the 95
cvfitplot(cvKeep, xlock = c("mean", "median"), cvRF = NULL, cvSP = NULL)
cvfitplot(cvKeep, xlock = c("mean", "median"), cvRF = NULL, cvSP = NULL)
cvKeep |
The output of |
xlock |
Focus horizontal axis on |
cvRF |
Include cross-validation results from random forecast non-parametric curves. Obtain these from |
cvSP |
Include cross-validation results from spline regression non-parametric curves. Obtain these from |
No returned value. Produces a summary plot of cross-validated errors.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE) cvfitplot(cvKeep) # Add results from non-parameteric curves cvRF <- cvnpcurve(x,rate,cvKeep$cvIndex) cvSP <- cvnpcurve(x,rate,cvKeep$cvIndex,type="spline") cvfitplot(cvKeep,cvRF=cvRF,cvSP=cvSP)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE) cvfitplot(cvKeep) # Add results from non-parameteric curves cvRF <- cvnpcurve(x,rate,cvKeep$cvIndex) cvSP <- cvnpcurve(x,rate,cvKeep$cvIndex,type="spline") cvfitplot(cvKeep,cvRF=cvRF,cvSP=cvSP)
Obtain cross-validated errors for a non-parametric curve with given sample splits.
cvnpcurve(x, y, cvIndex, type = "rforest", dummy = NULL)
cvnpcurve(x, y, cvIndex, type = "rforest", dummy = NULL)
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
cvIndex |
A matrix detailing how the sample was split for the cross-validation. Output from |
type |
The type of the reserve demand curve. This can be any of |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
Returns summary cross-validated errors, comparable with the output from cvfit
.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE) # Get non-parametric curve cross-validated errors cvRF <- cvnpcurve(x,rate,cvKeep$cvIndex) cvSP <- cvnpcurve(x,rate,cvKeep$cvIndex,type="spline")
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE) # Get non-parametric curve cross-validated errors cvRF <- cvnpcurve(x,rate,cvKeep$cvIndex) cvSP <- cvnpcurve(x,rate,cvKeep$cvIndex,type="spline")
The short-term interest rate used for the European Central Bank (ECB) is the volume-weighted Euro Overnight Index Average (EONIA) rate. Various explanatory variables are provided, as listed in the Chen et al. (2023). Data are collected from 1999 to 2019, resulting in 239 maintenance periods where all data is available.
ecb
ecb
ecb
a list containing
rate
the normalised EONIA rate.
x
a matrix including the ECB excess reserves and various regressors.
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
plot(ecb$x[,1],ecb$rate,xlab="Excess Reserves",ylab="Rate")
plot(ecb$x[,1],ecb$rate,xlab="Excess Reserves",ylab="Rate")
Calculate the predicted reserves given some rate, i.e., calculate the prediction of the inverse curve.
invcurve( object, ynew = NULL, xnew = NULL, dummynew = NULL, warn = c(TRUE, FALSE) )
invcurve( object, ynew = NULL, xnew = NULL, dummynew = NULL, warn = c(TRUE, FALSE) )
object |
A model fit with |
ynew |
The input rate. If |
xnew |
The values for the additional regressors that were used in the curve fit. Must be a matrix, ordered (columns) as they were input in the fitting of the curve. The constant is dealt with automatically. Do not input the excess reserves. If |
dummynew |
The values for the indicator, if one was used in the fitting of the curve. If |
warn |
A logical ( |
Returns a vector of values of the predicted reserves
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- curve(x,rate,type="logistic") invcurve(fit) # Use a different input rate invcurve(fit,ynew=0.1)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- curve(x,rate,type="logistic") invcurve(fit) # Use a different input rate invcurve(fit,ynew=0.1)
Fits a non-parametric reserve demand curve between excess reserves and normalised rates
npcurve(x, y, type = c("rforest", "spline"), dummy = NULL, q = NULL, ...)
npcurve(x, y, type = c("rforest", "spline"), dummy = NULL, q = NULL, ...)
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
type |
The type of the reserve demand curve. This can be any of |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
q |
Target interval. This is a scalar below 1, for example 0.9 is the 90% interval. If |
... |
Additional arguments (unused). |
Returns a model of class npcurvir
. This includes
type
the type of the curve.
fit
the non-parametric model for the mean.
fitQ
The non-parametric model for the quantiles.
data
a list including the y
, x
, and dummy
used for the fitting of the curve.
q
the interval used in the fitting of the curve.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
predict.npcurvir
, and plot.npcurvir
.
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] npcurve(x,rate)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] npcurve(x,rate)
Plot a reserve demand curve estimated using curve
.
Plot a non-parametric reserve demand curve estimated using npcurve
.
## S3 method for class 'curvir' plot( x, ploty = c(FALSE, TRUE), plotq = c(TRUE, FALSE), usemean = c(FALSE, TRUE), prcmp = c(FALSE, TRUE), useline = c(FALSE, TRUE), main = NULL, pch = 20, ... ) ## S3 method for class 'npcurvir' plot( x, ploty = c(FALSE, TRUE), plotq = c(TRUE, FALSE), usemean = c(FALSE, TRUE), prcmp = c(FALSE, TRUE), useline = c(FALSE, TRUE), main = NULL, pch = 20, ... )
## S3 method for class 'curvir' plot( x, ploty = c(FALSE, TRUE), plotq = c(TRUE, FALSE), usemean = c(FALSE, TRUE), prcmp = c(FALSE, TRUE), useline = c(FALSE, TRUE), main = NULL, pch = 20, ... ) ## S3 method for class 'npcurvir' plot( x, ploty = c(FALSE, TRUE), plotq = c(TRUE, FALSE), usemean = c(FALSE, TRUE), prcmp = c(FALSE, TRUE), useline = c(FALSE, TRUE), main = NULL, pch = 20, ... )
x |
A model fit with |
ploty |
Logical ( |
plotq |
Logical ( |
usemean |
Logical ( |
prcmp |
Logical ( |
useline |
Logical ( |
main |
Use to overide the default plot title. |
pch |
Use to overide the dafault marker type for points. |
... |
Additional inputs (currently unused). |
No returned value. Produces a plot of the estimated curve.
plot(curvir)
: Plot parametric curves
plot(npcurvir)
: Plot non-parametric curves
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- curve(x,rate) plot(fit) # Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- npcurve(x,rate) plot(fit)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- curve(x,rate) plot(fit) # Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- npcurve(x,rate) plot(fit)
Predicted values based on curvir model object
Predicted values based on npcurvir model object
## S3 method for class 'curvir' predict(object, newdata = NULL, newdummy = NULL, ...) ## S3 method for class 'npcurvir' predict(object, newdata = NULL, newdummy = NULL, ...)
## S3 method for class 'curvir' predict(object, newdata = NULL, newdummy = NULL, ...) ## S3 method for class 'npcurvir' predict(object, newdata = NULL, newdummy = NULL, ...)
object |
A model fit with |
newdata |
New input data organised as the x matrix in |
newdummy |
New input dummy organised as the dummy vector in |
... |
Further arguments (unused) |
Returns a matrix of predicted values. If the model has estimates for intervals then it will provide upper and lower intervals.
Returns a matrix of predicted values. If the model has estimates for intervals then it will provide upper and lower intervals.
predict(curvir)
: Predicted values for parametric curves
predict(npcurvir)
: Predicted values for non-parametric curves
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- curve(x,rate) predict(fit) # An example with new data predict(fit,newdata=tail(x)) # Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- npcurve(x,rate) predict(fit)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- curve(x,rate) predict(fit) # An example with new data predict(fit,newdata=tail(x)) # Use ECB example data rate <- ecb$rate x <- ecb$x[,1,drop=FALSE] fit <- npcurve(x,rate) predict(fit)
Using cross-validation automatically select explanatory variables for a reserve demand curve type.
varselect( x, y, type = "logistic", folds = 10, constant = c(TRUE, FALSE), sign = NULL, reps = 3, search = c("backward", "forward"), wsel = c("select", "combine"), dummy = NULL )
varselect( x, y, type = "logistic", folds = 10, constant = c(TRUE, FALSE), sign = NULL, reps = 3, search = c("backward", "forward"), wsel = c("select", "combine"), dummy = NULL )
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
type |
The type of the reserve demand curve. This can be any of |
folds |
Folds to use for cross-validation. |
constant |
A logical ( |
sign |
A vector of equal length to the number of additional regressors in |
reps |
Number of repetitions for the particle swarm optimisation. |
search |
Search strategy for variable inclusion. With |
wsel |
Use the minimum error set of parameters ( |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
Returns a list with the recommended variable selection choice:
keep
a logical vector with which variables to keep.
errors
statistics of the cross-validated MSE error.
Nikolaos Kourentzes, [email protected]
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] varKeep <- varselect(x,rate,folds=5) # Print result print(varKeep) # Fit curve with the selected variables curve(x[,varKeep$keep,drop=FALSE],rate)
# Use ECB example data rate <- ecb$rate x <- ecb$x[,1:3,drop=FALSE] varKeep <- varselect(x,rate,folds=5) # Print result print(varKeep) # Fit curve with the selected variables curve(x[,varKeep$keep,drop=FALSE],rate)