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§
The premium leg, paying the running spread.
notional: f64The 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: CreditCurveIdThe credit curve the contract is valued on — a reference entity in the contract’s currency, or an index.
currency: CurrencyThe contract’s currency.
collateral: CollateralSpecWhat the trade is collateralised against.
effective: NaiveDateThe 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: AccrualOnDefaultHow premium accrued since the last coupon is settled on default.
upfront: f64The 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
impl CreditDefaultSwap
pub fn buys_protection(&self) -> bool
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
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
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
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
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
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
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>
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
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
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
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
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
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>
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
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
impl CreditDefaultSwap
pub(crate) fn legs<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<CdsLegs<R>, PricingError>
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
impl CreditDefaultSwap
pub fn diagnostics<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<CdsDiagnostics, PricingError>
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
impl Clone for CreditDefaultSwap
§fn clone(&self) -> CreditDefaultSwap
fn clone(&self) -> CreditDefaultSwap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for CreditDefaultSwap
impl Debug for CreditDefaultSwap
§impl PartialEq for CreditDefaultSwap
impl PartialEq for CreditDefaultSwap
§fn eq(&self, other: &CreditDefaultSwap) -> bool
fn eq(&self, other: &CreditDefaultSwap) -> bool
self and other values to be equal, and is used by ==.§impl<R: Scalar> Priceable<R> for CreditDefaultSwap
impl<R: Scalar> Priceable<R> for CreditDefaultSwap
§fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
§fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
§fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
§impl PricingRiskFactors for CreditDefaultSwap
impl PricingRiskFactors for CreditDefaultSwap
§fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>
fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>
§impl Product for CreditDefaultSwap
impl Product for CreditDefaultSwap
§fn restruck_at_rate(&self, rate: f64) -> Option<AnyInstrument>
fn restruck_at_rate(&self, rate: f64) -> Option<AnyInstrument>
Re-struck at the running coupon rate.
§fn currency(&self) -> Currency
fn currency(&self) -> Currency
§fn contract_dates(&self) -> Vec<(&'static str, NaiveDate)>
fn contract_dates(&self) -> Vec<(&'static str, NaiveDate)>
(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>>
fn legs(&self) -> Option<Vec<&Leg>>
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>
fn final_payment_date(&self) -> Option<NaiveDate>
None for a product no ladder is built from.§fn restruck_at_spread(&self, _spread: f64) -> Option<AnyInstrument>
fn restruck_at_spread(&self, _spread: f64) -> Option<AnyInstrument>
spread on its spread
leg, or None for a product that quotes none.