hasquant
Safe HaskellNone
LanguageHaskell2010

QuantLib.TermStructure.Credit

Description

Credit term structures and helpers.

Hazard shifts

shiftedHazardRateCurve retains QuantLib's parallel and relative wrappers. Their survival calculation uses 48-point Gauss-Chebyshev quadrature, so even a constant hazard integrates with a small numerical error. For a flat annual hazard h, parallel survival is exp(-k*h*t), with k = pi/(96*sin(pi/96)), rather than exp(-h*t). This numerical behavior is retained for compatibility. Parallel queries now refuse negative or non-finite resulting hazards, including during native survival integration, rather than returning invalid credit rates. Shaped shifts instead retain base survival and apply the exact interpolation primitive of their spread; see shiftedHazardRateCurve for bounds and query checks.

Conditional survival

conditionalSurvivalCurve is a hasquant curve view, not a QuantLib class binding. It keeps the original native interpolation and hazard-wrapper quadrature. For original-curve time s at its new fixed reference, a view-time t reads S(s+t)/S(s), f(s+t)/S(s) and h(s+t) from the original curve. View times are years from the new reference on the original day counter. Date queries preserve original-date ratios when that day counter adds year fractions; callers must check that clock convention rather than silently re-interpolate. The new reference must lie within the original support and have positive finite survival: normalizing zero or an invalid value cannot define a conditional curve. Sources exposing scheduled jumps are refused: the generic curve interface does not expose their quote handles, so transferring their jump metadata would lose updates. The view keeps its original curve alive, observes its updates and inherits its calendar, day counter, maximum date and extrapolation permission. Its reference remains fixed if the original curve moves; a reference that then becomes invalid is refused when queried. Native query values must remain finite.

Synopsis

Types

Curves and helpers

type GenDefaultProbabilityTermStructure d = GenTermStructure (AnyOf CDefaultProbabilityTermStructure' d) Source #

A DefaultProbabilityTermStructure or one of its leaves; see the hierarchy under GenTermStructure.

type DefaultProbabilityTermStructure = GenDefaultProbabilityTermStructure CDefaultProbabilityTermStructure Source #

A TermStructure; see the hierarchy under GenTermStructure.

type PiecewiseDefaultCurve = GenDefaultProbabilityTermStructure CPiecewiseDefaultCurve Source #

A DefaultProbabilityTermStructure bootstrapped from default-probability helpers, whose nodes can be read; see the hierarchy under GenTermStructure.

Coordinates

data Reference Source #

A term-structure reference point. ReferenceDate stays fixed for the object's lifetime; SettlementDays follows the global evaluation date using the supplied calendar.

Instances

Instances details
Show Reference Source # 
Instance details

Defined in QuantLib.TermStructure

Eq Reference Source # 
Instance details

Defined in QuantLib.TermStructure

data TermPoint Source #

A date or year-fraction coordinate measured from a term structure's reference date.

Constructors

DatePoint !Day 
TimePoint !Double 

Instances

Instances details
Show TermPoint Source # 
Instance details

Defined in QuantLib.TermStructure

Eq TermPoint Source # 
Instance details

Defined in QuantLib.TermStructure

data TermInterval Source #

A same-representation interval. Keeping both endpoints in one constructor prevents mixed date/time intervals that upstream does not accept.

Instances

Instances details
Show TermInterval Source # 
Instance details

Defined in QuantLib.TermStructure

Eq TermInterval Source # 
Instance details

Defined in QuantLib.TermStructure

Hazard shifts

data HazardRateShift q Source #

A live shift of a credit curve. Spreads are annual continuous hazard fractions; relative operands are dimensionless (0.01 means multiplying hazards by 1.01).

Constructors

ParallelHazardShift

QuantLib's additive parallel hazard wrapper.

Fields

  • (GenQuote q)

    Annual additive spread quote.

RelativeHazardShift

QuantLib's relative hazard wrapper.

Fields

  • (GenQuote q)

    Fractional change quote, normally at least -1.

KeyRateHazardShifts

Linear spread in curve time between dates, flat outside the grid.

Fields

  • (NonEmpty (Day, GenQuote q))

    Strictly increasing dates after the underlying reference date, paired with annual spread quotes.

BucketHazardShifts

Constant spread on [previous end, end), zero at and after the last end.

Fields

  • (NonEmpty (Day, GenQuote q))

    Strictly increasing period ends after the underlying reference date, paired with annual spread quotes; the first period starts at that reference date.

Bootstrap configuration

data IterativeBootstrapOpts Source #

Every constructor parameter of QuantLib's curve-generic IterativeBootstrap. The first three fields are Maybe because Nothing preserves QuantLib's Null<Real>() sentinel, which selects a suitable value for each curve pillar.

Constructors

Flat, conditional and spreaded curves

shiftedHazardRateCurve Source #

Arguments

:: GenDefaultProbabilityTermStructure d

Underlying credit curve.

-> HazardRateShift q

Live shift quotes and, for shapes, their date grid.

-> IO DefaultProbabilityTermStructure 

Apply a live hazard shift, retaining the underlying reference date, day counter, calendar and maximum date. The underlying and all quotes remain observed.

Parallel and relative shifts retain QuantLib's original wrappers and numerical integration; parallel queries additionally check finite nonnegative hazards. The shaped adapter is defined by hasquant: it adds the spread to the underlying hazard and multiplies underlying survival by exp(-integral spread dt). QuantLib's linear/forward-flat interpolation primitives integrate the spread exactly, so bucket boundaries introduce no survival jumps and the accumulated change remains after the last bucket. The base curve is never sampled or re-interpolated. Curve times use its own day counter.

Shaped queries refuse non-finite spreads, negative or non-finite resulting hazards, and non-finite survival probabilities or values outside [0,1]. Multiplication roundoff at most four machine epsilons above one is clamped to one, so exactly zero hazards are not refused because exp(-x) * exp(x) rounded upward. Survival queries check their endpoint and both sides of earlier spread knots; this is not a proof of positivity at every point of an arbitrary underlying curve. Underflow and overflow of the exponential correction remain native floating-point limits.

flatHazardRate :: Reference -> GenQuote q -> DayCounter -> IO DefaultProbabilityTermStructure Source #

Flat hazard-rate curve with either a fixed or evaluation-date-relative reference point.

conditionalSurvivalCurve Source #

Arguments

:: GenDefaultProbabilityTermStructure d

Original credit curve, retained and observed by the view.

-> Day

New fixed reference date, on or after the original reference and no later than its maximum date.

-> IO DefaultProbabilityTermStructure 

The original native credit curve conditioned on survival at a later fixed reference. This is the delegated curve view described in Conditional survival.

Helpers and bootstrapped curves

spreadCdsHelper Source #

Arguments

:: GenQuote q

runningSpread

-> (Word, TimeUnit)

tenor

-> Int

settlementDays

-> Calendar 
-> Frequency 
-> BusinessDayConvention 
-> DateGenerationRule 
-> DayCounter 
-> Double 
-> GenYieldTermStructure y

discountCurve

-> Bool

settlesAccrual

-> Bool

paysAtDefaultTime

-> Maybe Day

startDate

-> DayCounter

lastPeriodDayCounter

-> Bool

rebatesAccrual

-> PricingModel

model

-> Maybe Day

tradeDate (1.44; QuantLib 1.43 requires Nothing)

-> IO DefaultProbabilityHelper 

bootstrap helper for a CDS quoted by running spread

upfrontCdsHelper Source #

Arguments

:: GenQuote q

upfront

-> Double

runningSpread

-> (Word, TimeUnit)

tenor

-> Int

settlementDays

-> Calendar 
-> Frequency 
-> BusinessDayConvention 
-> DateGenerationRule 
-> DayCounter 
-> Double

recoveryDate

-> GenYieldTermStructure y

discountCurve

-> Word

upfrontSettlementDays

-> Bool 
-> Bool

paysAtDefaultTime

-> Maybe Day

startDate

-> DayCounter

lastPeriodDayCounter

-> Bool

rebatesAccrual

-> PricingModel

model

-> Maybe Day

tradeDate (1.44; QuantLib 1.43 requires Nothing)

-> IO DefaultProbabilityHelper 

the upfront must be quoted in fractional units.

interpolatedHazardRateCurve Source #

Arguments

:: NonEmpty (Day, Double) 
-> DayCounter 
-> Calendar 
-> [(Day, GenQuote q)]

jumps

-> Interpolation 
-> Bool

extrapolate past the curve's max date

-> IO DefaultProbabilityTermStructure 

interpolatedAffineHazardRateCurve Source #

Arguments

:: NonEmpty (Day, Double) 
-> DayCounter 
-> GenOneFactorAffineModel om 
-> Calendar 
-> [(Day, GenQuote q)]

jumps

-> Interpolation 
-> Bool

extrapolate past the curve's max date

-> IO AffineHazardRateCurve 

Hazard-rate curve interpolated deterministically between nodes, combined with a one-factor affine short-rate model's stochastic discount mechanics -- see 'qlexperimentalcredit/interpolatedaffinehazardratecurve.hpp'.

piecewiseDefaultCurve Source #

Arguments

:: Reference 
-> NonEmpty DefaultProbabilityHelper

instruments

-> DayCounter

dayCounter

-> [(Day, GenQuote q)]

jumps paired with their dates

-> ProbabilityTrait

bootstrap trait

-> Interpolation

interpolator

-> IterativeBootstrapOpts

bootstrap settings

-> Bool

extrapolate past the curve's max date

-> IO PiecewiseDefaultCurve 

Default-probability term structure bootstrapped from CDS/default helpers with either a fixed or evaluation-date-relative reference point and complete iterative-bootstrap settings.

Inspectors

defaultProbability :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double Source #

Default probability from the reference point to a date or year fraction.

hazardRate :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double Source #

Hazard rate at a date or year fraction, with annual frequency and continuous compounding.

survivalProbability :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double Source #

Survival probability from the reference point to a date or year fraction.

defaultDensity :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double Source #

Default density at a date or year fraction.

defaultProbabilityBetween :: GenDefaultProbabilityTermStructure d -> TermInterval -> Bool -> IO Double Source #

Default probability over a same-representation date or year-fraction interval.

conditionalSurvivalProbability Source #

Arguments

:: AffineHazardRateCurve 
-> TermInterval 
-> Double

yVal

-> Bool 
-> IO Double 

Probability of survival to the interval's later point, conditional on survival to its earlier point and on the stochastic hazard-rate component realizing yVal there -- see 'qlexperimentalcredit/onefactoraffinesurvival.hpp'.

impliedQuote :: DefaultProbabilityHelper -> IO Double Source #

The fair running-spread/upfront quote implied by the helper's current market data and pricing engine -- the value that would make the quoted instrument re-price at par. Requires the helper to have already been used to bootstrap a curve (throws otherwise, per upstream).

impliedQuoteOn :: DefaultProbabilityHelper -> GenDefaultProbabilityTermStructure d -> IO Double Source #

The quote that would make the helper reprice exactly on the given default-probability curve: a par spread or upfront read with the helper's own conventions on any credit curve.

class HasNodes c where Source #

Bootstrapped curve leaves that retain their native nodes. The class lives in this root module for the same reason as HasHelperUnderlying: its instances span the topical curve modules.

Methods

bootstrappedNodes :: c -> IO [(Day, Double)] Source #

The curve's (date, value) nodes; reading them runs the bootstrap. The first node is the reference date (inflation curves: the base date), the rest are helper pillars. Each value is what the curve interpolates: the trait's quantity for yield and default curves, a discount-factor spread for piecewiseSpreadYieldCurve, and the rate before seasonality for inflation curves. Jump factors are applied separately and are not part of the nodes.

An interpolated curve of the same kind on these nodes, with the original day counter, interpolation, jumps and seasonality, reproduces the bootstrapped curve. The exception is a local bootstrap, whose convex-monotone shape also depends on state the nodes do not carry.