0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Can you add a snippet of code to demonstrate the issue? $\endgroup$
    – StackG
    Sep 23, 2020 at 22:37
  • $\begingroup$ 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/… $\endgroup$
    – Dom
    Sep 24, 2020 at 12:59

1 Answer 1

0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.