Setting Floating-Leg Fixing Days for a QuantLib Interest Rate Swap
Summary
The document shows how to change the fixing-day convention for a floating leg when valuing an interest rate swap in QuantLib Python. A standard VanillaSwap built with an Ibor index inherits the index’s fixing-day setting; the example reports that the resulting coupons use two fixing days. The accepted answer explains that VanillaSwap offers limited customization for this setting.
For a custom fixing lag, the suggested approach is to construct the fixed and floating legs separately, pass the desired fixing-day value when creating the Ibor leg, then combine the legs in a Swap and attach the pricing engine. The example checks the resulting floating coupons and confirms the requested one-day setting. The advice concerns instrument construction and fixing conventions, not the validity of the illustrative curves or a general swap-pricing methodology. The answer also notes that the two-leg Swap constructor treats its first leg as paid and its second as received, which matters for trade direction.
Key ideas
- A VanillaSwap uses the fixing-day convention associated with its floating index and offers limited control over that setting.
- Build the floating leg separately when the swap needs a fixing lag different from the index default.
- QuantLib’s Ibor leg builder accepts a fixing-days parameter for the floating coupons.
- Combining separately built legs in a Swap requires attention to the constructor’s pay and receive leg ordering.
Tags
Full text
# Specify fixing days for floating leg in Interest Rate Swap valuation using QuantLib Python
# Specify fixing days for floating leg in Interest Rate Swap valuation using QuantLib Python
I am trying to price an Interest Rate Swap using QuantLib Python, and everything seems to be fine. However, I can't seem to understand where I can specify the number of fixing days.
Below are my codes. Kindly note that the curve used for discounting and for the US Libor is hypothetical, and only for illustration purpose.
```
import QuantLib as ql
valuationDate = ql.Date(30, 6, 2020)
ql.Settings.instance().evaluationDate = valuationDate
dayConvention = ql.Actual360()
calendar = ql.UnitedStates()
businessConvention = ql.Following
settlementDays = 3
settlementDate = calendar.advance(valuationDate, ql.Period(settlementDays, ql.Days))
zeroCurve = ql.ZeroCurve([ql.Date(30, 6, 2020), ql.Date(30, 6, 2021), ql.Date(30, 6, 2022), ql.Date(30, 7, 2025)], [0.05, 0.06, 0.06, 0.07], dayConvention, calendar, ql.Linear(), ql.Compounded)
handle = ql.YieldTermStructureHandle(zeroCurve)
fixedFrequency = ql.Annual
floatFrequency = ql.Semiannual
floatIndex = ql.USDLibor(ql.Period(floatFrequency), handle)
floatIndex.addFixing(ql.Date(30, 12, 2019), 0.01)
floatIndex.addFixing(ql.Date(29, 6, 2020), 0.02)
issueDate = ql.Date(1, 1, 2019)
maturityDate = ql.Date(1, 1, 2023)
fixedLegTenor = ql.Period(fixedFrequency)
fixedSchedule = ql.Schedule(settlementDate, maturityDate,
fixedLegTenor, calendar,
businessConvention, businessConvention,
ql.DateGeneration.Forward, True)
floatLegTenor = ql.Period(floatFrequency)
floatSchedule = ql.Schedule(settlementDate, maturityDate,
floatLegTenor, calendar,
businessConvention, businessConvention,
ql.DateGeneration.Forward, True)
notional = 34000
fixedRate = 0.03
fixedLegDayCount = ql.Actual365Fixed()
floatSpread = 0.01
floatLegDayCount = ql.Actual360()
irs = ql.VanillaSwap(ql.VanillaSwap.Payer, notional, fixedSchedule,
fixedRate, fixedLegDayCount, floatSchedule,
floatIndex, floatSpread, floatLegDayCount)
discounting = ql.DiscountingSwapEngine(handle)
irs.setPricingEngine(discounting)
```
From QuantLib, the number of fixing days is 2 as shown below:
```
for i, cf in enumerate(irs.leg(1)):
c = ql.as_floating_rate_coupon(cf)
if c:
print(c.fixingDays())
```
which returns
> 2
> 2
> 2
> 2
> 2
Is there a way that I can specify another number of fixing days, say 1?
Thanks for your help!
## Answer by Luigi Ballabio (score 2, accepted)
https://quant.stackexchange.com/a/68364
`VanillaSwap` models simple swaps, so it doesn't have a lot of bells and whistles. For more control, you can create the two legs separately and use the `Swap` class. In your case:
```
fixed_leg = ql.FixedRateLeg(fixedSchedule, fixedLegDayCount, [notional], [fixedRate])
floating_leg = ql.IborLeg([notional], floatSchedule, floatIndex, floatLegDayCount,
spreads=[floatSpread], fixingDays=[1])
irs = ql.Swap(fixed_leg, floating_leg)
irs.setPricingEngine(discounting)
```
The constructor of `Swap` that takes two legs assumes that the first is paid and the second is received.
As for the fixing days:
```
for cf in floating_leg:
c = ql.as_floating_rate_coupon(cf)
if c:
print(c.fixingDays())
```
The output is:
```
1
1
1
1
1
```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.