Bojan Nikolic: Using and Understanding the QuantLib Addin

[website home] | [BN Algorithms]

QLW – QuantLib-Addin like interface from Java and Python

The purpose of QLW is to present interface of QuantLib Excel Addin in Java and Python. This makes easy direct translation of Excel worksheets that use QuantLib Addin into automated large-scale programs.

In this documentation you will see examples as QLW code as well as transcribed Excel tables. Compared to the standard SWIG wrap of QuantLib, QLW has the following advantages:

  • Higher level interface that hides some complexities that are not necessary for application development

  • Independent memory management that does not suffer from some inevitable shortcomings in normal C++ applications when wrapped in Java (see, e.g., https://www.bnikolic.co.uk/blog/cpp-swig-java-raii.html)

  • One-to-one correspondence to the QauntLib Addin (we will be happy to help you translate your spreadsheets to Java!)

  • Easy use on grid/cloud distributed computing platforms

For more information about QLW, including licensing options and support, see this URL or contact us at <webs@bnikolic.co.uk>.

An example QLW/Java application is shown below:

// 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;

public class  AmericanOptionExample {

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

        property_t today=new property_t(35930); 
        property_t settlementdate=new property_t(35932);
        property_t exercisedate=new property_t(36297);

        property_t dcc=new property_t("Actual/365 (Fixed)");

        qlw.qlSettingsSetEvaluationDate(today,
                                        qlw.OH_NULL());

        String payoff=qlw.qlStrikedTypePayoff("payoff", 
                                              "Vanilla", 
                                              "Put", 
                                              40.0,
                                              qlw.OH_NULL(),
                                              qlw.OH_NULL(),
                                              qlw.OH_NULL(),
                                              false
                                              );

        String exercise=qlw.qlAmericanExercise("exercise", 
                                               settlementdate,
                                               exercisedate,
                                               new property_t(false),
                                               qlw.OH_NULL(),
                                               qlw.OH_NULL(),
                                               false);

        String option=qlw.qlVanillaOption("option",
                                          payoff, 
                                          exercise,
                                          qlw.OH_NULL(),
                                          qlw.OH_NULL(),
                                          false);


        String vol=qlw.qlBlackConstantVol("vol",
                                          settlementdate, 
                                          "TARGET", 
                                          0.2, 
                                          dcc,
                                          qlw.OH_NULL(),
                                          qlw.OH_NULL(),
                                          false);

        String process=qlw.qlGeneralizedBlackScholesProcess("process", 
                                                            "vol",
                                                            36.0, 
                                                            dcc,
                                                            settlementdate, 
                                                            0.06, 
                                                            0.00,
                                                            qlw.OH_NULL(),
                                                            qlw.OH_NULL(),
                                                            false)        ;


        String AmericanEngines[] = { "BAWA", "BSA", "FDA", "JR", "CRR", "AEQPB", "TRI", "TIAN", "LR", "JOSHI"};

        for (String ename : AmericanEngines ) {
            
            String pengine;

            if ( ename == "BAWA" || ename ==  "BSA")
                {
                pengine=qlw.qlPricingEngine("pengine-"+ename, 
                                            ename,
                                            process,
                                            qlw.OH_NULL(),
                                            qlw.OH_NULL(),
                                            false);
                }
            else
                {
                pengine=qlw.qlBinomialPricingEngine("pengine-"+ename, 
                                                    ename,
                                                    process,
                                                    50,
                                                    qlw.OH_NULL(),
                                                    qlw.OH_NULL(),
                                                    false);
                }
            
            qlw.qlInstrumentSetPricingEngine(option, pengine,
                                             qlw.OH_NULL());
            
            System.out.println("NPV using " + ename +": "+ qlw.qlInstrumentNPV(option,
                                                                               qlw.OH_NULL()));
        }
        
                

    }

}