Bojan Nikolic: Using and Understanding the QuantLib Addin

[website home] | [BN Algorithms]

qlMakeVanillaSwap – Make a vanilla interest rate swap object

Creates an object representing a vanilla interest rate swap, i.e., a swap of a fixed rate for a floating rate defined as a spread on top of a standard index. The payment frequency of the fixed leg is defined by the currency of the floating index: 6months in case of GBP and 1 year in case of other currencies (to check the payment schedule use the function qlSwapLegAnalysis()). The spot date of the swap is defined by the fixing days calendar of the floating leg. The fixed rate can be omitted from the call to the function in which case it is set to the fair rate. See view-only spreadsheet.

Usage:

=qlMakeVanillaSwap(<ObjPrefix>, <SwapTenor>,
                   <IborIndex>, <FixedRate>,
                   <ForwardStart>, <FixDayCounter>,
                   <Spread>,
                   <PricingEngineID>)
<ObjPrefix>

Usual meaning, can be left blank.

<SwapTenor>

Duration of the interest rate swap, expressed as relative length of time. For example “5Y” or “9M”. See Periods of time in QuantLib

<IborIndex>

Object that defines the index which is the reference for the floating leg of the swap. For example, an Euribor index (see qlEURIBOR – create an object representing the Euribor index)

<FixedRate>

The interest rate on the fixed leg of the swap

<ForwardStart>

A time period to specify that the swap starts in the future. Use “0D” or leave empty for immediate start.

<FixDayCounter>

Day Counting convention used for computing the accrued interest on the fixed leg of the swap (see Day Count(ing) Conventions). Note the day counting convention of the floating leg is defined by the index it is referencing.

<Spread>

Optional spread above the reference index at which the floating leg accrues interest

<PricingEngineID>

Object to be used to price the swap

Example

Below is a minimal example to create a vanilla swap:

  1. First, a yield curve is created using qlInterpolatedYieldCurve (see qlInterpolatedYieldCurve – Create a yield curve that interpolates between supplied data) function and based on only two data points

  2. Next, a pricing engine for swaps is created based on this yeild curve

  3. Also, a Euribor object is created using the qlEuribor to represent the floating leg of the swap

  4. Finally, the interest rate swap object is created using the qlMakeVanillaSwap function

Here is the example itself:

0D

nil

->

0D

nil

10Y

nil

->

10Y

nil

=qlInterpolatedYieldCurve(, R[-2]C:R[-1]C,R[-2]C[1]:R[-1]C[1], “TARGET”, “Actual/360”,,,”ZeroYield”,)

yield curve (needed for pricing engine)

->

obj_00004#0004

yield curve (needed for pricing engine)

=qlDiscountingSwapEngine(,R[-1]C)

pricing engine

->

obj_00005#0004

pricing engine

=qlEuribor(,”6M”)

Definition of the floating leg

->

obj_00006#0002

Definition of the floating leg

=qlMakeVanillaSwap(,”5Y”, R[-1]C,0.01,”0D”,”Actual/360”,0,R[-2]C)

Creates the actual swap

->

obj_00007#0005

Creates the actual swap

Here is example usage in QLW – QuantLib-Addin like interface from Java and Python

// Copyright (C) 2012 Bojan Nikolic <bojan@bnikolic.co.uk>
//

import co.uk.bnikolic.qlw.property_t;
import co.uk.bnikolic.qlw.qlw;
import co.uk.bnikolic.qlw.StringVector;
import co.uk.bnikolic.qlw.LongVector;
import co.uk.bnikolic.qlw.PropertyVector;
import co.uk.bnikolic.qlw.DoubleVector;

public class qlMakeVanillaSwap {
    
    public static void main(String[] args) throws Exception {

        PropertyVector datesList= new PropertyVector();
        datesList.add(new property_t("0D"));
        datesList.add(new property_t("10Y"));
        DoubleVector ratesList=new DoubleVector();
        ratesList.add(0.01);
        ratesList.add(0.01);

        property_t dcc=new property_t("Actual/365 (Fixed)");
        
        String curve=qlw.qlInterpolatedYieldCurve("curve",
                                                  datesList,  
                                                  ratesList,
                                                  "TARGET", dcc,
                                                  new PropertyVector(), 
                                                  new PropertyVector(),
                                                  new property_t("ZeroYield"), 
                                                  new property_t("LogLinear"),
                                                  qlw.OH_NULL(),
                                                  qlw.OH_NULL(),
                                                  false);

        String engine=qlw.qlDiscountingSwapEngine("engine", curve,
                                                  qlw.OH_NULL(),
                                                  qlw.OH_NULL(),
                                                  qlw.OH_NULL(),
                                                  qlw.OH_NULL(),
                                                  qlw.OH_NULL(),
                                                  false);

        String index=qlw.qlEuribor("index","6M",
                                   new property_t(curve),
                                   qlw.OH_NULL(),
                                   qlw.OH_NULL(),
                                   false);

        String swap=qlw.qlMakeVanillaSwap("swap",
                                          "5Y",
                                          index,
                                          new property_t(0.01),
                                          "0D",
                                          new property_t("Actual/360"),
                                          new property_t(0.0),
                                          engine,
                                          qlw.OH_NULL(),
                                          qlw.OH_NULL(),
                                          false);

        System.out.println("Swap fair rate: " +
                           qlw.qlVanillaSwapFairRate(swap, qlw.OH_NULL()));
        
    }

}