Quantcast
Channel: Path
Viewing all articles
Browse latest Browse all 83

Bootstrapping default probabilities from CDS prices in VBA

$
0
0
Default probabilities are needed when dealing with credit market models. This time, I wanted to present one simple algorithm for bootstrapping default probabilities from CDS market prices. Final product will be just one simple Excel/VBA worksheetfunction, which can be quickly copy-pasted and used in VBE standard module.


IMPLIED SURVIVAL PROBABILITY

Calculating implied survival probabilities from CDS prices follows the same idea, as calculating implied volatility from option price. For options, we have known market price, from which we can numerically solve the corresponding option volatility by using option pricing model. For CDS, we have known market price, from which we can solve the corresponding survival probability by using CDS pricing model. This is exactly the procedure, what this algorithm is doing. However, instead of just calculating one survival probability for a given CDS price, the algorithm is calculating all survival probabilities for a given CDS term structure. The pricing model for CDS is standard model (JP Morgan approach).


FUNCTION INPUT/OUTPUT

Zero-coupon bond prices, CDS prices and recovery rate assumption are needed as market data input for calculations. VBA function survivalProbability takes market information matrix (curves) and recovery rate assumption value (recovery) as input parameters. Function then returns an array of survival probabilities. Default probabilities can then be calculated from survival probabilities.

Input market information matrix (N x 3) should contain the following data in the following order:
  • 1st row vector - maturities in years
  • 2nd row vector - zero-coupon bond prices (ex. 0.9825)
  • 3rd row vector - CDS prices as basis points (ex. 0.25 % is given as 25)

After giving required input parameters for this function and selecting correct range for function output, remember to press CTRL+SHIFT+ENTER for retrieving result array (N x 1) into worksheet.


VBA FUNCTION


Option Explicit
'
' function takes market curves matrix (Nx3) and recovery rate (1x1) as arguments, then calculates and
' returns vector of survival probabilities (Nx1) for a given market data
' matrix input data order: 1st row vector = time, 2nd row vector = zero-coupon bond prices,
' 3rd row vector = cds rates in basis points
PublicFunction survivalProbability(ByRef curves As Range, ByVal recovery AsDouble) AsVariant
'
' information for dimensioning arrays
Dim nColumns AsInteger: nColumns = curves.Columns.Count
Dim nRows AsInteger: nRows = curves.Rows.Count
'
' create arrays for data
Dim p() AsDouble: ReDim p(0 To nRows)
Dim c() AsDouble: ReDim c(0 To curves.Rows.Count, 1 To curves.Columns.Count)
'
' copy variant array data into new array, having 1 additional item for today
c(0, 1) = 0: c(0, 2) = 1: c(0, 3) = 0
Dim cInput AsVariant: cInput = curves.Value2
'
Dim i AsInteger, j AsInteger, k AsInteger
For i = 1 To nRows
c(i, 1) = cInput(i, 1)
c(i, 2) = cInput(i, 2)
c(i, 3) = cInput(i, 3)
Next i
'
' calculation of survival probabilities (SP)
Dim L AsDouble: L = (1 - recovery)
Dim term AsDouble, terms AsDouble, divider AsDouble, term1 AsDouble, term2 AsDouble
'
For i = LBound(p) To UBound(p)
'
If (i = 0) Then p(i) = 1# ' SP today is one
If (i = 1) Then p(i) = L / ((c(i, 3) / 10000) * (c(i, 1) - c(i - 1, 1)) + L) ' first SP formula
'
If (i > 1) Then' SP after first period are calculated recursively
terms = 0
For j = 1 To (i - 1)
term = c(j, 2) * (L * p(j - 1) - (L + (c(j, 1) - c(j - 1, 1)) * (c(i, 3) / 10000)) * p(j))
terms = terms + term
Next j
'
divider = c(i, 2) * (L + (c(i, 1) - c(i - 1, 1)) * (c(i, 3) / 10000))
term1 = terms / divider
term2 = (p(i - 1) * L) / (L + (c(i, 1) - c(i - 1, 1)) * (c(i, 3) / 10000))
p(i) = term1 + term2
EndIf
Next i
'
' create output array excluding the first SP (for today)
Dim result() AsDouble: ReDim result(1 To UBound(p))
For i = 1 To UBound(p)
result(i) = p(i)
Next i
'
' finally, transpose output array (Nx1)
survivalProbability = Application.WorksheetFunction.Transpose(result)
EndFunction
'


CALCULATION EXAMPLE


The following Excel screenshot presents the calculation of default probabilities for Barclays and HSBC. Market data has been retrieved in early january 2014. VBA function input matrix (curves) has been marked with yellow color. Function output range has been marked with blue color. Default probability (PD) is calculated in column G.

















Thanks for reading.

-Mike

Viewing all articles
Browse latest Browse all 83

Trending Articles