3
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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);
};
$\endgroup$
  • $\begingroup$ Thanks a lot, I will try with this class. Is there a way to include also the case of cross-currency swap? $\endgroup$ – opt Sep 17 at 14:14
  • $\begingroup$ AFAIK no, you could of course have two swaps with two different currencies and with zero fixed rate, and handle the FX conversions yourself (compute npv then convert it using the Fx spot). But I don't know about any Xccy basis swap class in QL. $\endgroup$ – byouness Sep 17 at 14:21
  • $\begingroup$ I see, so if I have EURUSD and collateralized in USD, I will create a portfolio of a EUR IRS and USD IRS. Then the USD IRS is priced as usual, discounting with USD OIS curve. For the EUR IRS I will have to use the usual EUR projection curve but discounting with the USD-implied EUR OIS curve? No other trick to be done? $\endgroup$ – opt Sep 17 at 15:57
  • $\begingroup$ You will use for USD and EUR the same curves you would have used had there been a CrossCurrencySwap class in QuantLib, then to price, you get the NPV of each leg and then convert e.g. the EUR leg's NPV to USD using the FX spot. What do you think? $\endgroup$ – byouness Sep 18 at 8:57

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.