Skip to main content

CreditDefaultSwap

Struct CreditDefaultSwap 

pub struct CreditDefaultSwap {
    pub premium: Leg,
    pub notional: f64,
    pub protection_grid: Vec<NaiveDate>,
    pub fixed_recovery: Option<f64>,
    pub credit: CreditCurveId,
    pub currency: Currency,
    pub collateral: CollateralSpec,
    pub effective: NaiveDate,
    pub accrual_on_default: AccrualOnDefault,
    pub upfront: f64,
    pub cash_settlement: Option<NaiveDate>,
}
Expand description

A single-name credit default swap.

The premium leg is an ordinary compiled fixed leg — the running spread is a coupon rate like any other. What makes this a credit product is the protection leg, which is not a leg of cashflows at all: it pays on an event whose timing is a distribution, so it is described by the grid its integral is taken over rather than by dated payments.

Fields§

§premium: Leg

The premium leg, paying the running spread.

§notional: f64

The notional protected.

§protection_grid: Vec<NaiveDate>

The dates the protection integral steps over, ascending and covering the protected period. Built once, curve-free.

§fixed_recovery: Option<f64>

The recovery assumed when the contract fixes one. None uses the entity’s market recovery, and a trade that needs one says so through its risk factors.

§credit: CreditCurveId

The credit curve the contract is valued on — a reference entity in the contract’s currency, or an index.

§currency: Currency

The contract’s currency.

§collateral: CollateralSpec

What the trade is collateralised against.

§effective: NaiveDate

The protection start date. The premium schedule may begin earlier — a standard contract accrues from the prior IMM date — but no default before this date is covered.

§accrual_on_default: AccrualOnDefault

How premium accrued since the last coupon is settled on default.

§upfront: f64

The upfront the protection buyer pays at settlement, as a decimal of the notional.

§cash_settlement: Option<NaiveDate>

The cash-settlement date the upfront and the accrual rebate are paid on — T+3 business days for the standard contract, as the ISDA standard model discounts them. None settles at valuation, undiscounted: a contract built without a trade date has no settlement to discount from.

Implementations§

§

impl CreditDefaultSwap

pub fn buys_protection(&self) -> bool

Whether this contract buys protection.

Derived from the premium leg rather than stored beside it: a protection buyer pays the premium, so holding both a direction and a side would be holding one fact twice and inviting the two to disagree.

pub fn needs_market_recovery(&self) -> bool

Whether this contract needs the entity’s market recovery to price.

pub fn accrued_to_effective(&self) -> f64

The accrued the buyer is charged for but does not own, at unit coupon — the notional accrued from the premium leg’s first accrual start to the protection start.

A standard contract accrues from the prior IMM date while protection begins a spot lag past the trade date, so the first coupon charges the buyer for days before they were covered. The contract settles that by rebating those days, and a trade struck late in a coupon period rebates almost a whole coupon: at unit coupon this is N · τ(first accrual, protection start) on the first coupon’s own day count.

Zero where protection begins on or before the first accrual — which is every contract whose schedule starts at its own effective date, so a non-standard build is unaffected.

§

impl CreditDefaultSwap

pub fn standard( template: &CdsTemplate, trade_date: NaiveDate, entity: impl Into<String>, currency: Currency, tenor_years: u32, notional: f64, coupon: f64, buys_protection: bool, ) -> Self

The ISDA standard contract from its template: protection from the template’s spot lag past the trade date, maturity by the CDS2015 roll for tenor_years, and a CDS-generated quarterly IMM-20th premium schedule whose first accrual starts at the prior IMM date and whose terminal date is unadjusted. Recovery floats (the entity’s market recovery); accrual on default is Proportional; no upfront.

pub fn standard_maturing( template: &CdsTemplate, trade_date: NaiveDate, entity: impl Into<String>, currency: Currency, maturity: NaiveDate, notional: f64, coupon: f64, buys_protection: bool, ) -> Self

standard with the maturity supplied directly. The reference entity is entity on the template’s standard tier and clause; a contract on another tier states it through standard_on.

pub fn standard_on( template: &CdsTemplate, trade_date: NaiveDate, credit: CreditCurveId, currency: Currency, maturity: NaiveDate, notional: f64, coupon: f64, buys_protection: bool, ) -> Self

The standard contract on credit — the one constructor that takes the full identity, so a subordinated name, another documentation clause or an index is stated rather than filled in.

§Panics

If maturity is not after the step-in date (trade_date plus the template’s spot lag).

pub fn with_protection_start( self, protection_start: NaiveDate, ) -> Result<Self, CreditError>

A forward-starting contract: protection from protection_start, the trade’s settlement unchanged. The premium leg keeps the coupons whose accrual ends after the start (a standard contract accrues from the prior IMM date) and the protection grid begins with the first of them.

§Errors

A CreditError on or after the last coupon’s accrual end.

pub fn with_upfront(self, upfront: f64) -> Self

Sets the upfront the buyer pays at settlement, as a decimal of notional.

pub fn with_fixed_recovery(self, recovery: f64) -> Self

Locks a contractual recovery on the trade.

pub(crate) fn with_running_coupon(self, coupon: f64) -> Self

The contract re-struck at the running coupon coupon: every fixed premium coupon’s rate replaced, its dates, accruals and side kept — the contract a par-quoted ladder rung is at another quote.

pub fn maturity(&self) -> NaiveDate

The contract’s maturity — the last premium date.

§Panics

If the contract has no premium dates, which the constructors prevent.

pub fn protection_observed_from(&self, as_of: NaiveDate) -> NaiveDate

The day protection is integrated from, under the ISDA standard model: the effective protection start — the protection start, or the day after as_of if that is later — less one day, because protection covers its first day from the start of that day. For a standard contract valued on its trade date this is the trade date itself.

pub fn integration_grid( &self, as_of: NaiveDate, pillars: &[NaiveDate], ) -> Vec<NaiveDate>

The protection integral’s grid from as_of: the day protection is observed from (protection_observed_from), every premium date and every curve node strictly inside, and the maturity — so that every interval carries a flat hazard and a flat forward, which is what the closed-form kernels assume. Empty once protection has expired.

pillars are the nodes of both curves, discount and survival: a discount pillar inside an interval would otherwise average two forwards.

pub fn enclosing_accrual(&self, a: NaiveDate, b: NaiveDate) -> f64

The accrual of the premium period enclosing the midpoint of [a, b] — the α of the halfway accrual-on-default convention.

§

impl CreditDefaultSwap

pub(crate) fn legs<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<CdsLegs<R>, PricingError>

Both legs under the ISDA CDS Standard Model (JPMCDS), on piecewise flat forward and hazard curves, which is what a standard contract’s upfront is quoted on. Where an interval’s combined rate is near zero, its integral is taken by series rather than by the closed form, so the value stays smooth in the hazard.

The premium leg pays each coupon’s accrual, discounted from its payment date and weighted by survival to the day before it — protection is observed from the start of each day, so a coupon is paid if the entity survived to the end of the previous one. A coupon counts when it pays after the effective protection start. The final period accrues inclusive of its end date; that is a term of the contract, so it lives on the coupon, not here.

Accrual on default (Proportional, the standard) is the model’s per-coupon integral of (t − t_start)·h·P·Q from the later of the accrual start and the protection start, less a day, to the payment date less a day, over every curve node inside, with t_start the accrual start less a day and less the half-day bias 1/730, scaled by 365/360 for an ACT/360 coupon on ACT/365F time.

The protection leg is (1 − R)·N·∫ P·dQ, integrated from the day protection is observed from — the trade date for a contract valued on it — over the union of both curves’ nodes and the premium dates, each interval closed-form on a flat forward and a flat hazard (splitting a flat interval changes nothing: the closed form telescopes).

The accrual rebate and the upfront settle on the cash-settlement date and are discounted from it; once that date has passed they are no longer owed. The rebate comes out of the annuity as well as the value, so a contract struck at its own par_rate is worthless: par = protection / (premium + accrual − rebate), the model’s −protection·s / (couponLeg + rebate).

§

impl CreditDefaultSwap

pub fn diagnostics<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<CdsDiagnostics, PricingError>

Each part of the contract’s value, signed as it enters that value, and the risky annuity behind its quote.

The one reading that cannot be assembled from outside: the premium leg is survival-weighted inside the walk, and the protection leg is an integral over a grid rather than a schedule of payments, so neither is reachable from the contract’s cashflow leg.

§Errors

As Priceable::npv.

Trait Implementations§

§

impl Clone for CreditDefaultSwap

§

fn clone(&self) -> CreditDefaultSwap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for CreditDefaultSwap

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl PartialEq for CreditDefaultSwap

§

fn eq(&self, other: &CreditDefaultSwap) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<R: Scalar> Priceable<R> for CreditDefaultSwap

§

fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>

Present value against the resolved market view. Read more
§

fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>

The par rate — the fixed rate at which the product is worth nothing. Read more
§

fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>

The par (breakeven) floating-leg spread. Zero for a product with no floating leg. Read more
§

impl PricingRiskFactors for CreditDefaultSwap

§

fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>

The market data this product is priced against. Read more
§

impl Product for CreditDefaultSwap

§

fn restruck_at_rate(&self, rate: f64) -> Option<AnyInstrument>

Re-struck at the running coupon rate.

§

fn currency(&self) -> Currency

The currency the product pays in. An FX product values in its quote currency; a book converts.
§

fn contract_dates(&self) -> Vec<(&'static str, NaiveDate)>

The contract dates the product resolved to, as (name, date) pairs — exactly the dates its stated constructor takes, so a product built through a derived form can be read back and rebuilt through the stated one. Empty for a product with no stated form. No default: every product states which it is — see AnyInstrument::contract_dates.
§

fn legs(&self) -> Option<Vec<&Leg>>

The legs the product itself holds, in a declared order, or None for a product that holds none — see AnyInstrument::legs. No default: every product states which it is.
§

fn final_payment_date(&self) -> Option<NaiveDate>

The date of the product’s final payment, where a calibration rung can be built on it; None for a product no ladder is built from.
§

fn restruck_at_spread(&self, _spread: f64) -> Option<AnyInstrument>

This product re-struck at the basis spread spread on its spread leg, or None for a product that quotes none.
§

impl StructuralPartialEq for CreditDefaultSwap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.