## KRD

Function

**within Bond with keys Bond KRD keys returns the Key Rate Duration(s) (KRD) of the referenced bond(s) as of a specified array of future times**

*KRD*

*T₁, T₂, ..., Tₙ*KRD is defined and implemented outside of QuantLib as follows:

Let

**be the bond's dirty price as of the bond's settlement date**

*P*

*Tˢ*KRD is an array of

**numbers**

*n***, such that**

*D₁, D₂, ..., Dₙ***represents the sensitivity of**

*Dᵢ***upon changing the zero rate**

*P***corresponding to maturity**

*rᵢ*

*Tᵢ*More specifically:

*Dᵢ = (Pᵢ⁻ - Pᵢ⁺)/(2ΔP)*, where

**= User-specified amount by which each interest rate described below is shifted both downwards and upwards. For example**

*Δ***means an initial rate of**

*Δ = 0.01***is shifted downwards to**

*4%***and upwards to**

*3%*

*5%***= Dirty price that corresponds to the given clean price.**

*P*In order to explain

**and**

*Pᵢ⁻***, let:**

*Pᵢ⁺***= Bond's continuously compounded yield implied by the given clean price.**

*y***= Yield curve built out of zero rates**

*YC***, of which the corresponding equivalent continuously compounded rates are all equal to**

*r₁, r₂, ..., rₙ*

*y*Due to the way the bond's continuously compounded yield

**is defined,**

*y***must then equal the bond's NPV calculated off the yield curve**

*P*

*YC*Now

**and**

*Pᵢ⁻***are defined as follows:**

*Pᵢ⁺***= Dirty bond price calculated using a yield curve**

*Pᵢ⁻***, which differs from**

*YCᵢ⁻***in that it is built out of the zero rates**

*YC*

*r₁, r₂, ..., rᵢ-Δ, ..., rₙ***= Dirty bond price calculated using a yield curve**

*Pᵢ⁺***, which differs from**

*YCᵢ⁺***in that it is built out of the zero rates**

*YC*

*r₁, r₂, ..., rᵢ+Δ, ..., rₙ*Note all yield curves are built using linear interpolation and flat extrapolation with respect to the input zero rates.

This has the consequense that the curves

**and**

*YCᵢ⁻***will differ from each other only in the time interval**

*YCᵢ⁺*

*(Tᵢ₋₁,Tᵢ₊₁)*This in turn implies that

**will receive non-zero contributions only from bond cash flows that occur in the interval**

*Pᵢ⁻ - Pᵢ⁺*

*(Tᵢ₋₁,Tᵢ₊₁)*The conclusion is that the

**KRD**

*iᵗʰ***is determined only by the cash flows occurring in the interval**

*Dᵢ = (Pᵢ⁻ - Pᵢ⁺)/(2ΔP)*

*(Tᵢ₋₁,Tᵢ₊₁)*PRECAUTION: This function treats the referenced bond as if it were a fixed rate bond even if this is not the case!

All index-linked cash flows are treated as fixed cash flows that pay the amount forecasted by the corresponding curve.