Skip to content
All library documents

How QuantLib Bond Dirty Price Uses Yield or a Pricing Engine

Article Quant Q&A · Author: Kulendra 'KJ' Janaka

Summary

The document clarifies two distinct ways to obtain a fixed-rate bond's dirty price in QuantLib. One method passes a yield, day-count convention, compounding rule, and payment frequency directly to the calculation. This route computes a price from the supplied yield and can be used even when the bond has no pricing engine attached.

The other method attaches a discounting bond pricing engine built with a yield term structure, then calls the no-argument dirty-price method. That route uses the pricing engine and its curve. The example gives both calls for the same bond and a flat curve, producing nearly identical prices when the yield inputs match. The distinction explains why changing a discount curve can affect engine-based valuation while a dirty-price call supplied with a yield remains driven by that yield. The example is limited to a simple fixed-rate bond and does not cover other bond types or curve setups.

Key ideas

  • QuantLib provides a dirty-price calculation that takes a yield and related conventions directly.
  • A separate no-argument dirty-price call uses the bond's attached pricing engine.
  • A discounting bond engine can value the bond from a supplied yield term structure.
  • The yield-based calculation does not depend on the discount curve attached to a pricing engine.
  • Matching the yield and curve assumptions can produce nearly identical prices by both methods.

Tags

Full text
# dirtyPrice() and discounting curve on QuantLib


# dirtyPrice() and discounting curve on QuantLib












I am pretty new to Quant field and QuantLib and have been having the following problem when trying to model a very simple fixed rate bond using Python.

It looks like the library does not use the discounting curve provided to the DiscountingEngine if I am using the dirtyPrice() method to calculate the IRR. It does affect the NPV() method.

Is this understanding correct? It seems like I can pass any value to the discounting curve and the dirtyPrice() method only uses the parameters passed to the FixedRateBond instrument and the parameters passed in the dirtyPrice() method it self.

## Answer by David Duarte (score 1, accepted)

https://quant.stackexchange.com/a/58177

The answer to your question is that there are two ways to call the `dirtyPrice` method: one that will give you a price for given yield and another that will give you a price using the supplied pricingEngine.

After creating a bond:

```
import QuantLib as ql
calendar = ql.TARGET()
dayCount = ql.Actual360()
start = ql.Date(15,12,2019)
maturity = ql.Date(15,12,2029)
bond = ql.FixedRateBond(2, calendar, 100.0, start, maturity, ql.Period('6M'), [0.05], dayCount)
```

One can call the `dirtyPrice` method and supply a yield (bond can have a null pricing engine), with the constructor `.dirtyPrice(yield, dayCount, compounding, frequency)`

```
px = bond.dirtyPrice(0.05, dayCount, ql.Compounded, ql.Annual)
print(px)
```

101.89618833523909

Or supply a pricing engine and call the method without parameters:

```
crv = ql.FlatForward(2, calendar, 0.05, dayCount, ql.Compounded, ql.Annual)
yts = ql.YieldTermStructureHandle(crv)
engine = ql.DiscountingBondEngine(yts)
bond.setPricingEngine(engine)
px = bond.dirtyPrice()
print(px)
```

101.89618833523907

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.