Modeling Single-Currency Basis Swaps with QuantLib FloatFloatSwap
Summary
A single-currency basis swap exchanges cash flows linked to two floating interest rate indices. The document points to QuantLib’s FloatFloatSwap instrument as the class for representing this structure in Python, contrasting it with a vanilla interest rate swap that has one fixed leg and one floating leg.
The class interface shows the main construction choices: two notionals, schedules, indices, and day-count conventions, with optional settings for exchanging principal between legs, gearing, spreads, caps, floors, and payment conventions. This identifies the relevant instrument and the information needed to configure it, but does not provide a complete Python example, pricing setup, or valuation results. Users would still need to build compatible schedules and market data, choose the leg conventions, and verify the binding and QuantLib version they use.
Key ideas
- A single-currency basis swap can be represented with QuantLib’s FloatFloatSwap instrument.
- The two floating legs can use separate schedules, indices, day-count conventions, and notionals.
- The interface includes options for principal exchanges, gearing, spreads, caps, floors, and payment conventions.
- The example identifies the instrument class but does not demonstrate full construction or valuation.
Tags
Full text
# Basis Swaps in Quantlib/Python
# Basis Swaps in Quantlib/Python
I am aware that I can create a IRS in Quantlib/Python by using the following function:
```
def makeSwap(start, maturity, nominal, fixedRate, index, typ=ql.VanillaSwap.Payer):
end = ql.TARGET().advance(start, maturity)
fixedLegTenor = ql.Period('1y')
fixedLegBDC = ql.ModifiedFollowing
fixedLegDC = ql.Thirty360(ql.Thirty360.BondBasis)
spread = 0.0
fixedSchedule = ql.Schedule(start,
end,
fixedLegTenor,
index.fixingCalendar(),
fixedLegBDC,
fixedLegBDC,
ql.DateGeneration.Backward,
False)
floatSchedule = ql.Schedule(start,
end,
index.tenor(),
index.fixingCalendar(),
index.businessDayConvention(),
index.businessDayConvention(),
ql.DateGeneration.Backward,
False)
swap = ql.VanillaSwap(typ,
nominal,
fixedSchedule,
fixedRate,
fixedLegDC,
floatSchedule,
index,
spread,
index.dayCounter())
return swap, [index.fixingDate(x) for x in floatSchedule][:-1]
```
and then call for example:
```
makeSwap(t + ql.Period('2d'),
ql.Period('5Y'),
1e6,
0.03,
ql.euribor6m)
```
but how can I create a basis swap instead?
## Answer by byouness (score 2)
https://quant.stackexchange.com/a/48725
If it's a single currency basis swap, then `FloatFloatSwap` is the class you are looking for.
Here is the hpp file of the class: https://github.com/lballabio/QuantLib/blob/master/ql/instruments/floatfloatswap.hpp
And it's included in the SWIG input file `swap.i`, as you can see here:
https://github.com/lballabio/QuantLib-SWIG/blob/66ca96765688e9094dcfbbbd032ffd0596e7cadf/SWIG/swap.i#L295-L316
```
%shared_ptr(FloatFloatSwap)
class FloatFloatSwap : public Swap {
public:
FloatFloatSwap(VanillaSwap::Type type, const std::vector<Real> &nominal1,
const std::vector<Real> &nominal2, const Schedule &schedule1,
const boost::shared_ptr<InterestRateIndex> &index1,
const DayCounter &dayCount1, const Schedule &schedule2,
const boost::shared_ptr<InterestRateIndex> &index2,
const DayCounter &dayCount2,
const bool intermediateCapitalExchange = false,
const bool finalCapitalExchange = false,
const std::vector<Real> &gearing1 = std::vector<Real>(),
const std::vector<Real> &spread1 = std::vector<Real>(),
const std::vector<Real> &cappedRate1 = std::vector<Real>(),
const std::vector<Real> &flooredRate1 = std::vector<Real>(),
const std::vector<Real> &gearing2 = std::vector<Real>(),
const std::vector<Real> &spread2 = std::vector<Real>(),
const std::vector<Real> &cappedRate2 = std::vector<Real>(),
const std::vector<Real> &flooredRate2 = std::vector<Real>(),
BusinessDayConvention paymentConvention1 = Following,
BusinessDayConvention paymentConvention2 = Following);
};
```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.