just wanted to ask how to use Quantlib on replicating Excel's MDURATION.
Given the following parameters, I was able to get a value of 4.478837 via MS Excel's MDURATION Function.
# GIVEN: # settlement_date = "2021-05-15" # maturity_date = "2025-11-30" # coupon_rate = 0.00375 # yld_rate = 0.01 # frequency = 2 # basis = 1 # # EXPECTED RESULT: 4.478837
I am trying to replicate this using Quantlib Python but I'm getting a different result of 4.32822. This is my current code
import QuantLib as ql from datetime import datetime days_difference = (datetime(2025, 11, 30) - datetime(2021, 5, 15)).days coupon = 0.00375 yld = 0.01 start = ql.Date(15,5,2021) maturity = start + ql.Period(days_difference, ql.Days) bond = ql.FixedRateBond(2, ql.TARGET(), 1000, start, maturity, ql.Period('1Y'), [coupon], ql.ActualActual()) rate = ql.InterestRate(yld, ql.ActualActual(), ql.Compounded, ql.Semiannual) simple_duration = ql.BondFunctions.duration(bond, rate, ql.Duration.Simple) mod_duration = ql.BondFunctions.duration(bond, rate, ql.Duration.Modified) mac_duration = ql.BondFunctions.duration(bond, rate, ql.Duration.Macaulay) print(mac_duration, mod_duration, ) # OUTPUT: (4.349865119875341 4.328223999875962)
So how to properly use Quantlib to be able to arrive at 4.478837?
Sorry if this is too basic as I am new to Quantlib and Im still confused on how to use it.