BLS IV calculated by QuantLib is different from Hull's

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

BLS IV calculated by QuantLib is different from Hull's

Alex Cicco
Hi All,

I am new to quant lib.  So, please forgive my newbie question. 

My System Quantlib + boost + Java Swig interface. 
I am using a Java testing code adapted from the work by  Richard Gomes and Tito Ingargiola on Equity Options.
The testing code is enclosed at the end of this email.

My trouble is:
I cannot get BLS European IV calculated by QuantLib tied out with the value generated by Hull's DerivativeGem

------------------------------------------------------------------------------------------------------------------------------
Here is my input for the computation of an equity option IV

Trading Date: 2008-12-01,
Underlying stock price: 55.08,
Option Strike: 42.5,
Option Type: Put
Option Price: 0.215,
riskFreeRate = 0.03;
dividendYield = 0.00;
Option Expiration Date: 2008-12-20 ( the Saturday following the third Friday of the month)
--> Option Time to Expiration: 15 days  (when counting trading days, I include 12/01/2008 as the option trading takes place at 9:30 of 12/01/2008)

--------------------------------------------------------------------------------------------------------------------------------------
Using the above input, and Hull's DerivativeGem Excel worksheet, I got an IV of 0.6897

-----------------------------------------------
Using QuantLib, I set

Try 1:
TodaysDate = 12/01/2008
SettlementDate =12/01/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7398648108461248

Try 2:
TodaysDate = 12/01/2008
SettlementDate =12/03/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7817627320081257

------------------------------------------------------------------------------------------------------------------------------------------------------

Could you advise on which parameter I set wrong in using QuantLib?

Thank you very much

Best regards,

Alex
------------------------------------------------------------------------------------------------------------------------------------------------------

My Java Testing Code goes here

package com.alexCicco.test.quantLibTest;


/*
 Copyright (C) 2007 Richard Gomes
 Copyright (C) 2007 Tito Ingargiola

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <[hidden email]>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

//package examples;

import org.quantlib.Actual365Fixed;
import org.quantlib.AmericanExercise;

import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;

import org.quantlib.AnalyticEuropeanEngine;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Calendar;
import org.quantlib.Date;

import org.quantlib.DayCounter;
import org.quantlib.EuropeanExercise;
import org.quantlib.Exercise;

import org.quantlib.FlatForward;

import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;

import org.quantlib.PlainVanillaPayoff;

import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;

import org.quantlib.TARGET;

import org.quantlib.VanillaOption;

import org.quantlib.YieldTermStructureHandle;

/**
 * Test Implied volatility of European options
 * @author Alex Cicco
 */
public class EuropeanIV {

    static {
        try {
            System.loadLibrary("QuantLibJNI");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
       
        long beginTime = System.currentTimeMillis();

        // our option
        Option.Type type = Option.Type.Put;
        double strike = 42.5;
        double underlying = 55.08;
        double riskFreeRate = 0.03;
        double dividendYield = 0.00;
        double volatility = 0.01;
       
        Date todaysDate = new Date(1, Month.December, 2008);
        Date settlementDate = new Date(1, Month.December, 2008);
        Settings.instance().setEvaluationDate(todaysDate);
               
        Date maturity = new Date(20, Month.December, 2008);
        DayCounter dayCounter = new Actual365Fixed();
        Calendar calendar = new TARGET();

        Exercise europeanExercise = new EuropeanExercise(maturity);
        Exercise americanExercise = new AmericanExercise(settlementDate, maturity);
 
        // define the underlying asset and the yield/dividend/volatility curves
        QuoteHandle underlyingH = new QuoteHandle(new SimpleQuote(underlying));
       
        YieldTermStructureHandle flatTermStructure =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, riskFreeRate, dayCounter));
       
        YieldTermStructureHandle flatDividendYield =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, dividendYield, dayCounter));
       
        BlackVolTermStructureHandle flatVolatility =
            new BlackVolTermStructureHandle(new BlackConstantVol(
                           settlementDate, calendar, volatility, dayCounter));

        BlackScholesMertonProcess stochasticProcess =
            new BlackScholesMertonProcess(underlyingH,
                                          flatDividendYield,
                                          flatTermStructure,
                                          flatVolatility);

        // options
        Payoff payoff = new PlainVanillaPayoff(type, strike);

        VanillaOption europeanOption =
            new VanillaOption(payoff, europeanExercise);
       
        VanillaOption americanOption =
            new VanillaOption(payoff, americanExercise);

        double optionPrice = 0.215;
       
        europeanOption.setPricingEngine(
                new AnalyticEuropeanEngine(stochasticProcess));
       
        double iv_european = europeanOption.impliedVolatility(optionPrice, stochasticProcess);
       
       
        double iv_american = americanOption.impliedVolatility(optionPrice, stochasticProcess);
       
        String fmt = "\n%-35s %-35s %-35s\n";
        System.out.printf(fmt, "Method", "European_IV", "American_IV");
        System.out.println("=====================================================================================");
       
        // Black-Scholes for European
        String method = "Black-Scholes";
        System.out.printf(fmt, new Object[] { method,
                                              iv_european,                                             
                                              Double.NaN } );      

        // Bjerksund and Stensland approximation for American
        method = "American: Bjerksund/Stensland";       
        System.out.printf(fmt, new Object[] { method,
                                              Double.NaN,
                                              iv_american } );

        long msecs = (System.currentTimeMillis()-beginTime);
        System.out.println("Run completed in "+msecs+" ms.");

    }
}



------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: BLS IV calculated by QuantLib is different from Hull's

animesh
Hi,
   In your calcuation and Hull White there is difference of 7%. There is no formula for calculating implied vol accurately. What traders/quants generally do is put an implied volatility in option pricing formula to price the option. If it matches the market price then you have the implied volatility.

For example Call Price = S N(d1) - K e^-(rT) N(d2)
d1 and d2 are again standard definitions d1 = (Log(S/K) + (r + sigma^2/2)(T))/(sigma (T)^0.5)
d2 = d1 - sigma (T)^0.5

What I would suggest is use the different volatilities in the range (0.60 - 0.80) to price the Put option and see which one is closest to the price you want.
You can do the same thing online if you want a rough check here.....
http://www.sitmo.com/live/OptionVanilla.html

Also am not sure if time is being calculated by Number of Days / 365 or Number of Days / 252.


On 9/6/10 9:46 PM, Alex Cicco wrote:
Hi All,

I am new to quant lib.  So, please forgive my newbie question. 

My System Quantlib + boost + Java Swig interface. 
I am using a Java testing code adapted from the work by  Richard Gomes and Tito Ingargiola on Equity Options.
The testing code is enclosed at the end of this email.

My trouble is:
I cannot get BLS European IV calculated by QuantLib tied out with the value generated by Hull's DerivativeGem

------------------------------------------------------------------------------------------------------------------------------
Here is my input for the computation of an equity option IV

Trading Date: 2008-12-01,
Underlying stock price: 55.08,
Option Strike: 42.5,
Option Type: Put
Option Price: 0.215,
riskFreeRate = 0.03;
dividendYield = 0.00;
Option Expiration Date: 2008-12-20 ( the Saturday following the third Friday of the month)
--> Option Time to Expiration: 15 days  (when counting trading days, I include 12/01/2008 as the option trading takes place at 9:30 of 12/01/2008)

--------------------------------------------------------------------------------------------------------------------------------------
Using the above input, and Hull's DerivativeGem Excel worksheet, I got an IV of 0.6897

-----------------------------------------------
Using QuantLib, I set

Try 1:
TodaysDate = 12/01/2008
SettlementDate =12/01/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7398648108461248

Try 2:
TodaysDate = 12/01/2008
SettlementDate =12/03/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7817627320081257

------------------------------------------------------------------------------------------------------------------------------------------------------

Could you advise on which parameter I set wrong in using QuantLib?

Thank you very much

Best regards,

Alex
------------------------------------------------------------------------------------------------------------------------------------------------------

My Java Testing Code goes here

package com.alexCicco.test.quantLibTest;


/*
 Copyright (C) 2007 Richard Gomes
 Copyright (C) 2007 Tito Ingargiola

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <[hidden email]>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

//package examples;

import org.quantlib.Actual365Fixed;
import org.quantlib.AmericanExercise;

import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;

import org.quantlib.AnalyticEuropeanEngine;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Calendar;
import org.quantlib.Date;

import org.quantlib.DayCounter;
import org.quantlib.EuropeanExercise;
import org.quantlib.Exercise;

import org.quantlib.FlatForward;

import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;

import org.quantlib.PlainVanillaPayoff;

import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;

import org.quantlib.TARGET;

import org.quantlib.VanillaOption;

import org.quantlib.YieldTermStructureHandle;

/**
 * Test Implied volatility of European options
 * @author Alex Cicco
 */
public class EuropeanIV {

    static {
        try {
            System.loadLibrary("QuantLibJNI");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
       
        long beginTime = System.currentTimeMillis();

        // our option
        Option.Type type = Option.Type.Put;
        double strike = 42.5;
        double underlying = 55.08;
        double riskFreeRate = 0.03;
        double dividendYield = 0.00;
        double volatility = 0.01;
       
        Date todaysDate = new Date(1, Month.December, 2008);
        Date settlementDate = new Date(1, Month.December, 2008);
        Settings.instance().setEvaluationDate(todaysDate);
               
        Date maturity = new Date(20, Month.December, 2008);
        DayCounter dayCounter = new Actual365Fixed();
        Calendar calendar = new TARGET();

        Exercise europeanExercise = new EuropeanExercise(maturity);
        Exercise americanExercise = new AmericanExercise(settlementDate, maturity);
 
        // define the underlying asset and the yield/dividend/volatility curves
        QuoteHandle underlyingH = new QuoteHandle(new SimpleQuote(underlying));
       
        YieldTermStructureHandle flatTermStructure =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, riskFreeRate, dayCounter));
       
        YieldTermStructureHandle flatDividendYield =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, dividendYield, dayCounter));
       
        BlackVolTermStructureHandle flatVolatility =
            new BlackVolTermStructureHandle(new BlackConstantVol(
                           settlementDate, calendar, volatility, dayCounter));

        BlackScholesMertonProcess stochasticProcess =
            new BlackScholesMertonProcess(underlyingH,
                                          flatDividendYield,
                                          flatTermStructure,
                                          flatVolatility);

        // options
        Payoff payoff = new PlainVanillaPayoff(type, strike);

        VanillaOption europeanOption =
            new VanillaOption(payoff, europeanExercise);
       
        VanillaOption americanOption =
            new VanillaOption(payoff, americanExercise);

        double optionPrice = 0.215;
       
        europeanOption.setPricingEngine(
                new AnalyticEuropeanEngine(stochasticProcess));
       
        double iv_european = europeanOption.impliedVolatility(optionPrice, stochasticProcess);
       
       
        double iv_american = americanOption.impliedVolatility(optionPrice, stochasticProcess);
       
        String fmt = "\n%-35s %-35s %-35s\n";
        System.out.printf(fmt, "Method", "European_IV", "American_IV");
        System.out.println("=====================================================================================");
       
        // Black-Scholes for European
        String method = "Black-Scholes";
        System.out.printf(fmt, new Object[] { method,
                                              iv_european,                                             
                                              Double.NaN } );      

        // Bjerksund and Stensland approximation for American
        method = "American: Bjerksund/Stensland";       
        System.out.printf(fmt, new Object[] { method,
                                              Double.NaN,
                                              iv_american } );

        long msecs = (System.currentTimeMillis()-beginTime);
        System.out.println("Run completed in "+msecs+" ms.");

    }
}


------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users

-- 
Regards,
Animesh Saxena

(http://quantanalysis.wordpress.com)
Ph: (+91)9920098221

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: BLS IV calculated by QuantLib is different from Hull's

Alex Cicco
Thank you very much, Animesh. 
My problem is solved.  Based on your suggestion, I change the dayCounter to Business252. 
Then everything ties out.

With my best regards,

Alex

On Mon, Sep 6, 2010 at 2:18 PM, animesh saxena <[hidden email]> wrote:
Hi,
   In your calcuation and Hull White there is difference of 7%. There is no formula for calculating implied vol accurately. What traders/quants generally do is put an implied volatility in option pricing formula to price the option. If it matches the market price then you have the implied volatility.

For example Call Price = S N(d1) - K e^-(rT) N(d2)
d1 and d2 are again standard definitions d1 = (Log(S/K) + (r + sigma^2/2)(T))/(sigma (T)^0.5)
d2 = d1 - sigma (T)^0.5

What I would suggest is use the different volatilities in the range (0.60 - 0.80) to price the Put option and see which one is closest to the price you want.
You can do the same thing online if you want a rough check here.....
http://www.sitmo.com/live/OptionVanilla.html

Also am not sure if time is being calculated by Number of Days / 365 or Number of Days / 252.


On 9/6/10 9:46 PM, Alex Cicco wrote:
Hi All,

I am new to quant lib.  So, please forgive my newbie question. 

My System Quantlib + boost + Java Swig interface. 
I am using a Java testing code adapted from the work by  Richard Gomes and Tito Ingargiola on Equity Options.
The testing code is enclosed at the end of this email.

My trouble is:
I cannot get BLS European IV calculated by QuantLib tied out with the value generated by Hull's DerivativeGem

------------------------------------------------------------------------------------------------------------------------------
Here is my input for the computation of an equity option IV

Trading Date: 2008-12-01,
Underlying stock price: 55.08,
Option Strike: 42.5,
Option Type: Put
Option Price: 0.215,
riskFreeRate = 0.03;
dividendYield = 0.00;
Option Expiration Date: 2008-12-20 ( the Saturday following the third Friday of the month)
--> Option Time to Expiration: 15 days  (when counting trading days, I include 12/01/2008 as the option trading takes place at 9:30 of 12/01/2008)

--------------------------------------------------------------------------------------------------------------------------------------
Using the above input, and Hull's DerivativeGem Excel worksheet, I got an IV of 0.6897

-----------------------------------------------
Using QuantLib, I set

Try 1:
TodaysDate = 12/01/2008
SettlementDate =12/01/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7398648108461248

Try 2:
TodaysDate = 12/01/2008
SettlementDate =12/03/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7817627320081257

------------------------------------------------------------------------------------------------------------------------------------------------------

Could you advise on which parameter I set wrong in using QuantLib?

Thank you very much

Best regards,

Alex
------------------------------------------------------------------------------------------------------------------------------------------------------

My Java Testing Code goes here

package com.alexCicco.test.quantLibTest;


/*
 Copyright (C) 2007 Richard Gomes
 Copyright (C) 2007 Tito Ingargiola

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <[hidden email]>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

//package examples;

import org.quantlib.Actual365Fixed;
import org.quantlib.AmericanExercise;

import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;

import org.quantlib.AnalyticEuropeanEngine;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Calendar;
import org.quantlib.Date;

import org.quantlib.DayCounter;
import org.quantlib.EuropeanExercise;
import org.quantlib.Exercise;

import org.quantlib.FlatForward;

import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;

import org.quantlib.PlainVanillaPayoff;

import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;

import org.quantlib.TARGET;

import org.quantlib.VanillaOption;

import org.quantlib.YieldTermStructureHandle;

/**
 * Test Implied volatility of European options
 * @author Alex Cicco
 */
public class EuropeanIV {

    static {
        try {
            System.loadLibrary("QuantLibJNI");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
       
        long beginTime = System.currentTimeMillis();

        // our option
        Option.Type type = Option.Type.Put;
        double strike = 42.5;
        double underlying = 55.08;
        double riskFreeRate = 0.03;
        double dividendYield = 0.00;
        double volatility = 0.01;
       
        Date todaysDate = new Date(1, Month.December, 2008);
        Date settlementDate = new Date(1, Month.December, 2008);
        Settings.instance().setEvaluationDate(todaysDate);
               
        Date maturity = new Date(20, Month.December, 2008);
        DayCounter dayCounter = new Actual365Fixed();
        Calendar calendar = new TARGET();

        Exercise europeanExercise = new EuropeanExercise(maturity);
        Exercise americanExercise = new AmericanExercise(settlementDate, maturity);
 
        // define the underlying asset and the yield/dividend/volatility curves
        QuoteHandle underlyingH = new QuoteHandle(new SimpleQuote(underlying));
       
        YieldTermStructureHandle flatTermStructure =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, riskFreeRate, dayCounter));
       
        YieldTermStructureHandle flatDividendYield =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, dividendYield, dayCounter));
       
        BlackVolTermStructureHandle flatVolatility =
            new BlackVolTermStructureHandle(new BlackConstantVol(
                           settlementDate, calendar, volatility, dayCounter));

        BlackScholesMertonProcess stochasticProcess =
            new BlackScholesMertonProcess(underlyingH,
                                          flatDividendYield,
                                          flatTermStructure,
                                          flatVolatility);

        // options
        Payoff payoff = new PlainVanillaPayoff(type, strike);

        VanillaOption europeanOption =
            new VanillaOption(payoff, europeanExercise);
       
        VanillaOption americanOption =
            new VanillaOption(payoff, americanExercise);

        double optionPrice = 0.215;
       
        europeanOption.setPricingEngine(
                new AnalyticEuropeanEngine(stochasticProcess));
       
        double iv_european = europeanOption.impliedVolatility(optionPrice, stochasticProcess);
       
       
        double iv_american = americanOption.impliedVolatility(optionPrice, stochasticProcess);
       
        String fmt = "\n%-35s %-35s %-35s\n";
        System.out.printf(fmt, "Method", "European_IV", "American_IV");
        System.out.println("=====================================================================================");
       
        // Black-Scholes for European
        String method = "Black-Scholes";
        System.out.printf(fmt, new Object[] { method,
                                              iv_european,                                             
                                              Double.NaN } );      

        // Bjerksund and Stensland approximation for American
        method = "American: Bjerksund/Stensland";       
        System.out.printf(fmt, new Object[] { method,
                                              Double.NaN,
                                              iv_american } );

        long msecs = (System.currentTimeMillis()-beginTime);
        System.out.println("Run completed in "+msecs+" ms.");

    }
}


------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users

-- 
Regards,
Animesh Saxena

(http://quantanalysis.wordpress.com)
Ph: (+91)9920098221


------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: BLS IV calculated by QuantLib is different from Hull's

Alex Cicco
Sub-subject: Why Business252() is so expensive in calculating IV of equity.

Hi All,

On compute IV using quantLib + Swig + JAVA, I thought my problem is solved after helpful input by Animesh. ( see the conversion below ). 

However, simply replacing the following statement
DayCounter dayCounter = new Actual365Fixed();
by
DayCounter dayCounter = new Business252();

I can tie out quantLib IV with Hull's one.  But the performance dropped SIGNIFICANTLY.

To compute IV of 9 million option quotes, using Actual365Fixed dayCounter, it takes about 20 min.
Using Business252(), it takes more than 18 hours to ONLY finish about 1/30 of the 9 million quotes. 

Is there a computational economic way to compute IV (using 250 day per year)?

Thank you very much.

Alex

On Mon, Sep 6, 2010 at 9:03 PM, Alex Cicco <[hidden email]> wrote:
Thank you very much, Animesh. 
My problem is solved.  Based on your suggestion, I change the dayCounter to Business252. 
Then everything ties out.

With my best regards,

Alex


On Mon, Sep 6, 2010 at 2:18 PM, animesh saxena <[hidden email]> wrote:
Hi,
   In your calcuation and Hull White there is difference of 7%. There is no formula for calculating implied vol accurately. What traders/quants generally do is put an implied volatility in option pricing formula to price the option. If it matches the market price then you have the implied volatility.

For example Call Price = S N(d1) - K e^-(rT) N(d2)
d1 and d2 are again standard definitions d1 = (Log(S/K) + (r + sigma^2/2)(T))/(sigma (T)^0.5)
d2 = d1 - sigma (T)^0.5

What I would suggest is use the different volatilities in the range (0.60 - 0.80) to price the Put option and see which one is closest to the price you want.
You can do the same thing online if you want a rough check here.....
http://www.sitmo.com/live/OptionVanilla.html

Also am not sure if time is being calculated by Number of Days / 365 or Number of Days / 252.


On 9/6/10 9:46 PM, Alex Cicco wrote:
Hi All,

I am new to quant lib.  So, please forgive my newbie question. 

My System Quantlib + boost + Java Swig interface. 
I am using a Java testing code adapted from the work by  Richard Gomes and Tito Ingargiola on Equity Options.
The testing code is enclosed at the end of this email.

My trouble is:
I cannot get BLS European IV calculated by QuantLib tied out with the value generated by Hull's DerivativeGem

------------------------------------------------------------------------------------------------------------------------------
Here is my input for the computation of an equity option IV

Trading Date: 2008-12-01,
Underlying stock price: 55.08,
Option Strike: 42.5,
Option Type: Put
Option Price: 0.215,
riskFreeRate = 0.03;
dividendYield = 0.00;
Option Expiration Date: 2008-12-20 ( the Saturday following the third Friday of the month)
--> Option Time to Expiration: 15 days  (when counting trading days, I include 12/01/2008 as the option trading takes place at 9:30 of 12/01/2008)

--------------------------------------------------------------------------------------------------------------------------------------
Using the above input, and Hull's DerivativeGem Excel worksheet, I got an IV of 0.6897

-----------------------------------------------
Using QuantLib, I set

Try 1:
TodaysDate = 12/01/2008
SettlementDate =12/01/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7398648108461248

Try 2:
TodaysDate = 12/01/2008
SettlementDate =12/03/2008,
Maturity Date = 12/20/2008.
I got an IV of 0.7817627320081257

------------------------------------------------------------------------------------------------------------------------------------------------------

Could you advise on which parameter I set wrong in using QuantLib?

Thank you very much

Best regards,

Alex
------------------------------------------------------------------------------------------------------------------------------------------------------

My Java Testing Code goes here

package com.alexCicco.test.quantLibTest;


/*
 Copyright (C) 2007 Richard Gomes
 Copyright (C) 2007 Tito Ingargiola

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <[hidden email]>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

//package examples;

import org.quantlib.Actual365Fixed;
import org.quantlib.AmericanExercise;

import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;

import org.quantlib.AnalyticEuropeanEngine;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Calendar;
import org.quantlib.Date;

import org.quantlib.DayCounter;
import org.quantlib.EuropeanExercise;
import org.quantlib.Exercise;

import org.quantlib.FlatForward;

import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;

import org.quantlib.PlainVanillaPayoff;

import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;

import org.quantlib.TARGET;

import org.quantlib.VanillaOption;

import org.quantlib.YieldTermStructureHandle;

/**
 * Test Implied volatility of European options
 * @author Alex Cicco
 */
public class EuropeanIV {

    static {
        try {
            System.loadLibrary("QuantLibJNI");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
       
        long beginTime = System.currentTimeMillis();

        // our option
        Option.Type type = Option.Type.Put;
        double strike = 42.5;
        double underlying = 55.08;
        double riskFreeRate = 0.03;
        double dividendYield = 0.00;
        double volatility = 0.01;
       
        Date todaysDate = new Date(1, Month.December, 2008);
        Date settlementDate = new Date(1, Month.December, 2008);
        Settings.instance().setEvaluationDate(todaysDate);
               
        Date maturity = new Date(20, Month.December, 2008);
        DayCounter dayCounter = new Actual365Fixed();
        Calendar calendar = new TARGET();

        Exercise europeanExercise = new EuropeanExercise(maturity);
        Exercise americanExercise = new AmericanExercise(settlementDate, maturity);
 
        // define the underlying asset and the yield/dividend/volatility curves
        QuoteHandle underlyingH = new QuoteHandle(new SimpleQuote(underlying));
       
        YieldTermStructureHandle flatTermStructure =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, riskFreeRate, dayCounter));
       
        YieldTermStructureHandle flatDividendYield =
            new YieldTermStructureHandle(new FlatForward(
                                  settlementDate, dividendYield, dayCounter));
       
        BlackVolTermStructureHandle flatVolatility =
            new BlackVolTermStructureHandle(new BlackConstantVol(
                           settlementDate, calendar, volatility, dayCounter));

        BlackScholesMertonProcess stochasticProcess =
            new BlackScholesMertonProcess(underlyingH,
                                          flatDividendYield,
                                          flatTermStructure,
                                          flatVolatility);

        // options
        Payoff payoff = new PlainVanillaPayoff(type, strike);

        VanillaOption europeanOption =
            new VanillaOption(payoff, europeanExercise);
       
        VanillaOption americanOption =
            new VanillaOption(payoff, americanExercise);

        double optionPrice = 0.215;
       
        europeanOption.setPricingEngine(
                new AnalyticEuropeanEngine(stochasticProcess));
       
        double iv_european = europeanOption.impliedVolatility(optionPrice, stochasticProcess);
       
       
        double iv_american = americanOption.impliedVolatility(optionPrice, stochasticProcess);
       
        String fmt = "\n%-35s %-35s %-35s\n";
        System.out.printf(fmt, "Method", "European_IV", "American_IV");
        System.out.println("=====================================================================================");
       
        // Black-Scholes for European
        String method = "Black-Scholes";
        System.out.printf(fmt, new Object[] { method,
                                              iv_european,                                             
                                              Double.NaN } );      

        // Bjerksund and Stensland approximation for American
        method = "American: Bjerksund/Stensland";       
        System.out.printf(fmt, new Object[] { method,
                                              Double.NaN,
                                              iv_american } );

        long msecs = (System.currentTimeMillis()-beginTime);
        System.out.println("Run completed in "+msecs+" ms.");

    }
}


------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users

-- 
Regards,
Animesh Saxena

(http://quantanalysis.wordpress.com)
Ph: (+91)9920098221



------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: BLS IV calculated by QuantLib is different from Hull's

Luigi Ballabio
On Wed, 2010-09-08 at 20:37 -0400, Alex Cicco wrote:
> Sub-subject: Why Business252() is so expensive in calculating IV of
> equity.

That's because in order to calculate the number of business days between
two dates d1 and d2, it has to loop on every date from d1 to d2 and
check whether it's a business day.  That's much more expensive than,
say, the actual/365 day counter, which calculates the number of days
between d1 and d2 simply as d2-d1.

Luigi


--

So little done, so much to do.
-- Cecil Rhodes



------------------------------------------------------------------------------
Automate Storage Tiering Simply
Optimize IT performance and efficiency through flexible, powerful,
automated storage tiering capabilities. View this brief to learn how
you can reduce costs and improve performance.
http://p.sf.net/sfu/dell-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: BLS IV calculated by QuantLib is different from Hull's

Alex Cicco
Luigi,

Thanks for the clarification.  I strat data into different dates. 
For each day, I only create one Business252 day counter.  It looks that I worked around the problem :)

Best regards,

Alex

On Fri, Sep 10, 2010 at 10:50 AM, Luigi Ballabio <[hidden email]> wrote:
On Wed, 2010-09-08 at 20:37 -0400, Alex Cicco wrote:
> Sub-subject: Why Business252() is so expensive in calculating IV of
> equity.

That's because in order to calculate the number of business days between
two dates d1 and d2, it has to loop on every date from d1 to d2 and
check whether it's a business day.  That's much more expensive than,
say, the actual/365 day counter, which calculates the number of days
between d1 and d2 simply as d2-d1.

Luigi


--

So little done, so much to do.
-- Cecil Rhodes




------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users