QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Classes | Public Types | List of all members
CreditDefaultSwap Class Reference

Credit default swap. More...

#include <ql/instruments/creditdefaultswap.hpp>

+ Inheritance diagram for CreditDefaultSwap:
+ Collaboration diagram for CreditDefaultSwap:

Classes

class  arguments
 
class  engine
 
class  results
 

Public Types

enum  PricingModel { Midpoint , ISDA }
 
- Public Types inherited from Observer
typedef set_type::iterator iterator
 

Public Member Functions

Constructors
 CreditDefaultSwap (Protection::Side side, Real notional, Rate spread, const Schedule &schedule, BusinessDayConvention paymentConvention, const DayCounter &dayCounter, bool settlesAccrual=true, bool paysAtDefaultTime=true, const Date &protectionStart=Date(), ext::shared_ptr< Claim >=ext::shared_ptr< Claim >(), const DayCounter &lastPeriodDayCounter=DayCounter(), bool rebatesAccrual=true, const Date &tradeDate=Date(), Natural cashSettlementDays=3)
 CDS quoted as running-spread only. More...
 
 CreditDefaultSwap (Protection::Side side, Real notional, Rate upfront, Rate spread, const Schedule &schedule, BusinessDayConvention paymentConvention, const DayCounter &dayCounter, bool settlesAccrual=true, bool paysAtDefaultTime=true, const Date &protectionStart=Date(), const Date &upfrontDate=Date(), ext::shared_ptr< Claim >=ext::shared_ptr< Claim >(), const DayCounter &lastPeriodDayCounter=DayCounter(), bool rebatesAccrual=true, const Date &tradeDate=Date(), Natural cashSettlementDays=3)
 CDS quoted as upfront and running spread. More...
 
Inspectors
Protection::Side side () const
 
Real notional () const
 
Rate runningSpread () const
 
ext::optional< Rateupfront () const
 
bool settlesAccrual () const
 
bool paysAtDefaultTime () const
 
const Legcoupons () const
 
const DateprotectionStartDate () const
 The first date for which defaults will trigger the contract. More...
 
const DateprotectionEndDate () const
 The last date for which defaults will trigger the contract. More...
 
bool rebatesAccrual () const
 
const ext::shared_ptr< SimpleCashFlow > & upfrontPayment () const
 
const ext::shared_ptr< SimpleCashFlow > & accrualRebate () const
 
const DatetradeDate () const
 
Natural cashSettlementDays () const
 
Results
Rate fairUpfront () const
 
Rate fairSpread () const
 
Real couponLegBPS () const
 
Real upfrontBPS () const
 
Real couponLegNPV () const
 
Real defaultLegNPV () const
 
Real upfrontNPV () const
 
Real accrualRebateNPV () const
 
Rate impliedHazardRate (Real targetNPV, const Handle< YieldTermStructure > &discountCurve, const DayCounter &dayCounter, Real recoveryRate=0.4, Real accuracy=1.0e-8, PricingModel model=Midpoint) const
 Implied hazard rate calculation. More...
 
Rate conventionalSpread (Real conventionalRecovery, const Handle< YieldTermStructure > &discountCurve, const DayCounter &dayCounter, PricingModel model=Midpoint) const
 Conventional/standard upfront-to-spread conversion. More...
 
- Public Member Functions inherited from Instrument
 Instrument ()
 
Real NPV () const
 returns the net present value of the instrument. More...
 
Real errorEstimate () const
 returns the error estimate on the NPV when available. More...
 
const DatevaluationDate () const
 returns the date the net present value refers to. More...
 
template<typename T >
result (const std::string &tag) const
 returns any additional result returned by the pricing engine. More...
 
const std::map< std::string, ext::any > & additionalResults () const
 returns all additional result returned by the pricing engine. More...
 
void setPricingEngine (const ext::shared_ptr< PricingEngine > &)
 set the pricing engine to be used. More...
 
- Public Member Functions inherited from LazyObject
 LazyObject ()
 
 ~LazyObject () override=default
 
void update () override
 
bool isCalculated () const
 
void forwardFirstNotificationOnly ()
 
void alwaysForwardNotifications ()
 
void recalculate ()
 
void freeze ()
 
void unfreeze ()
 
- Public Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 
Observableoperator= (const Observable &)
 
 Observable (Observable &&)=delete
 
Observableoperator= (Observable &&)=delete
 
virtual ~Observable ()=default
 
void notifyObservers ()
 
- Public Member Functions inherited from Observer
 Observer ()=default
 
 Observer (const Observer &)
 
Observeroperator= (const Observer &)
 
virtual ~Observer ()
 
std::pair< iterator, boolregisterWith (const ext::shared_ptr< Observable > &)
 
void registerWithObservables (const ext::shared_ptr< Observer > &)
 
Size unregisterWith (const ext::shared_ptr< Observable > &)
 
void unregisterWithAll ()
 
virtual void update ()=0
 
virtual void deepUpdate ()
 

Instrument interface

Protection::Side side_
 
Real notional_
 
ext::optional< Rateupfront_
 
Rate runningSpread_
 
bool settlesAccrual_
 
bool paysAtDefaultTime_
 
ext::shared_ptr< Claimclaim_
 
Leg leg_
 
ext::shared_ptr< SimpleCashFlowupfrontPayment_
 
ext::shared_ptr< SimpleCashFlowaccrualRebate_
 
Date protectionStart_
 
Date tradeDate_
 
Natural cashSettlementDays_
 
Date maturity_
 
Rate fairUpfront_
 
Rate fairSpread_
 
Real couponLegBPS_
 
Real couponLegNPV_
 
Real upfrontBPS_
 
Real upfrontNPV_
 
Real defaultLegNPV_
 
Real accrualRebateNPV_
 
bool isExpired () const override
 returns whether the instrument might have value greater than zero. More...
 
void setupArguments (PricingEngine::arguments *) const override
 
void fetchResults (const PricingEngine::results *) const override
 
void setupExpired () const override
 
void init (const Schedule &schedule, BusinessDayConvention paymentConvention, const DayCounter &dayCounter, const DayCounter &lastPeriodDayCounter, bool rebatesAccrual, const Date &upfrontDate=Date())
 Shared initialisation. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Instrument
void calculate () const override
 
void performCalculations () const override
 
- Protected Member Functions inherited from LazyObject
- Protected Attributes inherited from Instrument
Real NPV_
 
Real errorEstimate_
 
Date valuationDate_
 
std::map< std::string, ext::any > additionalResults_
 
ext::shared_ptr< PricingEngineengine_
 
- Protected Attributes inherited from LazyObject
bool calculated_ = false
 
bool frozen_ = false
 
bool alwaysForward_
 

Detailed Description

Credit default swap.

Note
This instrument currently assumes that the issuer did not default until today's date.
Warning:
if Settings::includeReferenceDateCashFlows() is set to true, payments occurring at the settlement date of the swap might be included in the NPV and therefore affect the fair-spread calculation. This might not be what you want.
Warning:
conventionalSpread (and impliedHazardRate) by default use the mid-point engine, which is not ISDA conform.
Examples
CDS.cpp.

Definition at line 56 of file creditdefaultswap.hpp.

Member Enumeration Documentation

◆ PricingModel

Enumerator
Midpoint 
ISDA 

Definition at line 61 of file creditdefaultswap.hpp.

Constructor & Destructor Documentation

◆ CreditDefaultSwap() [1/2]

CreditDefaultSwap ( Protection::Side  side,
Real  notional,
Rate  spread,
const Schedule schedule,
BusinessDayConvention  paymentConvention,
const DayCounter dayCounter,
bool  settlesAccrual = true,
bool  paysAtDefaultTime = true,
const Date protectionStart = Date(),
ext::shared_ptr< Claim claim = ext::shared_ptr<Claim>(),
const DayCounter lastPeriodDayCounter = DayCounter(),
bool  rebatesAccrual = true,
const Date tradeDate = Date(),
Natural  cashSettlementDays = 3 
)

CDS quoted as running-spread only.

Parameters
sideWhether the protection is bought or sold.
notionalNotional value
spreadRunning spread in fractional units.
scheduleCoupon schedule.
paymentConventionBusiness-day convention for payment-date adjustment.
dayCounterDay-count convention for accrual.
settlesAccrualWhether or not the accrued coupon is due in the event of a default.
paysAtDefaultTimeIf set to true, any payments triggered by a default event are due at default time. If set to false, they are due at the end of the accrual period.
protectionStartThe first date where a default event will trigger the contract. Before the CDS Big Bang 2009, this was typically trade date (T) + 1 calendar day. After the CDS Big Bang 2009, protection is typically effective immediately i.e. on trade date so this is what should be entered for protection start. Notice that there is no default lookback period and protection start here. In the way it determines the dirty amount it is more like the trade execution date.
lastPeriodDayCounterDay-count convention for accrual in last period
rebatesAccrualThe protection seller pays the accrued scheduled current coupon at the start of the contract. The rebate date is not provided but computed to be two days after protection start.
tradeDateThe contract's trade date. It will be used with the cashSettlementDays to determine the date on which the cash settlement amount is paid. If not given, the trade date is guessed from the protection start date and schedule date generation rule.
cashSettlementDaysThe number of business days from tradeDate to cash settlement date.

Definition at line 39 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:

◆ CreditDefaultSwap() [2/2]

CreditDefaultSwap ( Protection::Side  side,
Real  notional,
Rate  upfront,
Rate  spread,
const Schedule schedule,
BusinessDayConvention  paymentConvention,
const DayCounter dayCounter,
bool  settlesAccrual = true,
bool  paysAtDefaultTime = true,
const Date protectionStart = Date(),
const Date upfrontDate = Date(),
ext::shared_ptr< Claim claim = ext::shared_ptr<Claim>(),
const DayCounter lastPeriodDayCounter = DayCounter(),
bool  rebatesAccrual = true,
const Date tradeDate = Date(),
Natural  cashSettlementDays = 3 
)

CDS quoted as upfront and running spread.

Parameters
sideWhether the protection is bought or sold.
notionalNotional value
upfrontUpfront in fractional units.
spreadRunning spread in fractional units.
scheduleCoupon schedule.
paymentConventionBusiness-day convention for payment-date adjustment.
dayCounterDay-count convention for accrual.
settlesAccrualWhether or not the accrued coupon is due in the event of a default.
paysAtDefaultTimeIf set to true, any payments triggered by a default event are due at default time. If set to false, they are due at the end of the accrual period.
protectionStartThe first date where a default event will trigger the contract. Before the CDS Big Bang 2009, this was typically trade date (T) + 1 calendar day. After the CDS Big Bang 2009, protection is typically effective immediately i.e. on trade date so this is what should be entered for protection start. Notice that there is no default lookback period and protection start here. In the way it determines the dirty amount it is more like the trade execution date.
upfrontDateSettlement date for the upfront and accrual rebate (if any) payments. Typically T+3, this is also the default value.
lastPeriodDayCounterDay-count convention for accrual in last period
rebatesAccrualThe protection seller pays the accrued scheduled current coupon at the start of the contract. The rebate date is not provided but computed to be two days after protection start.
tradeDateThe contract's trade date. It will be used with the cashSettlementDays to determine the date on which the cash settlement amount is paid if upfrontDate is empty. If not given, the trade date is guessed from the protection start date and schedule date generation rule.
cashSettlementDaysThe number of business days from tradeDate to cash settlement date.

Definition at line 62 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ isExpired()

bool isExpired ( ) const
overridevirtual

returns whether the instrument might have value greater than zero.

Implements Instrument.

Definition at line 207 of file creditdefaultswap.cpp.

◆ setupArguments()

void setupArguments ( PricingEngine::arguments ) const
overridevirtual

When a derived argument structure is defined for an instrument, this method should be overridden to fill it. This is mandatory in case a pricing engine is used.

Reimplemented from Instrument.

Definition at line 222 of file creditdefaultswap.cpp.

+ Here is the caller graph for this function:

◆ fetchResults()

void fetchResults ( const PricingEngine::results r) const
overridevirtual

When a derived result structure is defined for an instrument, this method should be overridden to read from it. This is mandatory in case a pricing engine is used.

Reimplemented from Instrument.

Definition at line 242 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:

◆ side()

Protection::Side side ( ) const

Definition at line 178 of file creditdefaultswap.cpp.

+ Here is the caller graph for this function:

◆ notional()

Real notional ( ) const

Definition at line 182 of file creditdefaultswap.cpp.

+ Here is the caller graph for this function:

◆ runningSpread()

Rate runningSpread ( ) const

Definition at line 186 of file creditdefaultswap.cpp.

◆ upfront()

ext::optional< Rate > upfront ( ) const

Definition at line 190 of file creditdefaultswap.cpp.

◆ settlesAccrual()

bool settlesAccrual ( ) const

Definition at line 194 of file creditdefaultswap.cpp.

◆ paysAtDefaultTime()

bool paysAtDefaultTime ( ) const

Definition at line 198 of file creditdefaultswap.cpp.

◆ coupons()

const Leg & coupons ( ) const

Definition at line 202 of file creditdefaultswap.cpp.

◆ protectionStartDate()

const Date & protectionStartDate ( ) const

The first date for which defaults will trigger the contract.

Definition at line 426 of file creditdefaultswap.cpp.

◆ protectionEndDate()

const Date & protectionEndDate ( ) const

The last date for which defaults will trigger the contract.

Definition at line 430 of file creditdefaultswap.cpp.

◆ rebatesAccrual()

bool rebatesAccrual ( ) const

Definition at line 187 of file creditdefaultswap.hpp.

+ Here is the caller graph for this function:

◆ upfrontPayment()

const ext::shared_ptr< SimpleCashFlow > & upfrontPayment ( ) const

Definition at line 435 of file creditdefaultswap.cpp.

+ Here is the caller graph for this function:

◆ accrualRebate()

const ext::shared_ptr< SimpleCashFlow > & accrualRebate ( ) const

Definition at line 439 of file creditdefaultswap.cpp.

◆ tradeDate()

const Date & tradeDate ( ) const

Definition at line 443 of file creditdefaultswap.cpp.

+ Here is the caller graph for this function:

◆ cashSettlementDays()

Natural cashSettlementDays ( ) const

Definition at line 447 of file creditdefaultswap.cpp.

◆ fairUpfront()

Rate fairUpfront ( ) const

Returns the upfront spread that, given the running spread and the quoted recovery rate, will make the instrument have an NPV of 0.

Definition at line 259 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fairSpread()

Rate fairSpread ( ) const

Returns the running spread that, given the quoted recovery rate, will make the running-only CDS have an NPV of 0.

Note
This calculation does not take any upfront into account, even if one was given.
Examples
CDS.cpp.

Definition at line 266 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ couponLegBPS()

Real couponLegBPS ( ) const

Returns the variation of the fixed-leg value given a one-basis-point change in the running spread.

Definition at line 273 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ upfrontBPS()

Real upfrontBPS ( ) const

Definition at line 301 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ couponLegNPV()

Real couponLegNPV ( ) const
Examples
CDS.cpp.

Definition at line 280 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defaultLegNPV()

Real defaultLegNPV ( ) const
Examples
CDS.cpp.

Definition at line 287 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ upfrontNPV()

Real upfrontNPV ( ) const

Definition at line 294 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ accrualRebateNPV()

Real accrualRebateNPV ( ) const

Definition at line 308 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ impliedHazardRate()

Rate impliedHazardRate ( Real  targetNPV,
const Handle< YieldTermStructure > &  discountCurve,
const DayCounter dayCounter,
Real  recoveryRate = 0.4,
Real  accuracy = 1.0e-8,
PricingModel  model = Midpoint 
) const

Implied hazard rate calculation.

Note
This method performs the calculation with the instrument characteristics. It will coincide with the ISDA calculation if your object has the standard characteristics. Notably:
  • The calendar should have no bank holidays, just weekends.
  • The yield curve should be LIBOR piecewise constant in fwd rates, with a discount factor of 1 on the calculation date, which coincides with the trade date.
  • Convention should be Following for yield curve and contract cashflows.
  • The CDS should pay accrued and mature on standard IMM dates, settle on trade date +1 and upfront settle on trade date +3.

Definition at line 340 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:

◆ conventionalSpread()

Rate conventionalSpread ( Real  conventionalRecovery,
const Handle< YieldTermStructure > &  discountCurve,
const DayCounter dayCounter,
PricingModel  model = Midpoint 
) const

Conventional/standard upfront-to-spread conversion.

Under a standard ISDA model and a set of standardised instrument characteristics, it is the running only quoted spread that will make a CDS contract have an NPV of 0 when quoted for that running only spread. Refer to: "ISDA Standard CDS converter specification." May 2009.

The conventional recovery rate to apply in the calculation is as specified by ISDA, not necessarily equal to the market-quoted one. It is typically 0.4 for SeniorSec and 0.2 for subordinate.

Note
The conversion employs a flat hazard rate. As a result, you will not recover the market quotes.
This method performs the calculation with the instrument characteristics. It will coincide with the ISDA calculation if your object has the standard characteristics. Notably:
  • The calendar should have no bank holidays, just weekends.
  • The yield curve should be LIBOR piecewise constant in fwd rates, with a discount factor of 1 on the calculation date, which coincides with the trade date.
  • Convention should be Following for yield curve and contract cashflows.
  • The CDS should pay accrued and mature on standard IMM dates, settle on trade date +1 and upfront settle on trade date +3.

Definition at line 383 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:

◆ setupExpired()

void setupExpired ( ) const
overrideprotectedvirtual

This method must leave the instrument in a consistent state when the expiration condition is met.

Reimplemented from Instrument.

Definition at line 215 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:

◆ init()

void init ( const Schedule schedule,
BusinessDayConvention  paymentConvention,
const DayCounter dayCounter,
const DayCounter lastPeriodDayCounter,
bool  rebatesAccrual,
const Date upfrontDate = Date() 
)
private

Shared initialisation.

Definition at line 87 of file creditdefaultswap.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ side_

Protection::Side side_
protected

Definition at line 283 of file creditdefaultswap.hpp.

◆ notional_

Real notional_
protected

Definition at line 284 of file creditdefaultswap.hpp.

◆ upfront_

ext::optional<Rate> upfront_
protected

Definition at line 285 of file creditdefaultswap.hpp.

◆ runningSpread_

Rate runningSpread_
protected

Definition at line 286 of file creditdefaultswap.hpp.

◆ settlesAccrual_

bool settlesAccrual_
protected

Definition at line 287 of file creditdefaultswap.hpp.

◆ paysAtDefaultTime_

bool paysAtDefaultTime_
protected

Definition at line 287 of file creditdefaultswap.hpp.

◆ claim_

ext::shared_ptr<Claim> claim_
protected

Definition at line 288 of file creditdefaultswap.hpp.

◆ leg_

Leg leg_
protected

Definition at line 289 of file creditdefaultswap.hpp.

◆ upfrontPayment_

ext::shared_ptr<SimpleCashFlow> upfrontPayment_
protected

Definition at line 290 of file creditdefaultswap.hpp.

◆ accrualRebate_

ext::shared_ptr<SimpleCashFlow> accrualRebate_
protected

Definition at line 291 of file creditdefaultswap.hpp.

◆ protectionStart_

Date protectionStart_
protected

Definition at line 292 of file creditdefaultswap.hpp.

◆ tradeDate_

Date tradeDate_
protected

Definition at line 293 of file creditdefaultswap.hpp.

◆ cashSettlementDays_

Natural cashSettlementDays_
protected

Definition at line 294 of file creditdefaultswap.hpp.

◆ maturity_

Date maturity_
protected

Definition at line 295 of file creditdefaultswap.hpp.

◆ fairUpfront_

Rate fairUpfront_
mutableprotected

Definition at line 297 of file creditdefaultswap.hpp.

◆ fairSpread_

Rate fairSpread_
mutableprotected

Definition at line 298 of file creditdefaultswap.hpp.

◆ couponLegBPS_

Real couponLegBPS_
mutableprotected

Definition at line 299 of file creditdefaultswap.hpp.

◆ couponLegNPV_

Real couponLegNPV_
protected

Definition at line 299 of file creditdefaultswap.hpp.

◆ upfrontBPS_

Real upfrontBPS_
mutableprotected

Definition at line 300 of file creditdefaultswap.hpp.

◆ upfrontNPV_

Real upfrontNPV_
protected

Definition at line 300 of file creditdefaultswap.hpp.

◆ defaultLegNPV_

Real defaultLegNPV_
mutableprotected

Definition at line 301 of file creditdefaultswap.hpp.

◆ accrualRebateNPV_

Real accrualRebateNPV_
mutableprotected

Definition at line 302 of file creditdefaultswap.hpp.