# 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.

• Can you add a snippet of code to demonstrate the issue? Sep 23, 2020 at 22:37
• If you are interested, I have just released a beta of a Python library called FinancePy that also does this. Here is how I do what you are looking for github.com/domokane/FinancePy-Examples/blob/master/notebooks/…
– Dom
Sep 24, 2020 at 12:59

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