| Title: | Extended Vasicek Credit Loss Model with Macroeconomic Factors |
|---|---|
| Description: | Fits the extended Vasicek single-factor credit loss model where the probability of default depends on macroeconomic covariates. Maximum likelihood estimates of all parameters, including asset value correlation, are obtained via closed-form probit-transformed OLS regression; see Mayorov (2026) <doi:10.2139/ssrn.6506378> for derivation. |
| Authors: | Dmitriy Mayorov [aut, cre] |
| Maintainer: | Dmitriy Mayorov <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-05-30 09:32:40 UTC |
| Source: | https://github.com/externalmemory/vasicekfit-cran-package |
Fits the extended Vasicek single-factor credit loss model where the probability of default depends on macroeconomic covariates. Maximum likelihood estimates of all parameters, including asset value correlation, are obtained via closed-form probit-transformed OLS regression. Also provides density, distribution, quantile, and random generation functions for the Vasicek loss distribution.
Dmitriy Mayorov
Vasicek, O. A. (2002). The distribution of loan portfolio value. Risk, 15(12), 160–162.
Yang, B. H. (2014). Estimating Long-Run PD, Asset Correlation, and Portfolio Level PD by Vasicek Models. MPRA Paper No. 57244.
vasicekfit, predict.vasicekfit,
dvasicek
Obtain predictions from a fitted Vasicek model, optionally at specified confidence levels.
## S3 method for class 'vasicekfit' predict(object, newdata = NULL, type = c("link", "response"), alpha = NULL, ...)## S3 method for class 'vasicekfit' predict(object, newdata = NULL, type = c("link", "response"), alpha = NULL, ...)
object |
a |
newdata |
an optional data frame of new predictor values. If omitted, the training data are used. |
type |
character; |
alpha |
optional numeric vector of confidence levels in (0, 1). When supplied, predictions are conditional quantiles of the loss distribution at each confidence level. |
... |
additional arguments (currently unused). |
If alpha is NULL, a numeric vector of predictions.
If alpha is supplied, a matrix with rows corresponding to observations
and columns to confidence levels. When alpha is a scalar, the result
is a vector.
set.seed(42) n <- 100 u <- rnorm(n) x <- pnorm((qnorm(0.03) + 0.1 * u + sqrt(0.02) * rnorm(n)) / sqrt(1 - 0.02)) d <- data.frame(default_rate = x, macro = u) fit <- vasicekfit(default_rate ~ macro, data = d) # Conditional mean PD predict(fit, type = "response") # 99th percentile loss rate under stress predict(fit, newdata = data.frame(macro = 2), alpha = 0.99, type = "response") # Multiple confidence levels predict(fit, newdata = data.frame(macro = c(0, 1, 2)), alpha = c(0.95, 0.99, 0.999), type = "response")set.seed(42) n <- 100 u <- rnorm(n) x <- pnorm((qnorm(0.03) + 0.1 * u + sqrt(0.02) * rnorm(n)) / sqrt(1 - 0.02)) d <- data.frame(default_rate = x, macro = u) fit <- vasicekfit(default_rate ~ macro, data = d) # Conditional mean PD predict(fit, type = "response") # 99th percentile loss rate under stress predict(fit, newdata = data.frame(macro = 2), alpha = 0.99, type = "response") # Multiple confidence levels predict(fit, newdata = data.frame(macro = c(0, 1, 2)), alpha = c(0.95, 0.99, 0.999), type = "response")
Density, distribution function, quantile function, and random generation for the Vasicek credit loss distribution.
dvasicek(x, p, rho, kappa = NULL, u = NULL, log = FALSE) pvasicek(q, p, rho, kappa = NULL, u = NULL, lower.tail = TRUE, log.p = FALSE) qvasicek(prob, p, rho, kappa = NULL, u = NULL, lower.tail = TRUE, log.p = FALSE) rvasicek(n, p, rho, kappa = NULL, u = NULL)dvasicek(x, p, rho, kappa = NULL, u = NULL, log = FALSE) pvasicek(q, p, rho, kappa = NULL, u = NULL, lower.tail = TRUE, log.p = FALSE) qvasicek(prob, p, rho, kappa = NULL, u = NULL, lower.tail = TRUE, log.p = FALSE) rvasicek(n, p, rho, kappa = NULL, u = NULL)
x, q
|
vector of quantiles (loss rates in (0, 1)). |
prob |
vector of probabilities. |
n |
number of observations to generate. |
p |
probability of default, in (0, 1). |
rho |
asset value correlation, in (0, 1). |
kappa |
optional numeric vector of macro-factor sensitivities. |
u |
optional numeric vector of macro-factor values, same length as
|
log, log.p
|
logical; if |
lower.tail |
logical; if |
The Vasicek loss distribution arises from the single-factor Gaussian copula model. Its probability density function is
When kappa and u are NULL, this reduces to the standard
two-parameter Vasicek distribution.
dvasicek gives the density, pvasicek gives the distribution
function, qvasicek gives the quantile function, and rvasicek
generates random deviates.
Vasicek, O. A. (2002). The distribution of loan portfolio value. Risk, 15(12), 160–162.
# Standard Vasicek density curve(dvasicek(x, p = 0.03, rho = 0.10), from = 0.001, to = 0.20, ylab = "Density", main = "Vasicek loss distribution") # 99th percentile (Basel-style) qvasicek(0.99, p = 0.03, rho = 0.10) # Check CDF and quantile are inverses qvasicek(pvasicek(0.05, p = 0.03, rho = 0.10), p = 0.03, rho = 0.10) # Random sample set.seed(1) hist(rvasicek(10000, p = 0.03, rho = 0.10), breaks = 100, main = "Vasicek loss distribution samples")# Standard Vasicek density curve(dvasicek(x, p = 0.03, rho = 0.10), from = 0.001, to = 0.20, ylab = "Density", main = "Vasicek loss distribution") # 99th percentile (Basel-style) qvasicek(0.99, p = 0.03, rho = 0.10) # Check CDF and quantile are inverses qvasicek(pvasicek(0.05, p = 0.03, rho = 0.10), p = 0.03, rho = 0.10) # Random sample set.seed(1) hist(rvasicek(10000, p = 0.03, rho = 0.10), breaks = 100, main = "Vasicek loss distribution samples")
Fits the extended Vasicek single-factor credit loss model where the probability of default depends on macroeconomic covariates. All parameters, including asset value correlation, are estimated via closed-form probit-transformed OLS.
vasicekfit(formula, data, bias_correct = FALSE, portfolio_size = NULL)vasicekfit(formula, data, bias_correct = FALSE, portfolio_size = NULL)
formula |
a formula of the form |
data |
a data frame containing the variables in |
bias_correct |
logical; if |
portfolio_size |
optional positive integer. If supplied, a finite-portfolio variance correction is applied to the response before fitting (see Yang, 2014, section 4.3). |
An object of class "vasicekfit", which is a list containing:
estimated probability of default (baseline PD).
estimated asset value correlation.
named numeric vector of macro-factor sensitivities.
MLE variance estimate in probit space.
the underlying lm object.
fitted values in probit (Y) space.
residuals in probit (Y) space.
the model formula.
the matched call.
the terms object.
the model frame.
logical flag used.
portfolio size used, or NULL.
Vasicek, O. A. (2002). The distribution of loan portfolio value. Risk, 15(12), 160–162.
Yang, B. H. (2014). Estimating Long-Run PD, Asset Correlation, and Portfolio Level PD by Vasicek Models. MPRA Paper No. 57244.
set.seed(42) n <- 100 u1 <- rnorm(n) u2 <- rnorm(n) p_true <- 0.03; rho_true <- 0.02 kappa_true <- c(0.13, -0.07) z <- rnorm(n) x <- pnorm((qnorm(p_true) + kappa_true[1] * u1 + kappa_true[2] * u2 + sqrt(rho_true) * z) / sqrt(1 - rho_true)) d <- data.frame(default_rate = x, unemp = u1, hpi = u2) fit <- vasicekfit(default_rate ~ unemp + hpi, data = d) fitset.seed(42) n <- 100 u1 <- rnorm(n) u2 <- rnorm(n) p_true <- 0.03; rho_true <- 0.02 kappa_true <- c(0.13, -0.07) z <- rnorm(n) x <- pnorm((qnorm(p_true) + kappa_true[1] * u1 + kappa_true[2] * u2 + sqrt(rho_true) * z) / sqrt(1 - rho_true)) d <- data.frame(default_rate = x, unemp = u1, hpi = u2) fit <- vasicekfit(default_rate ~ unemp + hpi, data = d) fit
Print, summary, coefficient extraction, covariance, confidence interval,
and accessor methods for "vasicekfit" objects.
## S3 method for class 'vasicekfit' print(x, ...) ## S3 method for class 'vasicekfit' summary(object, type = c("iid", "HAC"), ...) ## S3 method for class 'vasicekfit' coef(object, ...) ## S3 method for class 'vasicekfit' fitted(object, ...) ## S3 method for class 'vasicekfit' residuals(object, ...) ## S3 method for class 'vasicekfit' vcov(object, type = c("iid", "HAC"), ...) ## S3 method for class 'vasicekfit' confint(object, parm, level = 0.95, type = c("iid", "HAC"), ...)## S3 method for class 'vasicekfit' print(x, ...) ## S3 method for class 'vasicekfit' summary(object, type = c("iid", "HAC"), ...) ## S3 method for class 'vasicekfit' coef(object, ...) ## S3 method for class 'vasicekfit' fitted(object, ...) ## S3 method for class 'vasicekfit' residuals(object, ...) ## S3 method for class 'vasicekfit' vcov(object, type = c("iid", "HAC"), ...) ## S3 method for class 'vasicekfit' confint(object, parm, level = 0.95, type = c("iid", "HAC"), ...)
x, object
|
a |
parm |
a specification of which parameters to compute confidence intervals for, either a vector of names or indices. If missing, all parameters are considered. |
level |
the confidence level required. |
type |
covariance type. |
... |
when |
coef returns the recovered Vasicek parameters (p, rho, and kappas)
in the original parameter space.
fitted and residuals return values in probit (Y) space,
consistent with the underlying OLS regression.
vcov returns the delta-method covariance matrix for the
original-space parameters ,
obtained by propagating the joint covariance of
through the closed-form recovery transform.
With type = "iid" the block is
treated as block-diagonal by the independence of sample mean and variance
under normality. The variance of uses
for the MLE and
when bias_correct = TRUE.
With type = "HAC" the joint covariance of
is estimated as the long-run variance of
the stacked influence functions
and
, computed via
lrvar. This is appropriate when the data exhibit
serial correlation (e.g. quarterly macro covariates), at the cost of some
finite-sample bias. Defaults follow lrvar (Andrews quadratic-spectral
kernel, prewhitened); pass prewhite, kernel, bw, or
adjust via ... to override.
The HAC standard errors do not change with bias_correct: the
long-run variance is estimated empirically from the influence functions
rather than from the parametric Gaussian formula, so the
scaling does not apply. The bias_correct flag
still affects the point estimates of , , and
(via ) regardless of type.
confint returns Wald intervals based on vcov.
print and summary return object invisibly.
coef returns a named numeric vector.
fitted and residuals return numeric vectors.
vcov returns a covariance matrix.
confint returns a two-column matrix of lower and upper bounds.
vasicekfit, predict.vasicekfit