Credit Risk Analytics

Credit Risk Analytics with Python — Survival Probabilities via Bootstrapping CDS spreads

Ameya Abhyankar
6 min readSep 19, 2020


Idea of credit risk is not new to us. Many times, during our everyday lives we are exposed to this risk. Imagine back in our college days when we lent some of our pocket money to a friend because he/she had to buy something and was falling short of funds. We used to be surely concerned if we were indeed going to receive our money back! This was the potential loss from credit risk that was bothering us! Those were good old days 😊.

The financial industry too is no stranger to the perils of credit risk. Banking and Financial market is an avenue where millions of dollars get lent / borrowed on an everyday basis. Banks and financial institutions exercise due care and diligence at their end when it comes to lending funds to a customer/ counterparty. However, market conditions are uncertain. As market conditions change, they can have a positive or a negative impact on the overall position of the counterparty. If conditions change for the worse, then this may make weaken the financial condition of the counterparty making it difficult for them to honor their loan re-payment commitments. This type of risk is classified as credit risk. Banks and financial institutions closely monitor credit risk in transactions because it’s their money that is at stake.

Credit Risk manifests in many forms!

Most of us equate credit risk as the risk of complete default on payment by a counterparty. Whereas, this is correct, there is something more to add to this definition. In the financial market, the following points that are also analyzed by banks as a part of their credit risk analysis.

a. Risk of complete default on payments

b. Risk of partial default on payments

c. Credit rating downgrade

d. Widening credit spreads

Mitigants against credit risk

In order to manage credit risk, banks and financial institutions take various measures. A few of these measures may range from:

a. Trading with highly rated counterparties

b. Over-collateralization

c. Periodic netting etc.

d. Trading Credit Default Swaps

In this article, we will discuss about the intricacies in Credit Default Swaps (CDS) as a product. CDS is one of the most widely used product by market participants to hedge their credit risk. Although, CDS products were one of the main asset classes that played a big role in the meltdown of 2008, when used appropriately, CDS helps in effectively hedging credit risk in transactions.

The first part of this post explains the basics about the structure of a CDS, and the second part of this article will be a walkthrough of computation of survival probability using Python.

Understanding Credit Default Swap

Credit Default Swap is a derivative product. For a CDS trade to happen, there must be a underlying product. The underlying product is generally a bond or a securitized product etc. CDS may be used for either trading or risk management.

For example, consider a CDS contract between two parties say party A and party B. Let Party A be the protection buyer and Party B be the protection seller.

The following is the cash flow payment patterns for the above example CDS trade:

Party A:

1. No Credit Event: Party A will continue to make premium payment at pre-defined points of time until contract maturity.

2. Credit Event Occurs: Party A will not pay premium payments due in the future anymore.

Party B:

1. No Credit Event: Party B will continue to receive premium payment at pre-defined points of time until contract maturity.

2. Credit Event Occurs: Party B will have to make good the loss to Party A owing to the credit event occurring.

Credit event could be any of the four events listed above and repeated here for easy reference.

a. Complete default on payments

b. Partial default on payments

c. Credit rating downgrade

d. Widening credit spreads

The above given are just four examples, in reality, the parties A and B can define any other credit events in the contract at the time of entering into the trade. CDS trades are done Over the Counter, so they can be customized to the requirements of the trading counterparties.

Poisson process and hazard rates

For analysis of credit events we use a probabilistic process by the name of Poisson process. Poisson process is a discrete time process which gives the probability of default between two time intervals conditional on surviving uptil the initial time point. Mathematically, Poisson process is given as:

Pr[τ < t+dt | τ >=t ] = λ(t) dt

Interpretation of the above equation is probability of default between time interval [t,t+dt] conditional on survival uptil time ‘t’. The term λ(t) is called as the hazard rate/default intensity. As a part of modelling survival probabilities, we make an assumption that hazard rates are deterministic quantities. We assume they are independent of interest rates and recovery rates. Basis these assumptions we get a formula for probability of survival uptil time ‘T’, conditional on survival uptil time ‘ts’ as:

Formula for probability of survival

Role of survival probability (i.e. probability of survival) in pricing CDS

The survival probability is a very key quantity in calculation of cash flows and therefore the valuation of a CDS contract. By referring to the above section on Understanding Credit Default Swap, we observe that there are cash flows structures that happen depending on a condition (i.e. credit event) occurring / not-occurring. Occurrence of a credit event is related to the concept of probability of default (i.e. which is the complement of probability of survival). We call it as a complement because:

Probability of survival + probability of default = 1

The quantity survival probability is not directly observable in the market. This is a quantity that has to be implied from traded credit spreads in the market. Credit spreads here imply the spreads on CDS contracts trading in the market. We use the CDS spreads and run a bootstrapping algorithm to calculate the survival probability. We then use these survival probabilities in pricing of CDS contracts.

Implementation of Credit Bootstrapping algorithm

Below, we will discuss the Python code that can be used for executing the bootstrapping algorithm to determine the survival probabilities.

1. Inputs are hypothetical CDS spreads of different maturities. Input file can be found on my Github repository at: (filename: CDS_Spreads.csv)

2. Import libraries, import data, configure pandas dataframe.

3. Bootstrapping algorithm for computing survival probabilities from the CDS spreads:

4. Tabulate the output and plot the survival probabilities chart

Survival Probabilities computed through bootstrapping credit spreads

The column in green is the survival probabilities computed via the bootstrapping algorithm. This will be used as an input for valuation of CDS contracts. The plot of survival probabilities is given in the chart below.

Plot of Survival probability vs CDS maturity

Thus, in this post, we learnt the importance of CDS contracts in hedging credit risk in an investment. Further, we discussed, the basic math behind valuation of a CDS contracts. Using Python makes it very easy to implement the credit curve bootstrapping algorithm. Further, a code written in Python becomes easily scalable. Leveraging the strong data visualization libraries in Python, its convenient to plot the survival probabilities which helps in visual analysis of risk for an analyst. The algorithm given in this article may be used as a generic algorithm for computing survival probabilities by using the CDS spreads quoted in the market.

This article was first posted on my training Institute’s website. Many other interesting articles on quantitative finance and analytics can be found in the Blog section of my website. Happy Reading ! :)