Title: | Generalized Credit Portfolio Model |
---|---|
Description: | Analyze the default risk of credit portfolios. Commonly known models, like CreditRisk+ or the CreditMetrics model are implemented in their very basic settings. The portfolio loss distribution can be achieved either by simulation or analytically in case of the classic CreditRisk+ model. Models are only implemented to respect losses caused by defaults, i.e. migration risk is not included. The package structure is kept flexible especially with respect to distributional assumptions in order to quantify the sensitivity of risk figures with respect to several assumptions. Therefore the package can be used to determine the credit risk of a given portfolio as well as to quantify model sensitivities. |
Authors: | Kevin Jakob |
Maintainer: | Kevin Jakob <[email protected]> |
License: | GPL-2 |
Version: | 1.2.2 |
Built: | 2024-12-11 06:44:34 UTC |
Source: | CRAN |
The package helps to analyze the default risk of credit portfolios. Commonly known models, like CreditRisk+ or the CreditMetrics model are implemented in their very basic settings. The portfolio loss distribution can be achieved either by simulation or analytically in case of the classic CreditRisk+ model. Models are only implemented to respect losses caused by defaults, i.e. migration risk is not included. The package structure is kept flexible especially with respect to distributional assumptions in order to quantify the sensitivity of risk figures with respect to several assumptions. Therefore the package can be used to determine the credit risk of a given portfolio as well as to quantify model sensitivities.
Package: | GCPM |
Type: | Package |
Version: | 1.2.2 |
Date: | 2016-12-29 |
License: | GPL-2 |
Kevin Jakob
Maintainer: Kevin Jakob <[email protected]>
Jakob, K. & Fischer, M. "GCPM: A flexible package to explore credit portfolio risk" Austrian Journal of Statistics 45.1 (2016): 25:44
Morgan, J. P. "CreditMetrics-technical document." JP Morgan, New York, 1997
First Boston Financial Products, "CreditRisk+", 1997
Gundlach & Lehrbass, "CreditRisk+ in the Banking Industry", Springer, 2003
#create a random portfolio with NC counterparties NC=100 #assign business lines and countries randomly business.lines=c("A","B","C") CP.business=business.lines[ceiling(runif(NC,0,length(business.lines)))] countries=c("A","B","C","D","E") CP.country=countries[ceiling(runif(NC,0,length(countries)))] #create matrix with sector weights (CreditRisk+ setting) #according to business lines NS=length(business.lines) W=matrix(0,nrow = NC,ncol = length(business.lines), dimnames = list(1:NC,business.lines)) for(i in 1:NC){W[i,CP.business[i]]=1} #create portfolio data frame portfolio=data.frame(Number=1:NC,Name=paste("Name ",1:NC),Business=CP.business, Country=CP.country,EAD=runif(NC,1e3,1e6),LGD=runif(NC), PD=runif(NC,0,0.3),Default=rep("Bernoulli",NC),W) #draw sector variances randomly sec.var=runif(NS,0.5,1.5) names(sec.var)=business.lines #draw N sector realizations (independent gamma distributed sectors) N=5e4 random.numbers=matrix(NA,ncol=NS,nrow=N,dimnames=list(1:N,business.lines)) for(i in 1:NS){ random.numbers[,i]=rgamma(N,shape = 1/sec.var[i],scale=sec.var[i])} #create a portfolio model and analyze the portfolio TestModel=init(model.type = "simulative",link.function = "CRP",N = N, loss.unit = 1e3, random.numbers = random.numbers,LHR=rep(1,N),loss.thr=5e6, max.entries=2e4) TestModel=analyze(TestModel,portfolio) #plot of pdf of portfolio loss (in million) with indicators for EL, VaR and ES alpha=c(0.995,0.999) plot(TestModel,1e6,alpha=alpha) #calculate portfolio VaR and ES VaR=VaR(TestModel,alpha) ES=ES(TestModel,alpha) #Calculate risk contributions to VaR and ES risk.cont=cbind(VaR.cont(TestModel,alpha = alpha), ES.cont(TestModel,alpha = alpha))
#create a random portfolio with NC counterparties NC=100 #assign business lines and countries randomly business.lines=c("A","B","C") CP.business=business.lines[ceiling(runif(NC,0,length(business.lines)))] countries=c("A","B","C","D","E") CP.country=countries[ceiling(runif(NC,0,length(countries)))] #create matrix with sector weights (CreditRisk+ setting) #according to business lines NS=length(business.lines) W=matrix(0,nrow = NC,ncol = length(business.lines), dimnames = list(1:NC,business.lines)) for(i in 1:NC){W[i,CP.business[i]]=1} #create portfolio data frame portfolio=data.frame(Number=1:NC,Name=paste("Name ",1:NC),Business=CP.business, Country=CP.country,EAD=runif(NC,1e3,1e6),LGD=runif(NC), PD=runif(NC,0,0.3),Default=rep("Bernoulli",NC),W) #draw sector variances randomly sec.var=runif(NS,0.5,1.5) names(sec.var)=business.lines #draw N sector realizations (independent gamma distributed sectors) N=5e4 random.numbers=matrix(NA,ncol=NS,nrow=N,dimnames=list(1:N,business.lines)) for(i in 1:NS){ random.numbers[,i]=rgamma(N,shape = 1/sec.var[i],scale=sec.var[i])} #create a portfolio model and analyze the portfolio TestModel=init(model.type = "simulative",link.function = "CRP",N = N, loss.unit = 1e3, random.numbers = random.numbers,LHR=rep(1,N),loss.thr=5e6, max.entries=2e4) TestModel=analyze(TestModel,portfolio) #plot of pdf of portfolio loss (in million) with indicators for EL, VaR and ES alpha=c(0.995,0.999) plot(TestModel,1e6,alpha=alpha) #calculate portfolio VaR and ES VaR=VaR(TestModel,alpha) ES=ES(TestModel,alpha) #Calculate risk contributions to VaR and ES risk.cont=cbind(VaR.cont(TestModel,alpha = alpha), ES.cont(TestModel,alpha = alpha))
Get the maximum value of the model's CDF. For simulative models,
the value should be equal to 1. For an analytical model,
the value depends on the value specified during initiation of the model (see init
).
alpha.max(this)
alpha.max(this)
this |
Object of class |
numeric of length 1
The method analyzes a given portfolio with a predefined portfolio model
(i.e. a GCPM
object). Portfolio key numbers such as the number of portfolio
positions, sum of EAD and PL or the expected loss are calculated. Afterwards the
loss distribution is estimated according to model.type
.
analyze(this,portfolio,alpha,Ncores)
analyze(this,portfolio,alpha,Ncores)
this |
object of class |
portfolio |
data frame containing portfolio data. The following columns
have to be defined (please be aware of the correct spelling of the column names): |
alpha |
loss levels for risk measures economic capital, value at risk and expected shortfall (optional) |
Ncores |
number of (virtual) cores used to perfom Monte Carlo simulation (requires package parallel, default=1) |
In case of an analytical CreditRisk+ model, a modified version of the
algorithm described in Gundlach & Lehrbass (2003) is used. For a simulative
model, the loss distribution is estimated based on N
simulations with
sector drawings specified by random.numbers
(see init
).
The sector names (column names) should not include any white spaces. In case of a
CreditMetrics type model, the values of R (not R^2) have to be provided as sector
weights. In the standard CreditMetrics or CreditRisk+ framework a counterparty can
be assigned to more than one sector. Within a analytical CreditRisk+ model, the
sector names have to match the names of sec.var
or in a simulative model
the column names of random.numbers
(see init
)
object of class GCPM
.
signature(this = "GCPM", portfolio = "data.frame",
alpha = "missing")
If loss levels alpha
are not provided, risk measures such as economic
capital, value at risk and expected shortfall are not calculated by default.
However, they can be calculated afterwards by calling the corresponding methods
(see VaR
, ES
, EC
)
signature(this = "GCPM", portfolio = "data.frame",
alpha = "numeric")
If loss levels alpha
are provided, risk measures such as economic
capital, value at risk and expected shortfall are calculated and printed.
To extract these risk measures into a separate variable you can use the
corresponding methods.
Jakob, K. & Fischer, M. "GCPM: A flexible package to explore credit portfolio risk" Austrian Journal of Statistics 45.1 (2016): 25:44
Morgan, J. P. "CreditMetrics-technical document." JP Morgan, New York, 1997
First Boston Financial Products, "CreditRisk+", 1997
Gundlach & Lehrbass, "CreditRisk+ in the Banking Industry", Springer, 2003
#create a random portfolio with NC counterparties NC=100 #assign business lines and countries randomly business.lines=c("A","B","C") CP.business=business.lines[ceiling(runif(NC,0,length(business.lines)))] countries=c("A","B","C","D","E") CP.country=countries[ceiling(runif(NC,0,length(countries)))] #create matrix with sector weights (CreditRisk+ setting) #according to business lines NS=length(business.lines) W=matrix(0,nrow = NC,ncol = length(business.lines), dimnames = list(1:NC,business.lines)) for(i in 1:NC){W[i,CP.business[i]]=1} #create portfolio data frame portfolio=data.frame(Number=1:NC,Name=paste("Name ",1:NC),Business=CP.business, Country=CP.country,EAD=runif(NC,1e3,1e6),LGD=runif(NC), PD=runif(NC,0,0.3),Default=rep("Bernoulli",NC),W) #draw sector variances randomly sec.var=runif(NS,0.5,1.5) names(sec.var)=business.lines #draw N sector realizations (independent gamma distributed sectors) N=5e4 random.numbers=matrix(NA,ncol=NS,nrow=N,dimnames=list(1:N,business.lines)) for(i in 1:NS){ random.numbers[,i]=rgamma(N,shape = 1/sec.var[i],scale=sec.var[i])} #create a portfolio model and analyze the portfolio TestModel=init(model.type = "simulative",link.function = "CRP",N = N, loss.unit = 1e3, random.numbers = random.numbers,LHR=rep(1,N),loss.thr=5e6, max.entries=2e4) TestModel=analyze(TestModel,portfolio) #plot of pdf of portfolio loss (in million) with indicators for EL, VaR and ES alpha=c(0.995,0.999) plot(TestModel,1e6,alpha=alpha) #calculate portfolio VaR and ES VaR=VaR(TestModel,alpha) ES=ES(TestModel,alpha) #Calculate risk contributions to VaR and ES risk.cont=cbind(VaR.cont(TestModel,alpha = alpha), ES.cont(TestModel,alpha = alpha)) #Use parallel computing for Monte Carlo simulation TestModel=analyze(TestModel,portfolio,Ncores=2)
#create a random portfolio with NC counterparties NC=100 #assign business lines and countries randomly business.lines=c("A","B","C") CP.business=business.lines[ceiling(runif(NC,0,length(business.lines)))] countries=c("A","B","C","D","E") CP.country=countries[ceiling(runif(NC,0,length(countries)))] #create matrix with sector weights (CreditRisk+ setting) #according to business lines NS=length(business.lines) W=matrix(0,nrow = NC,ncol = length(business.lines), dimnames = list(1:NC,business.lines)) for(i in 1:NC){W[i,CP.business[i]]=1} #create portfolio data frame portfolio=data.frame(Number=1:NC,Name=paste("Name ",1:NC),Business=CP.business, Country=CP.country,EAD=runif(NC,1e3,1e6),LGD=runif(NC), PD=runif(NC,0,0.3),Default=rep("Bernoulli",NC),W) #draw sector variances randomly sec.var=runif(NS,0.5,1.5) names(sec.var)=business.lines #draw N sector realizations (independent gamma distributed sectors) N=5e4 random.numbers=matrix(NA,ncol=NS,nrow=N,dimnames=list(1:N,business.lines)) for(i in 1:NS){ random.numbers[,i]=rgamma(N,shape = 1/sec.var[i],scale=sec.var[i])} #create a portfolio model and analyze the portfolio TestModel=init(model.type = "simulative",link.function = "CRP",N = N, loss.unit = 1e3, random.numbers = random.numbers,LHR=rep(1,N),loss.thr=5e6, max.entries=2e4) TestModel=analyze(TestModel,portfolio) #plot of pdf of portfolio loss (in million) with indicators for EL, VaR and ES alpha=c(0.995,0.999) plot(TestModel,1e6,alpha=alpha) #calculate portfolio VaR and ES VaR=VaR(TestModel,alpha) ES=ES(TestModel,alpha) #Calculate risk contributions to VaR and ES risk.cont=cbind(VaR.cont(TestModel,alpha = alpha), ES.cont(TestModel,alpha = alpha)) #Use parallel computing for Monte Carlo simulation TestModel=analyze(TestModel,portfolio,Ncores=2)
Get the business information for each counterparty defined in the portfolio.
business(this)
business(this)
this |
Object of class |
factor of length equal to number of portfolio positions
Get the CDF of the portfolio loss, available after execution of analyze
.
CDF(this)
CDF(this)
this |
Object of class |
numeric vector
Get the country information of each counterparty defined in the portfolio.
country(this)
country(this)
this |
Object of class |
factor of length equal to number of portfolio positions
Get the default distribution of each portfolio position. Using “Poisson” as default distribution one can simulate the standard CR+ model or group smaller counterparties into a pool and simulate their defaults.
default(this)
default(this)
this |
Object of class |
character of length equal to number of portfolio positions
Get the counterparties' exposure at default defined in the portfolio data.
EAD(this)
EAD(this)
this |
Object of class |
numeric value of length equal to the number of counterparties
Get the value of economic capital for the portfolio on level(s)
alpha
EC(this,alpha)
EC(this,alpha)
this |
Object of class |
alpha |
numeric vector of loss levels between 0 and 1 |
numeric vector of length equal to length(alpha)
.
Calculate contributions to the economic capital on portfolio level for each
portfolio position. In case of a simulative model, the risk contributions are
calculated as contributions to expected shortfall on a lower loss level
, such that ES(
) is as close as possible to EC(
).
Furthermore, in case of a simulative model, loss scenarios above a predefined
threshold (
loss.thr
) are analyzed in order to calculate the risk
contributions. If loss.thr
is too high (depending on value of alpha
)
the calculation will be not possible.
EC.cont(this,alpha)
EC.cont(this,alpha)
this |
Object of class |
alpha |
numeric vector of loss levels between 0 and 1 |
numeric matrix with number of rows equal to number of counterparties within the portfolio and number of columns equal to length(alpha)
Get the expected loss (EL) calculated from the portfolio loss distribution.
Because of the discretization and/or simulation errors, this is not equal to
the analytical EL (see EL.analyt
). Please also note, that in case
of a simulative model (with Bernoulli default distribution) of the CreditRisk+
type the simulated EL tends to be smaller than the analytical one because the
conditional PD has to be truncated (if
).
EL(this)
EL(this)
this |
Object of class |
numeric value of length 1
Get the expected loss (EL) calculated from the portfolio data. Because of the
discretization and/or simulation errors, this is not equal to the EL calculated
from the portfolio loss distribution (see EL
).
EL.analyt(this)
EL.analyt(this)
this |
Object of class |
numeric value of length 1
Get the value of the expected shortfall for the portfolio on level(s)
alpha
ES(this,alpha)
ES(this,alpha)
this |
Object of class |
alpha |
numeric vector of loss levels between 0 and 1 |
numeric vector of length equal to length(alpha)
.
Calculate contributions to the expected shortfall on portfolio level for each
portfolio position. In case of a simulative model, loss scenarios above a
predefined threshold (loss.thr
) are analyzed in order to calculate the
risk contributions. If loss.thr
is too high, calculation may be not
possible (depending on value of alpha
).
ES.cont(this,alpha)
ES.cont(this,alpha)
this |
Object of class |
alpha |
numeric vector of loss levels between 0 and 1 |
numeric matrix with number of rows equal to number of counterparties within the portfolio and number of columns equal to length(alpha)
This method provides an easy way to export the main results of the portfolio
(i.e. after running analyze
). A summary file and the portfolio loss
distribution (PDF and CDF) are exported to path.out
. With the help of
file.format
one can specify the csv format (“csv1” or
“csv2”). If a vector alpha
of loss levels is specified,
risk contributions to EC, VaR and ES are also exported according to level(s)
alpha
.
export(this,path.out,file.format,alpha)
export(this,path.out,file.format,alpha)
this |
Object of class |
path.out |
string specifying the output path |
file.format |
string specifying the file format (i.e “csv1” or “csv2”) |
alpha |
numeric vector with loss levels between 0 and 1 |
"GCPM"
The class represents a generalized credit portfolio framework. Users which are not familiar with credit portfolio models in general and the CreditRisk+ model as well as the CreditMetrics model in particular should refer to the references given below. Models can be simulative or analytical (in case of a CreditRisk+ type model). The link function can be chosen to be either of the CreditRisk+ or the CreditMetrics type. Counterparties' default distribution can be specified to be either Bernoulli or Poisson, which is the default distribution in the basic CreditRisk+ framework.
Objects can be created via the init
function (see init
)
model.type
:Character value, specifying the model type. One can choose between “simulative” and “CRP” which corresponds to the analytical version of the CreditRisk+ model (see First Boston Financial Products, 1997)
default
:Character vector specifying the counterparties' default distribution (either “Bernoulli” or “Poisson”)
link.function
:character value, specifying the type of the
link function. One can choose between “CRP”, which corresponds to
and “CM” which corresponds to
,
where PD is the original PD from portfolio data, x is the vector of sector
drawings,
is the CDF of the standard normal distribution, w is
the vector of sector weights given in the portfolio data and
is the correlation matrix of the sector variables estimated from
random.numbers
. “CRP” will be used automatically if
model.type
== "CRP".
loss.unit
:numeric value used to discretize potential losses.
NS
:number of sectors
NC
:number of counterparties
name
:counterparties' names defined in the portfolio
NR
:counterparties' identification numbers defined in the portfolio
EAD
:counterparties' exposure at default defined in the portfolio
LGD
:counterparties' loss given default defined in the portfolio
PL
:counterparties' potential loss ()
PD
:counterparties' probability of default defined in the portfolio
business
:counterparties' business line defined in the portfolio
country
:counterparties' country defined in the portfolio
EL.analyt
:Expected loss calculated from portfolio data (without discretization)
EL
:Expected loss derived from loss distribution
nu
:multiples of loss unit
representing discretized
potential losses within an analytical CreditRisk+ type model
PL.disc
:counterparties' potential loss ()
after discretization
PD.disc
:counterparties' probability of default defined in the portfolio after discretization
sec.var
:sector variances within an analytical CreditRisk+ type model
sector.names
:sector names
SD.div
:diversifiable part of portfolio risk (measured by standard deviation) in case of a CreditRisk+ type model
SD.syst
:Non-diversifiable part of portfolio risk (measured by standard deviation) in case of a CreditRisk+ type model
SD.analyt
:portfolio standard deviation derived from portfolio data in case of a CreditRisk+ type model
SD
:portfolio standard deviation derived from loss distribution
W
:counterparties' sector weights
idiosyncr
:counterparties idiosyncratic weight in case of a CreditRisk+ type model
alpha.max
:maximum level of CDF of the loss distribution within an analytical CreditRisk+ type model
a
:internal parameter used to calculate risk contributions in case of an analytical CreditRisk+ type model
PDF
:probability density function of portfolio losses
CDF
:cumulative distribution function of portfolio losses
B
:internal parameter used to calculate risk contributions in case of an analytical CreditRisk+ type model
loss
:portfolio losses corresponding to PDF
and
CDF
random.numbers
:sector drawing in case of a simulative model
LHR
:likelihood ration of sector drawing in case of a simulative model
numeric value defining the maximum number of loss scenarios stored to calculate risk contributions.
N
:number of simulations in case of a simulative model
scenarios
:scenarios (rows) of random.numbers
used
within the simulation of portfolio losses
seed
:parameter used to initialize the random number
generator. If seed
is not provided a value based on current system
time will be used.
loss.thr
:specifies a lower bound for portfolio losses to be
stored in order to derive risk contributions on counterparty level. Using
a lower value needs a lot of memory but will be necessary in order to
calculate risk contributions on lower CDF levels. This parameter is used
only if model.type
== "simulative".
sim.losses
:simulated portfolio losses in case of a simulative model
CP.sim.losses
:simulated losses on counterparty level when
the overall portfolio loss is greater or equal to loss.thr
Kevin Jakob
Jakob, K. & Fischer, M. "GCPM: A flexible package to explore credit portfolio risk" Austrian Journal of Statistics 45.1 (2016): 25:44
Morgan, J. P. "CreditMetrics-technical document." JP Morgan, New York, 1997
First Boston Financial Products, "CreditRisk+", 1997
Gundlach & Lehrbass, "CreditRisk+ in the Banking Industry", Springer, 2003
Get the idiosyncratic risk weights (i.e. risk weights which are not assigned
to any sector). Currently only available if model.type
== "CRP".
idiosyncr(this)
idiosyncr(this)
this |
Object of class |
numeric vector of length equal to number of counterparties
GCPM
The function helps to create a new object of class GCPM
. The arguments
of the function are passed to the object after performing some plausibility checks.
init(model.type = "CRP", link.function = "CRP", N, seed, loss.unit, alpha.max = 0.9999, loss.thr = Inf, sec.var, random.numbers = matrix(), LHR, max.entries=1e3)
init(model.type = "CRP", link.function = "CRP", N, seed, loss.unit, alpha.max = 0.9999, loss.thr = Inf, sec.var, random.numbers = matrix(), LHR, max.entries=1e3)
model.type |
Character value, specifying the model type. One can choose between “simulative” and “CRP” which corresponds to the analytical version of the CreditRisk+ model (see First Boston Financial Products, 1997) |
link.function |
character value, specifying the type of the link function. One can choose
between “CRP”, which corresponds to |
N |
numeric value, defining the number of simulations if
|
seed |
numeric value used to initialize the random number generator. If |
loss.unit |
numeric positive value used to discretize potential losses. |
alpha.max |
numeric value between 0 and 1 defining the maximum CDF-level which will be computed in case of an analytical CreditRisk+ type model. |
loss.thr |
numeric value specifying a lower bound for portfolio losses to be stored in
order to derive risk contributions on counterparty level. Using a lower value
needs a lot of memory but will be necessary in order to calculate risk
contributions on lower CDF levels. This parameter is used only if
|
sec.var |
named numeric vector defining the sector variances in case of a CreditRisk+
type model. The names have to correspond to the sector names given in the
portfolio. This parameter is used only if |
random.numbers |
matrix with sector drawings. The columns represent the sectors,
whereas the rows represent the scenarios (number of different simulations).
The column names must correspond to the names used in the portfolio data
(see |
LHR |
numeric vector of length equal to |
max.entries |
numeric value defining the maximum number of loss scenarios stored to calculate risk contributions. |
object of class GCPM
Kevin Jakob
Jakob, K. & Fischer, M. "GCPM: A flexible package to explore credit portfolio risk" Austrian Journal of Statistics 45.1 (2016): 25:44
Morgan, J. P. "CreditMetrics-technical document." JP Morgan, New York, 1997
First Boston Financial Products, "CreditRisk+", 1997
Gundlach & Lehrbass, "CreditRisk+ in the Banking Industry", Springer, 2003
#create a random portfolio with NC counterparties NC=100 #assign business lines and countries randomly business.lines=c("A","B","C") CP.business=business.lines[ceiling(runif(NC,0,length(business.lines)))] countries=c("A","B","C","D","E") CP.country=countries[ceiling(runif(NC,0,length(countries)))] #create matrix with sector weights (CreditRisk+ setting) #according to business lines NS=length(business.lines) W=matrix(0,nrow = NC,ncol = length(business.lines), dimnames = list(1:NC,business.lines)) for(i in 1:NC){W[i,CP.business[i]]=1} #create portfolio data frame portfolio=data.frame(Number=1:NC,Name=paste("Name ",1:NC),Business=CP.business, Country=CP.country,EAD=runif(NC,1e3,1e6),LGD=runif(NC), PD=runif(NC,0,0.3),Default=rep("Bernoulli",NC),W) #draw sector variances randomly sec.var=runif(NS,0.5,1.5) names(sec.var)=business.lines #draw N sector realizations (independent gamma distributed sectors) N=5e4 random.numbers=matrix(NA,ncol=NS,nrow=N,dimnames=list(1:N,business.lines)) for(i in 1:NS){ random.numbers[,i]=rgamma(N,shape = 1/sec.var[i],scale=sec.var[i])} #create a portfolio model and analyze the portfolio TestModel=init(model.type = "simulative",link.function = "CRP",N = N, loss.unit = 1e3, random.numbers = random.numbers,LHR=rep(1,N),loss.thr=5e6, max.entries=2e4) TestModel=analyze(TestModel,portfolio) #plot of pdf of portfolio loss (in million) with indicators for EL, VaR and ES alpha=c(0.995,0.999) plot(TestModel,1e6,alpha=alpha) #calculate portfolio VaR and ES VaR=VaR(TestModel,alpha) ES=ES(TestModel,alpha) #Calculate risk contributions to VaR and ES risk.cont=cbind(VaR.cont(TestModel,alpha = alpha), ES.cont(TestModel,alpha = alpha))
#create a random portfolio with NC counterparties NC=100 #assign business lines and countries randomly business.lines=c("A","B","C") CP.business=business.lines[ceiling(runif(NC,0,length(business.lines)))] countries=c("A","B","C","D","E") CP.country=countries[ceiling(runif(NC,0,length(countries)))] #create matrix with sector weights (CreditRisk+ setting) #according to business lines NS=length(business.lines) W=matrix(0,nrow = NC,ncol = length(business.lines), dimnames = list(1:NC,business.lines)) for(i in 1:NC){W[i,CP.business[i]]=1} #create portfolio data frame portfolio=data.frame(Number=1:NC,Name=paste("Name ",1:NC),Business=CP.business, Country=CP.country,EAD=runif(NC,1e3,1e6),LGD=runif(NC), PD=runif(NC,0,0.3),Default=rep("Bernoulli",NC),W) #draw sector variances randomly sec.var=runif(NS,0.5,1.5) names(sec.var)=business.lines #draw N sector realizations (independent gamma distributed sectors) N=5e4 random.numbers=matrix(NA,ncol=NS,nrow=N,dimnames=list(1:N,business.lines)) for(i in 1:NS){ random.numbers[,i]=rgamma(N,shape = 1/sec.var[i],scale=sec.var[i])} #create a portfolio model and analyze the portfolio TestModel=init(model.type = "simulative",link.function = "CRP",N = N, loss.unit = 1e3, random.numbers = random.numbers,LHR=rep(1,N),loss.thr=5e6, max.entries=2e4) TestModel=analyze(TestModel,portfolio) #plot of pdf of portfolio loss (in million) with indicators for EL, VaR and ES alpha=c(0.995,0.999) plot(TestModel,1e6,alpha=alpha) #calculate portfolio VaR and ES VaR=VaR(TestModel,alpha) ES=ES(TestModel,alpha) #Calculate risk contributions to VaR and ES risk.cont=cbind(VaR.cont(TestModel,alpha = alpha), ES.cont(TestModel,alpha = alpha))
Get the values of LGD, defined within the portfolio
LGD(this)
LGD(this)
this |
Object of class |
numeric vector of length equal to number of counterparties
Get the likelihood ratio for each scenario defined in random.numbers
(see init
)
LHR(this)
LHR(this)
this |
Object of class |
numeric vector of length equal to nrow(random.numbers)
Get the models link function (see init
)
link.function(this)
link.function(this)
this |
Object of class |
character value of length 1
Get the loss levels of the portfolio loss distribution.
loss(this)
loss(this)
this |
Object of class |
numeric vector
Get the value of loss.thr
(see init
)
loss.thr(this)
loss.thr(this)
this |
Object of class |
numeric value of length 1
Get the value of model.type
(see init
)
model.type(this)
model.type(this)
this |
Object of class |
character value of length 1
Get the value of N
(number of simulations, see init
)
N(this)
N(this)
this |
Object of class |
numeric value of length 1
Get the value of name
, i.e. the counterparties' names, defined in the
portfolio (see analyze
)
name(this)
name(this)
this |
Object of class |
character value of length equal to number of counterparties
Get the value of NC
, representing the number of counterparties within
the portfolio (see analyze
)
NC(this)
NC(this)
this |
Object of class |
numeric value of length 1
Get the value of NR
, the counterparties' identification numbers within the
portfolio (see analyze
)
NR(this)
NR(this)
this |
Object of class |
numeric value of length equal to number of counterparties
Get the value of NS
, the number of sectors within the model
(see init
)
NS(this)
NS(this)
this |
Object of class |
numeric value of length 1
Get the value of PD
, the counterparties default probabilities within the
portfolio (see analyze
. Please note, that these PDs are adjusted
because of discretization in order to preserve the expected loss.)
PD(this)
PD(this)
this |
Object of class |
numeric value of length equal to the number of counterparties
Get the value of PDF
, representing the pdf of the estimated portfolio
loss distribution.
PDF(this)
PDF(this)
this |
Object of class |
numeric vector
Get the value of PL
, the potential losses of counterparties
(see GCPM-class
). Please note, that the potential losses are
discretized according to loss.unit
(see init
).
PL(this)
PL(this)
this |
Object of class |
numeric value of length equal to the number of counterparties
Plot of the estimated pdf of the portfolio loss distribution.
plot(x,y,...)
plot(x,y,...)
x |
Object of class |
y |
plot unit for losses (x-axis), default value = 1 |
... |
Further arguments such as: |
The dataset contains an example portfolio in the structure needed by the analyze
function.
data("portfolio.pois")
data("portfolio.pois")
A data frame with 3000 counterparties and the following variables.
Number
Counterparty ID (numeric)
Name
Counterparty name (character)
Business
Business line (character)
Country
Country (character)
EAD
Exposure at default (numeric)
LGD
Loss given dafault (numeric)
PD
Probability of default (numeric)
Default
Default mode (‘Poisson’ or ‘Benroulli’)
A
sector weights for sector A
B
sector weights for sector B
C
sector weights for sector C
In order to speed up calculations, counterparties of portfolio.pois
with EAD*LGD < 200,000 are grouped together (pooled).
data("portfolio.pool")
data("portfolio.pool")
A data frame with 1400 counterparties and 3 pools (each per sector) and the following variables.
Number
Counterparty ID (numeric)
Name
Counterparty name (character)
Business
Business line (character)
Country
Country (character)
EAD
Exposure at default (numeric); pool: average EAD per counterparty
LGD
Loss given dafault (numeric); pool: EAD-weighted average LGD per counterparty
PD
Probability of default (numeric); pool: expectation of number of defaults
Default
Default mode (‘Poisson’ for pools or ‘Benroulli’)
A
sector weights for sector A
B
sector weights for sector B
C
sector weights for sector C
The workspace contain the example portfolio (with Poisson default mode) in the structure needed by the analyze
function as well as a pooled version.
data("portfolios")
data("portfolios")
Two data frames containing the portfolios.
portfolio.pois
, portfolio.pool
, analyze
Get the content of random.numbers
, representing the sector drawings
(see init
)
random.numbers(this)
random.numbers(this)
this |
Object of class |
numeric matrix
Get the value of SD
, the portfolio standard deviation derived from the
loss distribution.
SD(this)
SD(this)
this |
Object of class |
numeric value of length 1
Get the value of SD.analyt
, the portfolio standard deviation derived
from the portfolio data (see GCPM-class
). This value is only
available in case of an analytical model.
SD.analyt(this)
SD.analyt(this)
this |
Object of class |
numeric value of length 1
Get the counterparties' contributions to portfolio standard deviation
(see GCPM-class
). These values are only available in case of an
analytical model.
SD.cont(this)
SD.cont(this)
this |
Object of class |
numeric value of length equal to number of counterparties
Get the value of SD.div
, the diversifiable part of portfolio standard
deviation (see GCPM-class
)
SD.div(this)
SD.div(this)
this |
Object of class |
numeric value of length 1
Get the value of SD.syst
, the non-diversifiable part of portfolio
standard deviation.
SD.syst(this)
SD.syst(this)
this |
Object of class |
numeric value of length 1
Get the value of sec.var
, the sector variances in case of an analytical CreditRisk+
like model (see init
)
sec.var(this)
sec.var(this)
this |
Object of class |
numeric value of length equal to number of sectors
Get the value of sector.names
, the sector names (see init
)
sector.names(this)
sector.names(this)
this |
Object of class |
factor of length equal to number of sectors
Get the value of seed
(see init
)
seed(this)
seed(this)
this |
Object of class |
numeric value of length 1
Displays the most important parameters and portfolio statistics (if available).
Create a Summary List with Model Parameters.
summary(object,...)
summary(object,...)
object |
Object of class |
... |
No further arguments |
list
Calculate the portfolio value at risk on level(s) alpha
.
VaR(this,alpha)
VaR(this,alpha)
this |
Object of class |
alpha |
numeric vector with entries between 0 and 1 |
numeric value of length equal to length of alpha
Get the counterparties' contributions to portfolio value at risk
(see GCPM-class
). In case of a simulative model, these values are
calculated from individual losses greater or equal loss.thr
(see init
). Contributions are not available if loss.thr
is too high.
VaR.cont(this,alpha)
VaR.cont(this,alpha)
this |
Object of class |
alpha |
numeric vector with entries between 0 and 1 |
numeric matrix
Get the value of W
, the matrix of counterparties' sector weights defined
within the portfolio (see analyze
)
W(this)
W(this)
this |
Object of class |
numeric matrix