Bojan Nikolic: Using and Understanding the QuantLib Addin

[website home] | [BN Algorithms]

qlSwaption – create an object representing a swaption

Usage:

=qlSwaption(<ObjPrefix>, <VanillaSwap>,
            <Exercise>, <SettlementType>)
<ObjPrefix>

Optional prefix for names of objects created with this function

<VanillaSwap>

The underlying of the swaption, i.e., the swap that the buyer has the right but not the obligation to enter at a future date

<Exercise>

Object describing the when the swaption can be exercised. Created with for example qlEuropeanExercise – create an object defining a derivative that can only be exercised at maturity

<SettlementType>

How the swaption is settled. Possible options are “Cash” or “Physical”

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.PropertyMatrix;
import co.uk.bnikolic.qlw.DoubleVector;

public class qlSwaption  {

    public static void main(String[] args) throws Exception {
        
        String swap=mkSwap();
        String exercise=qlw.qlEuropeanExercise("exercise", 
                                               new property_t("41030"),
                                               qlw.OH_NULL(),
                                               qlw.OH_NULL(),
                                               false);
        String swaption=qlw.qlSwaption("swaption",
                                       swap, 
                                       exercise, 
                                       "Cash",
                                       qlw.OH_NULL(),
                                       qlw.OH_NULL(),
                                       false);

    }

    // See
    // http://www.bnikolic.co.uk/ql/addindoc/f/qlMakeVanillaSwap.html
    // for explanation of this function
    public static String mkSwap() {
        PropertyVector datesList= new PropertyVector();
        datesList.add(new property_t("0D"));
        datesList.add(new property_t("1Y"));
        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",
                                   qlw.OH_NULL(),
                                   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);
        return swap;

    }

}