Setting Up a Fixed Income Contract in Quantlib

Creating the Bond Object

# 3. Create FixedRateBond bond = ql.FixedRateBond( settlement_days, face_amount, schedule, coupons, day_counter )

Face Amount

The face amount is a number representing the face amount or principal of the bond.

face_amount = 10000.0

Settlement Days

settlement_days = 2

Coupons

The coupons parameter is a list that represents the coupon rate for the bond. If the bond has a single rate, you provide it in a list as follows:

coupons = [0.05]
Step-Up or Stepping Coupon RatesIf the bond has changing coupons over its lifetime, provide a list explicitly matching the number of periods in the bond schedule. For example, if a bond pays 3% for the first three years and 4% for the next two:

coupons = [0.03, 0.03, 0.03, 0.04, 0.04]

Day Count

Quantlib Day Count
day_counter = ql.ActualActual(ql.ActualActual.ISDA)

Mapping a Portfolio

portfolio = [ {"face-amount":10000,"settlement-days":2, rate:0.05}, ] def coupons(bond): if isinstance(my_var, str): rates = bond['rate'] split = rates.split(',') return map(lambda x: float(x), split) else: return bond['rate'] pass #date format "2026-06-21" def q_date(date_str): py_date = datetime.strptime(date_str, "%Y-%m-%d").date() ql_date = ql.Date.from_date(py_date) return ql_date pass def get_date_roll(bond): if bond['date-roll'] == 'following' return ql.Following if bond['date-roll'] == 'modified following' return ql.ModifiedFollowing if bond['date-roll'] == 'actual' return ql.Unadjusted if bond['date-roll'] == 'previous' return ql.Preceding if bond['date-roll'] == 'modified previous' return ql.ModifiedPreceding pass def schedule(bond): issue_date = q_date(bond['issue-date']) maturity_date = q_date(bond['maturity-date']) calendar = ql.UnitedStates(ql.UnitedStates.Settlement) convention = get_date_roll(bond) return ql.Schedule( issue_date, maturity_date, ql.Period(ql.Semiannual), calendar, convention, convention, ql.DateGeneration.Backward, False ) def day_count(bond): if bond['day-count'] == 'actual/actual': ql.ActualActual(ql.ActualActual.ISDA) if bond['day-count'] == 'actual/360': return ql.Actual360() pass bonds = map(lambda bond:ql.FixedRateBond( bond['settlement-days'], bond['face-amount'], schedule(bond), coupons(bond), day_count(bond) ), portfolio)

Desktop