# Bootstrapping a Default Probability Curve from Credit Default Swaps

This example shows how to bootstrap a default probability curve for `CDS` instruments.

### Create a `ratecurve` Object for a Zero Curve

Create a `ratecurve` object using `ratecurve`.

```Settle = datetime(2017,9,15); ZeroTimes = [calmonths(6) calyears([1 2 3 4 5 7 10 20 30])]; ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]'; ZeroDates = Settle + ZeroTimes; ZeroCurve = ratecurve("zero",Settle,ZeroDates,ZeroRates)```
```ZeroCurve = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 0 Dates: [10x1 datetime] Rates: [10x1 double] Settle: 15-Sep-2017 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous" ```

### Market CDS Spreads and a Vector of Market CDS Instruments

Define the market CDS spreads and use `fininstrument` to create a vector of market `CDS` instrument objects.

```SpreadTimes = [1 2 3 4 5 7 10 20 30]'; Spread = [140 175 210 265 310 360 410 460 490]'; MarketDates = datemnth(Settle,12*SpreadTimes); NumMarketInst = length(MarketDates); ContractSpreadBP = 50.*ones(NumMarketInst,1); MarketCDSInstruments(NumMarketInst,1) = fininstrument("cds", ... 'ContractSpread', ContractSpreadBP(end), 'Maturity', MarketDates(end)); for k = 1:NumMarketInst MarketCDSInstruments(k,1) = fininstrument("cds", ... 'ContractSpread', ContractSpreadBP(k), 'Maturity', MarketDates(k)); end MarketCDSInstruments```
```MarketCDSInstruments=9×1 object 9x1 CDS array with properties: ContractSpread Maturity Period Basis RecoveryRate BusinessDayConvention Holidays PayAccruedPremium Notional Name ```

### Bootstrap a Default Probability Curve

Use `defprobstrip`, `hazardrates`,and `survprobs` to analyse a default probability curve for the market `CDS` instruments.

`DefaultProbCurve = defprobstrip(ZeroCurve, MarketCDSInstruments, Spread)`
```DefaultProbCurve = defprobcurve with properties: Settle: 15-Sep-2017 Basis: 2 Dates: [9x1 datetime] DefaultProbabilities: [9x1 double] ```
`HazardRates = hazardrates(DefaultProbCurve)`
```HazardRates = 9×1 0.0233 0.0352 0.0474 0.0751 0.0879 0.0887 0.1023 0.1059 0.2271 ```
`SurvivalProbabilities = survprobs(DefaultProbCurve, MarketDates)`
```SurvivalProbabilities = 9×1 0.9766 0.9424 0.8981 0.8322 0.7612 0.6358 0.4658 0.1590 0.0159 ```