Bojan Nikolic: Using and Understanding the QuantLib Addin

[website home] | [BN Algorithms]

Valuing an equity option using the simple Black-Scholes Model

This example illustrates pricing of vanilla options using a constant volatility Black-Scholes Model. The process of pricing the option consists of three logical steps:

  1. Creating a description of the process governing the price of the underlying. In this case this is done using functions qlGeneralizedBlackScholesProcess and qlBlackConstantVol. The interest rates is defined by single values for the risk-free rate and the dividend yield (dividends are assumed to be continuous)

  2. Create a description of the option to price. This is done by combination of calls to qlEuropeanExercise, qlStrikedTypePayoff and qlVanillaOption

  3. Create a pricing engine and assign it to be used for pricing the derivative

The example prices a call option with strike at 110 and exercise date on 1st June 2012. The volatility is specified to be 0.25, today’s date is 1st June 2011, the interest free rate is assumed to be 5% and the dividend yield is 2%.

today’s date

2011-06-01

->

today’s date

2011-06-01

set global evaluation date

=qlSettingsSetEvaluationDate(R[-1]C)

->

set global evaluation date

nil

settlement date

=R[-2]C+2

->

settlement date

2011-06-03

calendar

TARGET

->

calendar

TARGET

volatility

0.25

->

volatility

0.25

day counter

Actual/365 (Fixed)

->

day counter

Actual/365 (Fixed)

black constant vol object

=qlBlackConstantVol(“blackvol1”,R[-4]C,R[-3]C,R[-2]C,R[-1]C)

->

black constant vol object

blackvol1#0009

underlying

100

->

underlying

100

risk free rate

0.05

->

risk free rate

0.05

dividend yield

0.02

->

dividend yield

0.02

stochastic process object

=qlGeneralizedBlackScholesProcess(“blackscholes1”,R[-4]C,R[-3]C,R[-5]C,R[-8]C,R[-2]C,R[-1]C)

->

stochastic process object

blackscholes1#0016

exercise date

2012-06-01

->

exercise date

2012-06-01

exercise object

=qlEuropeanExercise(“eu_exercise2”,R[-1]C)

->

exercise object

eu_exercise2#0005

payoff type

Vanilla

->

payoff type

Vanilla

option type

CALL

->

option type

CALL

strike

110

->

strike

110

striked type payoff

=qlStrikedTypePayoff(“eu_payoff”,R[-3]C,R[-2]C,R[-1]C)

->

striked type payoff

eu_payoff#0007

pricing engine

=qlPricingEngine(“eur_example_engine”,”AE”,R[-7]C)

->

pricing engine

eur_example_engine#0017

european option

=qlVanillaOption(“european_option”,R[-2]C,R[-6]C)

->

european option

european_option#0012

set engine

=qlInstrumentSetPricingEngine(R[-1]C,R[-2]C)

->

set engine

nil

NPV

=qlInstrumentNPV(R[-2]C,R[-1]C)

->

NPV

7.10

Here is the same example 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;

public class BlackScholesSimple {

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

        property_t today=new property_t(40695);
        
        property_t settlementdate=new property_t(40697);
        property_t excersisedate=new property_t(41061);

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

        qlw.qlSettingsSetEvaluationDate(today);

        String payoff=qlw.qlStrikedTypePayoff("payoff", 
                                              "Vanilla", 
                                              "Call", 
                                              110.0,
                                              qlw.OH_NULL()
                                              );

        String exercise=qlw.qlEuropeanExercise("exercise", 
                                               excersisedate);

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


        String vol=qlw.qlBlackConstantVol("vol",
                                          settlementdate, 
                                          "TARGET", 
                                          0.25, 
                                          dcc);

        String process=qlw.qlGeneralizedBlackScholesProcess("process", 
                                                            "vol",
                                                            100.0, 
                                                            dcc,
                                                            settlementdate, 
                                                            0.05, 
                                                            0.02)        ;

        String pengine=qlw.qlPricingEngine("pengine", 
                                           "AE",
                                           process);

        qlw.qlInstrumentSetPricingEngine(option, pengine);

        System.out.println("NPV: "+ qlw.qlInstrumentNPV(option));
        
                

    }

}