Description Usage Arguments Details See Also Examples
Functions for modelling credit risk:
Bernoulli mixture model with prescribed default and joint default probabilities
Bernoulli mixture model with Clayton copula dependencies of default.
Probitnormal Mixture of Bernoullis
Beta-Binomial Distribution
Logitnormal-Binomial Distribution
Probitnormal-Binomial Distribution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | cal.beta(pi1, pi2)
cal.claytonmix(pi1, pi2)
cal.probitnorm(pi1, pi2)
dclaytonmix(x, pi, theta)
pclaytonmix(q, pi, theta)
rclaytonmix(n, pi, theta)
rtcopulamix(n, pi, rho.asset, df)
dprobitnorm(x, mu, sigma)
pprobitnorm(q, mu, sigma)
rprobitnorm(n, mu, sigma)
rbinomial.mixture(n = 1000, m = 100,
model = c("probitnorm", "logitnorm", "beta"), ...)
rlogitnorm(n, mu, sigma)
fit.binomial(M, m)
fit.binomialBeta(M, m, startvals = c(2, 2), ses = FALSE, ...)
fit.binomialLogitnorm(M, m, startvals = c(-1, 0.5), ...)
fit.binomialProbitnorm(M, m, startvals = c(-1, 0.5), ...)
momest(data, trials, limit = 10)
|
data |
|
df |
|
limit |
|
M |
|
m |
|
model |
|
mu |
|
n |
|
pi |
|
pi1 |
|
pi2 |
|
q |
|
sigma |
|
ses |
|
startvals |
|
theta |
|
trials |
|
x |
|
rho.asset |
|
... |
ellipsis, arguments are passed down to either mixing
distribution or |
cal.beta()
: calibrates a beta mixture distribution on unit
interval to give an exchangeable Bernoulli mixture model with
prescribed default and joint default probabilities (see pages 354-355
in QRM).
cal.claytonmix()
: calibrates a mixture distribution on unit
interval to give an exchangeable Bernoulli mixture model with
prescribed default and joint default probabilities. The mixture
distribution is the one implied by a Clayton copula model of default
(see page 362 in QRM).
cal.probitnorm()
: calibrates a probitnormal mixture
distribution on unit interval to give an exchangeable Bernoulli
mixture model with prescribed default and joint default probabilities
(see page 354 in QRM).
dclaytonmix()
, pclaytonmix()
, rclaytonmix()
:
density, cumulative probability, and random generation for a mixture
distribution on the unit interval which gives an exchangeable
Bernoulli mixture model equivalent to a Clayton copula model (see page
362 in QRM).
fit.binomial()
: fits binomial distribution by maximum
likelihood.
dprobitnorm()
, pprobitnorm()
, rprobitnorm()
:
density, cumulative probability and random number generation for
distribution of random variable Q on unit interval such that the
probit transform of Q has a normal distribution with parameters
mu and sigma (see pages 353-354 in QRM).
fit.binomialBeta()
: fit a beta-binomial distribution by maximum
likelihood.
fit.binomialLogitnorm()
: fits a mixed binomial distribution
where success probability has a logitnormal distribution. Lower and
upper bounds for the input parameters M and m can be specified by
means of the arguments lower
and upper
, which are passed to
nlminb()
. If convergence occurs at an endpoint of either limit,
one need to reset lower and upper parameter estimators and run the
function again.
fit.binomialProbitnorm()
: Fits a mixed binomial distribution
where success probability has a probitnormal distribution. Lower and
upper bounds for the input parameters M and m can be specified by
means of the arguments lower
and upper
, which are passed to
nlminb()
. If convergence occurs at an endpoint of either limit,
one need to reset lower and upper parameter estimators and run the
function again.
momest()
: calculates moment estimator of default probabilities
and joint default probabilities for a homogeneous group. First
returned value is default probability estimate; second value is
estimate of joint default probability for two firms; and so on (see
pages 375-376 in QRM).
rbinomial.mixture()
: random variates from mixed binomial
distribution (see pages 354-355 and pages 375-377 of QRM).
rlogitnorm()
: Random number generation for distribution of
random variable Q on unit interval such that the probit transform of Q
has a normal distribution with parameters mu and
sigma (see pages 353-354 in QRM).
rtcopulamix()
: random generation for mixing distribution on
unit interval yielding Student's t copula model (see page 361 in QRM,
exchangeable case of this model is considered).
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 | ## calibrating models
pi.B <- 0.2
pi2.B <- 0.05
probitnorm.pars <- cal.probitnorm(pi.B, pi2.B)
probitnorm.pars
beta.pars <- cal.beta(pi.B, pi2.B)
beta.pars
claytonmix.pars <- cal.claytonmix(pi.B, pi2.B)
claytonmix.pars
q <- (1:1000) / 1001
q <- q[q < 0.25]
p.probitnorm <- pprobitnorm(q, probitnorm.pars[1],
probitnorm.pars[2])
p.beta <- pbeta(q, beta.pars[1], beta.pars[2])
p.claytonmix <- pclaytonmix(q, claytonmix.pars[1],
claytonmix.pars[2])
scale <- range((1 - p.probitnorm), (1 - p.beta), (1 - p.claytonmix))
plot(q, (1 - p.probitnorm), type = "l", log = "y", xlab = "q",
ylab = "P(Q > q)",ylim=scale)
lines(q, (1 - p.beta), col = 2)
lines(q, (1 - p.claytonmix), col = 3)
legend("topright", c("Probit-normal", "Beta", "Clayton-Mixture"),
lty=rep(1,3),col = (1:3))
## Clayton Mix
pi.B <- 0.0489603
pi2.B <- 0.003126529
claytonmix.pars <- cal.claytonmix(pi.B, pi2.B)
claytonmix.pars
q <- (1:1000) / 1001
q <- q[q < 0.25]
d.claytonmix <- dclaytonmix(q, claytonmix.pars[1], claytonmix.pars[2])
head(d.claytonmix)
## SP Data
data(spdata.raw)
attach(spdata.raw)
BdefaultRate <- Bdefaults / Bobligors
## Binomial Model
mod1a <- fit.binomial(Bdefaults, Bobligors)
## Binomial Logitnorm Model
mod1b <- fit.binomialLogitnorm(Bdefaults, Bobligors)
## Binomial Probitnorm Model
mod1c <- fit.binomialProbitnorm(Bdefaults, Bobligors)
## Binomial Beta Model
mod1d <- fit.binomialBeta(Bdefaults, Bobligors);
## Moment estimates for default probabilities
momest(Bdefaults, Bobligors)
pi.B <- momest(Bdefaults, Bobligors)[1]
pi2.B <- momest(Bdefaults, Bobligors)[2]
## Probitnorm
probitnorm.pars <- cal.probitnorm(pi.B, pi2.B)
q <- (1:1000)/1001
q <- q[ q < 0.25]
d.probitnorm <- dprobitnorm(q, probitnorm.pars[1], probitnorm.pars[2])
p <- c(0.90,0.95,0.975,0.99,0.995,0.999,0.9999,0.99999,0.999999)
sigma <- 0.2 * 10000 / sqrt(250)
VaR.t4 <- qst(p, df = 4, sd = sigma, scale = TRUE)
VaR.t4
detach(spdata.raw)
## Binomial Mixture Models
pi <- 0.04896
pi2 <- 0.00321
beta.pars <- cal.beta(pi, pi2)
probitnorm.pars <- cal.probitnorm(pi, pi2)
n <- 1000
m <- rep(500, n)
mod2a <- rbinomial.mixture(n, m, "beta", shape1 = beta.pars[1],
shape2 = beta.pars[2])
mod2b <- rbinomial.mixture(n, m, "probitnorm",
mu = probitnorm.pars[1],
sigma = probitnorm.pars[2])
|
Loading required package: gsl
Loading required package: Matrix
Loading required package: mvtnorm
Loading required package: numDeriv
Loading required package: timeSeries
Loading required package: timeDate
Attaching package: 'QRM'
The following object is masked from 'package:base':
lbeta
mu sigma rho.asset
-0.8983228 0.3732059 0.1222547
a b
3 12
pi theta
0.20000000 0.09982679
pi theta
0.04896030 0.03198761
[1] 0.001142736 0.021818856 0.103356236 0.285265923 0.592723408 1.035450932
[1] 4.896030e-02 3.126529e-03 2.485062e-04 2.320990e-05 2.386235e-06
[6] 2.576897e-07 2.836485e-08 3.122301e-09 3.395502e-10 3.619895e-11
[1] 137.1341 190.6782 248.3328 335.1372 411.8028 641.5889 1165.7670
[8] 2086.8939 3718.8363
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.