Credit Default Swap Valuation Using Copula Fitting Method

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Credit Default Swap (CDS)

Valuation Through The Use Of


Copula Fitting

Bruce Haydon
Citigroup Treasury

CQF Modeling July 2015

Page <1>

Bruce Haydon

January 2015 Cohort


13-July-2015

Part 1 - CVA Calculation for Interest Rate Swap


Hazard Rate
A general Hazard Rate of 3% was used to calculate the Probability of Default
through bootstrapping.
t

Probability of Survival: PS=e

Forward Rates Simulation Data


For this calculation, we will be using the 6M LIBOR rate (fixed at T, paid at T+0.5) at
each 6-month rate fixing point. Because this is a constant maturity 6M Forward
LIBOR, random interest rate simulations were pulled from the HJM MC spreadsheet
on the column corresponding to 6M tenor (tau=0.5).
Sampling is done from this column (tenor=0.5), with 10 samples being selected at a
time to build a distribution. From this an empirical median was calculated, and used
in the table as the basis for calculating the floating payment.

Discounting
For the Exposure Profile, discounting is applied to the time the cashflow is received,
not the present time. As such, the first cashflow will be discounted using DF(0,0.5),
which is the rate of the 6M Libor just fixed (cash to be paid out at 0.5Y).
Discount rates were obtained from the Bank of Englands OIS Spot Curve, found at
http://www.bankofengland.co.uk.

CQF Modeling July 2015

Page <2>

Bruce Haydon

Part 2 - CDS Basket Pricing


(1)Obtaining Hazard Rates & Probability of Default Curve

(2)Obtaining Historical PD Data from Deutsche Bank

(3)Conversion of Historical Data to PDs


Use of PDs
(4)Obtaining Correlation Matrix From Historical Data
A correlation matrix for the historical data is required for the Gaussian
Copula. Once historical data was put into columns,

PDs from all 5

reference assets were sampled on a weekly basis. Sampling daily was


considered too fine-grained. The MATLAB corrcoef function was used to
read in the historical data, and generate a 5x5 correlation matrix R.
(5)Perform Kernel Smoothing on Historical Data
The PD changes (dPDs) should be approximately normally distributed.
Plotting histograms of each shows some were more normally distributed than
others.
A kernel distribution produces a nonparametric probability density estimate
that adapts itself to the data, rather than selecting a density with a particular
parametric form and estimating the parameters. This distribution is defined
by a kernel density estimator, a smoothing function that determines the
shape of the curve used to generate the pdf, and a bandwidth value that
controls the smoothness of the resulting density curve.
Similar to a histogram, the kernel distribution builds a function to represent
the probability distribution using the sample data. But unlike a histogram,
which places the values into discrete bins, a kernel distribution sums the
component smoothing functions for each data value to produce a smooth,
continuous probability curve. The following plot shows a visual comparison of
a histogram and a kernel distribution generated from the same sample data.
Kernel Density Estimator
The kernel density estimator is the estimated probability density function
(pdf) of the random variable. Its formula is given by the equation:

CQF Modeling July 2015

Page <3>

Bruce Haydon

where n is the sample size, K() is the kernel smoothing function, h is the
bandwidth.
Kernel Smoothing Function
The kernel smoothing function defines the shape of the curve used to
generate the pdf. Similar to a histogram, the kernel distribution builds a
function to represent the probability distribution using the sample data. But
unlike a histogram, which places the values into discrete bins, a kernel
distribution sums the component smoothing functions for each data value to
produce a smooth, continuous probability curve. The following plots show a
visual comparison of a histogram and a kernel distribution generated from
the same sample data.
A histogram represents the probability distribution by establishing bins and
placing each data value in the appropriate bin. Below is a histogram of the
first sample set of dPDs (Italy) represented as a histogram:
MATLAB code used to generate histogram for original dPD historical data for
Obligor 3 (Portugal 5Y):
>> figure;
histogram (PDDELTAS(:,3))
str = sprintf('Histogram Original Samples Asset %d', 3);
title(str);
Resultant generated Histogram:

CQF Modeling July 2015

Page <4>

Bruce Haydon

The entire set of histograms for the original historical data sample sets can
be found in Appendix A.
Because of this bin count approach, the histogram produces a discrete
probability density function. This might be unsuitable for our purpose, in
generating random numbers from a fitted distribution using a Copula.
Alternatively, the kernel distribution builds the pdf by creating an individual
probability density curve for each data value, then summing the smooth
curves. This approach creates one smooth, continuous probability density
function for the data set.
We can see the result of kernel smoothing in the graph of asset 3 below,
where a kernel-smoothed curve is overlaid on the original histogram. The
solid line represents the smoothed pdf. The full set of smoothed curves can
be found in Appendix A as well

(6)Obtaining U: Generating a CDF from Kernel-Smoothed PDF


At this point we now have a kernel-smoothed PDF for each of the 5 sample
sets of X, and we need to convert our normally-distributed sample set to
uniform-distributed pseudo-samples u.
By executing the following block of code, we use MATLABs cdf function to
find corresponding CDF values of the empirically derived and smoothed PDF
curve (above) for each X historical sample value. This essentially translates
each sample value X into a unique pseud-sample u-historical, which

CQF Modeling July 2015

Page <5>

Bruce Haydon

should be normally distributed. The resulting matrix (nx5) of u-historical


values generated is stored in a table uhist

CQF Modeling July 2015

Page <6>

Bruce Haydon

MATLAB code for generating pseudo-samples u-hist:


>> figure;
histogram (PDDELTAS(:,3))
str = sprintf('Histogram Original Samples Asset %d', 3);
title(str);
A portion of the resultant (nx5) table uhist is shown below:

CQF Modeling July 2015

Page <7>

Bruce Haydon

(7)Copula

Fitting: Obtaining the Correlation Matrix

Now that we have our matrix of pseudo-samples u, there are two ways we
can proceed to obtain the correlation matrix necessary for the Copulas. The
first method is to convert the u-hist matrix into a matrix of Z-hist values
distributed on N[0,1] using the inverse normal CDF function, and finding
linear correlation of that matrix. The second method uses MATLAB functions
that operate on the pseudosamples u-hist directly without transformation
into Z-hist to generate correlation matrices for both Gaussian and t-copulas.
(a) Generate Z-hist, and obtain correlation from resulting matrix
For this, we use the transformation
pseudo-samples, and is known as
correlation matrix

=( Z

hist

Z =1 (U )

obtained from

Z hist (or z-hist). We obtain

) .

This is done through a one-line command in MATLAB below:


zhist(:,:)= norminv(uhist(:,:),0,1); %generate Z-historical
matrix
At this point we have our matrix of

Z hist , whereupon we find the

correlation matrix through the MATLAB function corrcoef.

rhohatZhist = corrcoef(zhist); %Generate correlation matrix


from Z-hist
The resulting (5x5) correlation matrix rhohatZhist is shown below:

CQF Modeling July 2015

Page <8>

Bruce Haydon

(b) Use MATLABs copulafit function to obtain correlation matrix


As an alternative, we can work of the
to

Z hist

U hist

data directly without converting

by using the copulafit function to obtain correlation matrix

for the Gaussian Copula. In addition, this same function also allows us to
obtain the correlation matrix and degrees of freedom for a t-Copula through a
separate invocation specifying that Copula type.

rhohatGaussian = copulafit('Gaussian',uhist);
[rhohatTcop,dfhat]= copulafit('t',uhist);

The resulting correlation matrix rhohatGaussian for the Gaussian Copula is


shown below:

Interestingly enough, we can see it is identical to the correlation matrix


obtained through the previous method using

Z hist . This gives some

validation to both sets of results.


The resulting correlation matrix fot the t-Copula, rhohatTcop, is shown
below:

CQF Modeling July 2015

Page <9>

Bruce Haydon

It is different than the first correlation matrix rhohatGaussian for the


Gaussian Copula, because the T-copula uses rank correlation whereas the
Gaussian Copula utilizes linear correlation. Therefore, it is not surprising the
two correlation matrices are different.
The degrees of freedom calculated for the T-Copula, dfhat, is shown below.
This pre-empts the step of otherwise having to use the Log-Likelihood
function to calculate to value manually through the determination of the
maximum point on a Log-Likelihood graph.

This means that the t-Copula degrees of freedom parameter is estimated to


be about 20.
(8) Cholesky Decomposition Of Correlation Matrix
At this point we need to use Cholesky Decomposition to satisfy

^= AA ' .

Before we can perform Cholesky Decomposition, we need to ensure the


matrix is Positive Definite. The chol function in MATLAB not only calculates
the Cholesky matrix, but also returns a value (represented here by
posdefindicator which indicates if correlation matrix is Positive-Definite, a
requirement of Cholesky Decomposition.

% This block of code performs Cholesky Decomposition on the Gaussian


% correlation matrix we have already calculated in a previous step.
load rhohatGaussian;

CQF Modeling July 2015

% load previously calculated correlation matrix

Page <10>

Bruce Haydon

[Rcholesky,posdefindicator]

= chol(rhohatGaussian);

% Now check to ensure RHO ("rhohatGuassian


if (posdefinindicator > 0) then
error ('RHO is not positive-definite');
end

After this block of code was run, the following (5x5) matrix Rcholesky,
which represents A in the equation:

^= AA '
.
^= AA '

As a quick test, lets validate the condition

using the MATLAB

interactive command line:

>> invRho=transpose(Rcholesky)
invRho =
1.0000
0.1928
0.5265
-0.0809
0.1307

0
0.9812
0.2170
0.0639
0.4645

0
0
0.8220
0.0142
0.1659

0
0
0
0.9946
0.1805

0
0
0
0
0.8409

-0.0809
0.0471
-0.0170
1.0000
0.2011

0.1307
0.4810
0.3059
0.2011
1.0000

>> test=invRho*Rcholesky
test =
1.0000
0.1928
0.5265
-0.0809
0.1307

0.1928
1.0000
0.3144
0.0471
0.4810

0.5265
0.3144
1.0000
-0.0170
0.3059

We can see that the matrix text, which is a product of the generated
Cholesky matrix times its transpose, equals our original correlation matrix

^
rhohatGaussian ( ) ,confirming that

^= AA '

holds.

(9) Generate Random Numbers From Guassian Copula

CQF Modeling July 2015

Page <11>

Bruce Haydon

With the correlation matrices and Cholesky Decomposition matrix calculated


above, we can now begin generating sample data using the Copula.
Our first method involves generating 10,000 samples of a uniformly
distributed Type equation here .

CQF Modeling July 2015

Page <12>

Bruce Haydon

After the command was run, the following (nx10000) matrix was generated.

Each row represents a vector U.To confirm the variables are uniformly
distributed, I generated a histogram of the data in column 1:
% Generate histogram on first column as test to ensure uniform distribution
figure;
histogram (Urandom(:,1));
str = sprintf('Histogram Random Generated Samples Asset 1');
title(str);

After the code above was executed, the following histogram was generated:

CQF Modeling July 2015

Page <13>

Bruce Haydon

By using column 1 as a sample, the generated histogram demonstrates that the


generated vectors are in fact uniformly distributed.
Now that we have our uniformly distributed U vector, we need to convert it to a
vector of independent standard Normal-distributed variables Z. To do so we use
the Inverse Normal CDF function

Z =invnormalCDF(U ) .

% Now convert "U" into vector of standard Normal distributed variables "Z"
% through the use of the Normal inverse cumulative distribution function.
ZSimulation=norminv(Urandom,0,1);

%Z=NormInverseCDF(U)

% Generate histogram on first column of generated data as test to


% ensure Normal distribution
figure;
histogram (ZSimulation(:,1));
str = sprintf('Histogram Random Generated Samples Asset 1 - Normal');
title(str);

The following histogram was generated by column 1 of the transformed random


sample data, confirming the independent variables constituting the vector Z (or
ZSimulation as used in the MATLAB program) is a Normal distribution.

The next step involves computing a vector of correlated variables X =AZ

CQF Modeling July 2015

Page <14>

Bruce Haydon

An empirical cumulative distribution function (ecdf) estimates the cdf of a


random variable by assigning equal probability to each observation in a
sample. Because of this approach, the ecdf is a discrete cumulative
distribution function that creates an exact match between the ecdf and the
distribution of the sample data.
The following plot shows a visual comparison of the ecdf of 20 random
numbers generated from a standard normal distribution, and the theoretical
cdf of a standard normal distribution. The circles indicate the value of the
ecdf calculated at each sample data point. The dashed line that passes
through each circle visually represents the ecdf, although the ecdf is not a
continuous function. The solid line shows the theoretical cdf of the standard
normal distribution from which the random numbers in the sample data were
drawn.

CQF Modeling July 2015

Page <15>

Bruce Haydon

(10)
(11)

CQF Modeling July 2015

Page <16>

Bruce Haydon

CQF Modeling July 2015

Page <17>

Bruce Haydon

APPENDIX A Original Sample Datasets

(A.1) Histograms of Original Sample Data


The following histograms were generated using the following code snippet as
found in the original script:
for ii=1:nAssets
figure;
histogram (PDDELTAS(:,ii))
str = sprintf('Histogram Original Samples Asset %d', ii);
title(str);
end;

CQF Modeling July 2015

Page <18>

Bruce Haydon

(A.2) Kernel-Smoothed PDFs Generated From Original Sample Data


The following code was used to generate the figures below:

end

for ii=1:nAssets
figure;
histogram (PDDELTAS(:,ii))
%Plot histogram first
hold on;
pdKS = fitdist(PDDELTAS(:,ii),'Kernel'); %generate fitted curve
x = -1:.05:1;
ySix = pdf(pdKS,x);
ySix = ySix*15;
% Scale pdf to overlay on histogram
plot(x,ySix,'k-','LineWidth',2);
str = sprintf('Kernel Smoothed PDF - Asset %d', ii);
title(str);

CQF Modeling July 2015

Page <19>

Bruce Haydon

CQF Modeling July 2015

Page <20>

Bruce Haydon

APPENDIX B Generated Sim Data using


copularnd
The following code was used to generate the simulation data from both the
Gaussian and T-Copulas using the built-in function copularnd().
%
load rhohatGaussian;
load rhohatTcop;
load dfhat;
estimate for T-Copula

% load previously calculated Rho for Gaussian Copula


% load previously calculated Rho for T-Copula
% load previously calculated degrees of freedom

nSimulations=10000

% number of simulated data sets to generate.

% Generate simulated "u's" using Gaussian Copula


% uSimGaussian = (nx5)matrix containing simulated u's from Gaussian Copula
uSimGuassian = copularnd('Gaussian',rhohatGaussian,nSimulations);
% Generate histograms of simulated data from Gaussian Copula to confirm
uniform distribution
for ii=1:nIssuers
figure;
histogram(uSimGuassian(:,ii));
str = sprintf('Gaussian Copula Generated data - Asset %d', ii);
title(str);
end

% Generate simulated "u's" using Gaussian Copula


% uSimtcopula = (nx5)matrix containing simulated u's from Gaussian Copula
uSimtcopula = copularnd('t',rhohatTcop,dfhat, nSimulations);
% Generate histograms of simulated data from T-Copula to confirm uniform
distribution
for ii=1:nIssuers
figure;
histogram(uSimtcopula(:,ii));
str = sprintf('T-Copula Generated data - Asset %d', ii);
title(str);
end

CQF Modeling July 2015

Page <21>

Bruce Haydon

The following histograms confirm uniform distribution in all generated datasets


(a) Gaussian Copula Generated using copularnd function

CQF Modeling July 2015

Page <22>

Bruce Haydon

(b)T- Copula Generated using copularnd function

CQF Modeling July 2015

Page <23>

Bruce Haydon

CQF Modeling July 2015

Page <24>

Bruce Haydon

You might also like