0
$\begingroup$

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!

$\endgroup$
4
  • $\begingroup$ Have you tried passing fixingdays to InterestRateIndex? $\endgroup$ Aug 18 '21 at 11:28
  • $\begingroup$ You mean, passing fixingDays as a parameter in the function floatIndex? As far as I know, it is not possible... $\endgroup$ Aug 18 '21 at 11:32
  • $\begingroup$ instead of floatIndex = ql.USDLibor(... , can you try floatIndex = ql.InterestRateIndex(... - looking at github.com/lballabio/QuantLib/blob/master/ql/indexes/… it takes settlementDays which is really fixingdays. $\endgroup$ Aug 18 '21 at 11:47
  • $\begingroup$ This is what I get in return AttributeError: No constructor defined. $\endgroup$ Aug 18 '21 at 11:57
2
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ Thanks a lot Luigi! $\endgroup$ Oct 14 '21 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.