QuantLib
A free/open-source library for quantitative finance
Reference manual - version 1.20
Public Types | List of all members
CreditDefaultSwap Class Reference

Credit default swap. More...

#include <ql/instruments/creditdefaultswap.hpp>

+ Inheritance diagram for CreditDefaultSwap:

Public Types

enum  PricingModel { Midpoint, ISDA }
 
- Public Types inherited from Observer
typedef boost::unordered_set< ext::shared_ptr< Observable > > set_type
 
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(), const ext::shared_ptr< Claim > &=ext::shared_ptr< Claim >(), const DayCounter &lastPeriodDayCounter=DayCounter(), bool rebatesAccrual=true)
 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(), const ext::shared_ptr< Claim > &=ext::shared_ptr< Claim >(), const DayCounter &lastPeriodDayCounter=DayCounter(), bool rebatesAccrual=true)
 CDS quoted as upfront and running spread. More...
 
Inspectors
Protection::Side side () const
 
Real notional () const
 
Rate runningSpread () const
 
boost::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.
 
const DateprotectionEndDate () const
 The last date for which defaults will trigger the contract.
 
bool rebatesAccrual () 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
Real NPV () const
 returns the net present value of the instrument.
 
Real errorEstimate () const
 returns the error estimate on the NPV when available.
 
const DatevaluationDate () const
 returns the date the net present value refers to.
 
template<typename T >
result (const std::string &tag) const
 returns any additional result returned by the pricing engine.
 
const std::map< std::string, boost::any > & additionalResults () const
 returns all additional result returned by the pricing engine.
 
void setPricingEngine (const ext::shared_ptr< PricingEngine > &)
 set the pricing engine to be used. More...
 
- Public Member Functions inherited from LazyObject
void update ()
 
void recalculate ()
 
void freeze ()
 
void unfreeze ()
 
void alwaysForwardNotifications ()
 
- Public Member Functions inherited from Observable
 Observable (const Observable &)
 
Observableoperator= (const Observable &)
 
void notifyObservers ()
 
- Public Member Functions inherited from Observer
 Observer (const Observer &)
 
Observeroperator= (const Observer &)
 
std::pair< iterator, bool > registerWith (const ext::shared_ptr< Observable > &)
 
void registerWithObservables (const ext::shared_ptr< Observer > &)
 
Size unregisterWith (const ext::shared_ptr< Observable > &)
 
void unregisterWithAll ()
 
virtual void deepUpdate ()
 

Instrument interface

Protection::Side side_
 
Real notional_
 
boost::optional< Rateupfront_
 
Rate runningSpread_
 
bool settlesAccrual_
 
bool paysAtDefaultTime_
 
ext::shared_ptr< Claimclaim_
 
Leg leg_
 
ext::shared_ptr< CashFlowupfrontPayment_
 
ext::shared_ptr< CashFlowaccrualRebate_
 
Date protectionStart_
 
Date maturity_
 
Rate fairUpfront_
 
Rate fairSpread_
 
Real couponLegBPS_
 
Real couponLegNPV_
 
Real upfrontBPS_
 
Real upfrontNPV_
 
Real defaultLegNPV_
 
Real accrualRebateNPV_
 
bool isExpired () const
 returns whether the instrument might have value greater than zero.
 
void setupArguments (PricingEngine::arguments *) const
 
void fetchResults (const PricingEngine::results *) const
 
void setupExpired () const
 

Additional Inherited Members

- Protected Member Functions inherited from Instrument
void calculate () const
 
virtual void performCalculations () const
 
- Protected Member Functions inherited from LazyObject
- Protected Attributes inherited from Instrument
Real NPV_
 
Real errorEstimate_
 
Date valuationDate_
 
std::map< std::string, boost::any > additionalResults_
 
ext::shared_ptr< PricingEngineengine_
 
- Protected Attributes inherited from LazyObject
bool calculated_
 
bool frozen_
 
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.

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(),
const ext::shared_ptr< Claim > &  = ext::shared_ptr< Claim >(),
const DayCounter lastPeriodDayCounter = DayCounter(),
bool  rebatesAccrual = true 
)

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. Typically T+1 Notice 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.

◆ 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(),
const ext::shared_ptr< Claim > &  = ext::shared_ptr< Claim >(),
const DayCounter lastPeriodDayCounter = DayCounter(),
bool  rebatesAccrual = true 
)

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. Typically T+1 Notice 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.

Member Function Documentation

◆ setupArguments()

void setupArguments ( PricingEngine::arguments *  ) const
virtual

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.

◆ fetchResults()

void fetchResults ( const PricingEngine::results *  r) const
virtual

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.

◆ 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.

◆ 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.

◆ couponLegBPS()

Real couponLegBPS ( ) const

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

◆ 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.

◆ 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.

◆ setupExpired()

void setupExpired ( ) const
protectedvirtual

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

Reimplemented from Instrument.