I am new to QuantLib and am trying to get it to replicate some simple bond math.
Suppose we have a 5-year bond with annual coupon payments of \$5 and face value of \$100, and interest rate of 4%. Classic calculations yield that the present value of the bond is \$104.45. When I try to do this simple example in QuantLib-Python, I get $104.70--despite my attempts to strip out calendar conventions.
How can I use QuantLib to line up with this simple bond math?
from QuantLib import * # Construct yield curve calc_date = Date(1, 1, 2017) Settings.instance().evaluationDate = calc_date spot_dates = [Date(1,1,2017), Date(1,1,2018), Date(1,1,2027)] spot_rates = [0.0, 0.04, 0.04] day_count = SimpleDayCounter() calendar = NullCalendar() interpolation = Linear() compounding = Compounded compounding_frequency = Annual spot_curve = ZeroCurve(spot_dates, spot_rates, day_count, calendar, interpolation, compounding, compounding_frequency) spot_curve_handle = YieldTermStructureHandle(spot_curve) # Construct bond schedule issue_date = Date(1, 1, 2017) maturity_date = Date(1, 1, 2022) tenor = Period(Semiannual) calendar = NullCalendar() business_convention = Unadjusted date_generation = DateGeneration.Backward month_end = False schedule = Schedule(issue_date, maturity_date, tenor, calendar, business_convention, business_convention, date_generation, month_end) # Create FixedRateBond Object coupon_rate = 0.05 coupons = [coupon_rate] settlement_days = 0 face_value = 100 fixed_rate_bond = FixedRateBond(settlement_days, face_value, schedule, coupons, day_count) # Set Valuation engine bond_engine = DiscountingBondEngine(spot_curve_handle) fixed_rate_bond.setPricingEngine(bond_engine) # Calculate present value value = fixed_rate_bond.NPV() print(value)