Confusion about VanillaOption::impliedVolatility

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

Confusion about VanillaOption::impliedVolatility

alex
Hi, I'm finding the implied volatility of an option two ways: solving with a Brent solver while using a BlackScholesCalculator; and setting the pricing engine to CoxRoss and then calling VanillaOption.impliedVolatility. The second way is because I want to factor in dividends.

The first way doesn't crash, but the second one does, throwing "root not bracketed". By now, I've been looking through my code and the QuantLib code on Github for a little bit of time.

I don't know precisely what's going wrong, but I have a question about this line [0]. Why is volQuote not set to a value?

[0] https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/vanillaoption.cpp#L48


Thanks.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Confusion about VanillaOption::impliedVolatility

Luigi Ballabio
Hi Alexander,
    any value set to volQuote at that point would be overwritten soon after, so we don't bother setting one. (It's set inside the function-call operator of PriceError, called by the Brent solver in ImpliedVolatilityHelper; see <https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/impliedvolatility.cpp#L51>).

This said:
1) the "root not bracketed" error means that the solution is outside the range of the solver; the price you're passing is either so high that even a 400% volatility can't reach it, or so low that even a null volatility can't reproduce it.
2) I'm not sure about the way you're going about your problem. For one thing, setting the engine to Cox-Ross doesn't hurt, but it doesn't have effect on the implied-volatility calculation, either: the implementation uses the analytic formula anyway. Also, I'm not sure how you're managing dividends. VanillaOption doesn't use discrete dividends, so you can't really factor them into the target price (this might be the reason the solver is failing to find a root). If you're using a continuous dividend yield, that's ok; otherwise, you should be using DividendVanillaOption instead.

Anyway: if you're still blocked, try posting an example of what you're trying to do. It will make it easier to diagnose the problem exactly.

Hope this helps,
    Luigi


On Mon, Mar 16, 2015 at 8:01 PM, Alexander Lamana <[hidden email]> wrote:
Hi, I'm finding the implied volatility of an option two ways: solving with a Brent solver while using a BlackScholesCalculator; and setting the pricing engine to CoxRoss and then calling VanillaOption.impliedVolatility. The second way is because I want to factor in dividends.

The first way doesn't crash, but the second one does, throwing "root not bracketed". By now, I've been looking through my code and the QuantLib code on Github for a little bit of time.

I don't know precisely what's going wrong, but I have a question about this line [0]. Why is volQuote not set to a value?

[0] https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/vanillaoption.cpp#L48


Thanks.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Confusion about VanillaOption::impliedVolatility

alex
I'm using the following option (and pretending as though the current day is the quote date, i.e.  Settings::instance().evaluationDate() = quote_date):

Quote Date: 12/19/2014
Expiration: 1/17/2015
Strike: 205.0
Type: Put
Spot: 205.74
Dividend Amount: 0.82461 (in dollars, not a percentage)
Risk Free Rate: 0.0002

To check my results, I was given that this option has an implied volatility of 0.1441. So, anything calculated should be close to that.

For the dividend, I'm just following what I saw in an online example and using a continuous yield.

Let me put this bit of code in a Gist for you. That may be easiest to read. https://gist.github.com/aml3/65038735906fd2b14e1f

Is there anything unusual about how VanillaOption.impliedVolatility works?

On Mon, Mar 16, 2015 at 6:16 PM, Luigi Ballabio <[hidden email]> wrote:
Hi Alexander,
    any value set to volQuote at that point would be overwritten soon after, so we don't bother setting one. (It's set inside the function-call operator of PriceError, called by the Brent solver in ImpliedVolatilityHelper; see <https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/impliedvolatility.cpp#L51>).

This said:
1) the "root not bracketed" error means that the solution is outside the range of the solver; the price you're passing is either so high that even a 400% volatility can't reach it, or so low that even a null volatility can't reproduce it.
2) I'm not sure about the way you're going about your problem. For one thing, setting the engine to Cox-Ross doesn't hurt, but it doesn't have effect on the implied-volatility calculation, either: the implementation uses the analytic formula anyway. Also, I'm not sure how you're managing dividends. VanillaOption doesn't use discrete dividends, so you can't really factor them into the target price (this might be the reason the solver is failing to find a root). If you're using a continuous dividend yield, that's ok; otherwise, you should be using DividendVanillaOption instead.

Anyway: if you're still blocked, try posting an example of what you're trying to do. It will make it easier to diagnose the problem exactly.

Hope this helps,
    Luigi


On Mon, Mar 16, 2015 at 8:01 PM, Alexander Lamana <[hidden email]> wrote:
Hi, I'm finding the implied volatility of an option two ways: solving with a Brent solver while using a BlackScholesCalculator; and setting the pricing engine to CoxRoss and then calling VanillaOption.impliedVolatility. The second way is because I want to factor in dividends.

The first way doesn't crash, but the second one does, throwing "root not bracketed". By now, I've been looking through my code and the QuantLib code on Github for a little bit of time.

I don't know precisely what's going wrong, but I have a question about this line [0]. Why is volQuote not set to a value?

[0] https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/vanillaoption.cpp#L48


Thanks.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Confusion about VanillaOption::impliedVolatility

Luigi Ballabio
Hi Alex,
    you're passing to impliedVolatility() the price of the underlying, which is way too high.  You have to pass the price of the option instead.

Luigi


On Tue, Mar 17, 2015 at 3:46 PM, Alexander Lamana <[hidden email]> wrote:
I'm using the following option (and pretending as though the current day is the quote date, i.e.  Settings::instance().evaluationDate() = quote_date):

Quote Date: 12/19/2014
Expiration: 1/17/2015
Strike: 205.0
Type: Put
Spot: 205.74
Dividend Amount: 0.82461 (in dollars, not a percentage)
Risk Free Rate: 0.0002

To check my results, I was given that this option has an implied volatility of 0.1441. So, anything calculated should be close to that.

For the dividend, I'm just following what I saw in an online example and using a continuous yield.

Let me put this bit of code in a Gist for you. That may be easiest to read. https://gist.github.com/aml3/65038735906fd2b14e1f

Is there anything unusual about how VanillaOption.impliedVolatility works?

On Mon, Mar 16, 2015 at 6:16 PM, Luigi Ballabio <[hidden email]> wrote:
Hi Alexander,
    any value set to volQuote at that point would be overwritten soon after, so we don't bother setting one. (It's set inside the function-call operator of PriceError, called by the Brent solver in ImpliedVolatilityHelper; see <https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/impliedvolatility.cpp#L51>).

This said:
1) the "root not bracketed" error means that the solution is outside the range of the solver; the price you're passing is either so high that even a 400% volatility can't reach it, or so low that even a null volatility can't reproduce it.
2) I'm not sure about the way you're going about your problem. For one thing, setting the engine to Cox-Ross doesn't hurt, but it doesn't have effect on the implied-volatility calculation, either: the implementation uses the analytic formula anyway. Also, I'm not sure how you're managing dividends. VanillaOption doesn't use discrete dividends, so you can't really factor them into the target price (this might be the reason the solver is failing to find a root). If you're using a continuous dividend yield, that's ok; otherwise, you should be using DividendVanillaOption instead.

Anyway: if you're still blocked, try posting an example of what you're trying to do. It will make it easier to diagnose the problem exactly.

Hope this helps,
    Luigi


On Mon, Mar 16, 2015 at 8:01 PM, Alexander Lamana <[hidden email]> wrote:
Hi, I'm finding the implied volatility of an option two ways: solving with a Brent solver while using a BlackScholesCalculator; and setting the pricing engine to CoxRoss and then calling VanillaOption.impliedVolatility. The second way is because I want to factor in dividends.

The first way doesn't crash, but the second one does, throwing "root not bracketed". By now, I've been looking through my code and the QuantLib code on Github for a little bit of time.

I don't know precisely what's going wrong, but I have a question about this line [0]. Why is volQuote not set to a value?

[0] https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/vanillaoption.cpp#L48


Thanks.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--




--

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Confusion about VanillaOption::impliedVolatility

alex
Hi Luigi,

Thanks! That did the trick. I updated the gist to reflect that change.


Thanks,
Alex


On Tue, Mar 17, 2015 at 1:25 PM, Luigi Ballabio <[hidden email]> wrote:
Hi Alex,
    you're passing to impliedVolatility() the price of the underlying, which is way too high.  You have to pass the price of the option instead.

Luigi


On Tue, Mar 17, 2015 at 3:46 PM, Alexander Lamana <[hidden email]> wrote:
I'm using the following option (and pretending as though the current day is the quote date, i.e.  Settings::instance().evaluationDate() = quote_date):

Quote Date: 12/19/2014
Expiration: 1/17/2015
Strike: 205.0
Type: Put
Spot: 205.74
Dividend Amount: 0.82461 (in dollars, not a percentage)
Risk Free Rate: 0.0002

To check my results, I was given that this option has an implied volatility of 0.1441. So, anything calculated should be close to that.

For the dividend, I'm just following what I saw in an online example and using a continuous yield.

Let me put this bit of code in a Gist for you. That may be easiest to read. https://gist.github.com/aml3/65038735906fd2b14e1f

Is there anything unusual about how VanillaOption.impliedVolatility works?

On Mon, Mar 16, 2015 at 6:16 PM, Luigi Ballabio <[hidden email]> wrote:
Hi Alexander,
    any value set to volQuote at that point would be overwritten soon after, so we don't bother setting one. (It's set inside the function-call operator of PriceError, called by the Brent solver in ImpliedVolatilityHelper; see <https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/impliedvolatility.cpp#L51>).

This said:
1) the "root not bracketed" error means that the solution is outside the range of the solver; the price you're passing is either so high that even a 400% volatility can't reach it, or so low that even a null volatility can't reproduce it.
2) I'm not sure about the way you're going about your problem. For one thing, setting the engine to Cox-Ross doesn't hurt, but it doesn't have effect on the implied-volatility calculation, either: the implementation uses the analytic formula anyway. Also, I'm not sure how you're managing dividends. VanillaOption doesn't use discrete dividends, so you can't really factor them into the target price (this might be the reason the solver is failing to find a root). If you're using a continuous dividend yield, that's ok; otherwise, you should be using DividendVanillaOption instead.

Anyway: if you're still blocked, try posting an example of what you're trying to do. It will make it easier to diagnose the problem exactly.

Hope this helps,
    Luigi


On Mon, Mar 16, 2015 at 8:01 PM, Alexander Lamana <[hidden email]> wrote:
Hi, I'm finding the implied volatility of an option two ways: solving with a Brent solver while using a BlackScholesCalculator; and setting the pricing engine to CoxRoss and then calling VanillaOption.impliedVolatility. The second way is because I want to factor in dividends.

The first way doesn't crash, but the second one does, throwing "root not bracketed". By now, I've been looking through my code and the QuantLib code on Github for a little bit of time.

I don't know precisely what's going wrong, but I have a question about this line [0]. Why is volQuote not set to a value?

[0] https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/vanillaoption.cpp#L48


Thanks.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--




--


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users