Updating QuantLib Fixed-Rate Bond Construction to Use a Schedule
Summary
The document explains a constructor error encountered while creating a fixed-rate bond in QuantLib. The example passes settlement details, dates, a coupon period, and a calendar directly to the bond constructor; the reported type error indicates that this argument pattern no longer matches the available interface. The issue is traced to a deprecated constructor that was removed in a later QuantLib release.
The stated remedy is to build a bond schedule first and pass that schedule to the current fixed-rate bond constructor. The post identifies the relevant version changes and directs readers to updated examples, but does not include a complete replacement snippet or discuss schedule conventions such as business-day adjustment, calendar, or payment dates. It is a focused API migration note useful for fixing bond setup code; it does not explain bond valuation or provide pricing analysis.
Key ideas
- The reported error comes from using an obsolete fixed-rate bond constructor signature.
- The constructor was deprecated in version 1.28 and removed in version 1.33.
- The current approach requires constructing a payment schedule and passing it to the bond constructor.
- The document focuses on API compatibility and does not cover bond valuation or pricing methods.
Tags
Full text
# QuantLib issue with creating a FixedRateBond
# QuantLib issue with creating a FixedRateBond
When trying to construct a simple bond object using QuantLib using the example from the docs, I get the following error:
```
bond = ql.FixedRateBond(2, ql.TARGET(), 100.0, ql.Date(15,12,2019), ql.Date(15,12,2024), ql.Period('1Y'), [0.05], ql.ActualActual(ql.ActualActual.Bond))
```
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/folders/1b/c43sykqx7fj5lrcvssd3v3g40000gn/T/ipykernel_15546/356881404.py in ?()
----> 1 bond = ql.FixedRateBond(2, ql.TARGET(), 100.0, ql.Date(15,12,2019), ql.Date(15,12,2024), ql.Period('1Y'), [0.05], ql.ActualActual(ql.ActualActual.Bond))
/opt/miniconda3/envs/python313/lib/python3.13/site-packages/QuantLib/QuantLib.py in ?(self, *args, **kwargs)
25882 def __init__(self, *args, **kwargs):
25883 r"""__init__(FixedRateBond self, Integer settlementDays, Real faceAmount, Schedule schedule, DoubleVector coupons, DayCounter paymentDayCounter, BusinessDayConvention paymentConvention=QuantLib::Following, Real redemption=100.0, Date issueDate=Date(), Calendar paymentCalendar=Calendar(), Period exCouponPeriod=Period(), Calendar exCouponCalendar=Calendar(), BusinessDayConvention exCouponConvention=Unadjusted, bool exCouponEndOfMonth=False) -> FixedRateBond"""
> 25884 _QuantLib.FixedRateBond_swiginit(self, _QuantLib.new_FixedRateBond(*args, **kwargs))
TypeError: in method 'new_FixedRateBond', argument 2 of type 'Real'
```
I have checked and confirmed that I am on QuantLib version 1.40, and it is strange as I have not had this issue in the past. The only difference is that I am trying to run this on Mac, whereas I have run this on a linux machine in the past. Appreciate everyone's help.
## Answer by Luigi Ballabio (score 1)
https://quant.stackexchange.com/a/85196
That constructor was deprecated in version 1.28 (October 2022) and removed in version 1.33 (January 2024); see https://github.com/lballabio/QuantLib/releases. I'm not sure from what docs you got this example, but you might want to notify whoever published them and suggest an update.
The current interface requires you to build a schedule and pass it to the bond constructor. You can find a few examples at https://www.quantlibguide.com/Vanilla%20bonds.html.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.