I have been adding greeks from the book to my index options spreadsheet.I have a minor technical question.In the second edition page 454 there is some Newton-Raphson IV code (shown below for convenience).Do you think the author may be checking for a lack of convergence by testing whether the price error ever increases between iterations? the test being Abs(cm - ci) <= minDiffIf so, I think there is a bug in the code.Since minDiff is always set to Abs(cm - ci) shortly before the while loop test executes, Abs(cm - ci) <= minDiff is always true.I checked the errata at http://www.espenhaug.com/ and found no correction.I can correct the test for convergence.But I would like to make sure I am correctly guessing the intended functionality. Thanks.Public Function GImpliedVolatilityNR(CallPutFlag As String, S As Double, X _As Double, T As Double, r As Double, B As Double, cm As Double, epsilon As Double) Dim vi As Double, ci As Double Dim vegai As Double Dim minDiff As Double 'Manaster and Koehler seed value (vi) vi = Sqr(Abs(Log(S / X) + r * T) * 2 / T) ci = GBlackScholes(CallPutFlag, S, X, T, r, B, vi) vegai = GVega(S, X, T, r, B, vi) minDiff = Abs(cm - ci) While Abs(cm - ci) >= epsilon And Abs(cm - ci) <= minDiff vi = vi - (ci - cm) / vegai ci = GBlackScholes(CallPutFlag, S, X, T, r, B, vi) vegai = GVega(S, X, T, r, B, vi) minDiff = Abs(cm - ci) Wend If Abs(cm - ci) < epsilon Then GImpliedVolatilityNR = vi Else GImpliedVolatilityNR = "NA"End Function

tthrift yes good point, looks like my test "Abs(cm - ci) <= minDiff " indeed always is true and have no function. And yes this is clearly not the best algorithm for finding implied vol. I will get some time to start updating my error list now. I have been quite busy some years now collecting formulas, not from people anymore (not much of my interest anymore), but from nature. "I can correct the test for convergence." please tell me tthrift, I have been kind of away from option pricing algorithms for some years and need to brush up my knowledge.

Last edited by Collector on November 24th, 2014, 11:00 pm, edited 1 time in total.

- Cuchulainn
**Posts:**59677**Joined:****Location:**Amsterdam-
**Contact:**

BTW, Collector, George Francis Fitzgerald did his relativity experiments on the cricket pitch where yours truly gave judo demos in student week 1974.The building on the right is the Physics dept.

Last edited by Cuchulainn on November 24th, 2014, 11:00 pm, edited 1 time in total.

- Cuchulainn
**Posts:**59677**Joined:****Location:**Amsterdam-
**Contact:**

I used the fixed point iteration for this very problem and it worked very well. Maybe for the 3rd edition? QuoteIn order to compute the implied volatility values in Table 1 (article Wilmott, Lewis, Duffy) we use the Black Scholes formula for calls and puts using the option values that we found using ADE. There are many methods to solve this nonlinear equation and in this case we used the fixed-point method in combination with Aitken?s delta-squared process to accelerate convergence. It is worth nothing that the fixed-point method converges for any initial guess because the corresponding iteration function is a contraction (Haaser (1991)). This is in contrast to the Newton Raphson and Bisection methods (for example), where it can sometimes be an issue in finding good starting values for these iterative methods. BTW the NR method can give problem when fitting yield for some short rate models. It is not robust, at least not always.

Last edited by Cuchulainn on November 24th, 2014, 11:00 pm, edited 1 time in total.

QuoteOriginally posted by: CuchulainnBTW, Collector, George Francis Fitzgerald did his relativity experiments on the cricket pitch where yours truly gave judo demos in student week 1974.The building on the right is the Physics dept.long time since I did Judo now, but I still know how to fall (most important), forward and backward roll is part of me. I can still land quite softly...but yes there was also that one time when my elbow broke in pieces (a Norwegian Championship fight, against they guy that won my weight class).

Last edited by Collector on November 25th, 2014, 11:00 pm, edited 1 time in total.

QuoteOriginally posted by: Collector... I will get some time to start updating my error list now. I have been quite busy some years now collecting formulas, not from people anymore (not much of my interest anymore), but from nature. Congratulations on your new book!!! I certainly did not expect that you would respond. Thanks for doing so.I imagined you would still be too busy doing somersaults after completing such a large involved project.Quote"I can correct the test for convergence." please tell me tthrift, I have been kind of away from option pricing algorithms for some years and need to brush up my knowledge.LOL.Collector, Perhaps I did not choose my words carefully enough.I claim no ability to provide insight into convergence. However, if the algorithm should indeed exit the while loop upon an increase in the magnitude of the Price error.ie "Abs(cm - ci) <= minDiff "Then I might be competent enough to rearrange code to accomplish that task.I will proceed under that assumption and will happily provide rearranged code for your amusement.Thanks for your options formula collection efforts.

QuoteOriginally posted by: CuchulainnI used the fixed point iteration for this very problem and it worked very well. Maybe for the 3rd edition? QuoteIn order to compute the implied volatility values in Table 1 (article Wilmott, Lewis, Duffy) we use the Black Scholes formula for calls and puts using the option values that we found using ADE. There are many methods to solve this nonlinear equation and in this case we used the fixed-point method in combination with Aitken?s delta-squared process to accelerate convergence. It is worth nothing that the fixed-point method converges for any initial guess because the corresponding iteration function is a contraction (Haaser (1991)). This is in contrast to the Newton Raphson and Bisection methods (for example), where it can sometimes be an issue in finding good starting values for these iterative methods. BTW the NR method can give problem when fitting yield for some short rate models. It is not robust, at least not always.My current needs for IV calculation are pretty simple. But if "you" say that something else would be more robust, I'm all ears. If I can find the time I would like to simulate the expectation of a set of trade management rules.I am guessing that might require core routines that are as robust and accurate as can be practical.Thanks for the response and the references. I'll try to track down the info and see if I can understand enough of it to pursue your hint.

QuoteOriginally posted by: tthrift...I will proceed under that assumption and will happily provide rearranged code for your amusement.fwiw.The most simple fix I found was to move the statement minDiff = Abs(cm - ci)from the end of the while loop to the beginning of the while loop.For the fun of it I also added some temporary/crude error checks for divergence and vega's approaching zero.I tested it lightly using today's closing prices for the RUT DEC calls and puts.It seemed to behave pretty well.For really deep in the money calls it started to show some issues.But that was expected.Public Function GImpliedVolatilityNR(CallPutFlag As String, S As Double, x _As Double, T As Double, r As Double, b As Double, cm As Double, epsilon As Double)Dim vi As Double, ci As DoubleDim vegai As DoubleDim minDiff As Double'Manaster and Koehler seed value (vi)vi = Sqr(Abs(Log(S / x) + r * T) * 2 / T)ci = GBlackScholes(CallPutFlag, S, x, T, r, b, vi)vegai = GVega(S, x, T, r, b, vi)minDiff = Abs(cm - ci)While Abs(cm - ci) >= epsilon And Abs(cm - ci) <= minDiff And vegai > 1E-200minDiff = Abs(cm - ci)vi = vi - (ci - cm) / vegaici = GBlackScholes(CallPutFlag, S, x, T, r, b, vi)vegai = GVega(S, x, T, r, b, vi)WendIf 1E-200 <= vegai Then GImpliedVolatilityNR = "near zero vega " Else GImpliedVolatilityNR = ""If Abs(cm - ci) > minDiff Then GImpliedVolatilityNR = GImpliedVolatilityNR & "Diverged "If Abs(cm - ci) < epsilon Then GImpliedVolatilityNR = vi Else GImpliedVolatilityNR = GImpliedVolatilityNR & "NA"End Function

QuoteOriginally posted by: CuchulainnI used the fixed point iteration for this very problem and it worked very well. Maybe for the 3rd edition? QuoteIn order to compute the implied volatility values in Table 1 (article Wilmott, Lewis, Duffy) we use the Black Scholes formula for calls and puts using the option values that we found using ADE. There are many methods to solve this nonlinear equation and in this case we used the fixed-point method in combination with Aitken?s delta-squared process to accelerate convergence. It is worth nothing that the fixed-point method converges for any initial guess because the corresponding iteration function is a contraction (Haaser (1991)). This is in contrast to the Newton Raphson and Bisection methods (for example), where it can sometimes be an issue in finding good starting values for these iterative methods. BTW the NR method can give problem when fitting yield for some short rate models. It is not robust, at least not always.I found the paper from which you quoted. It looks very interesting. But well above my head.After reading over it several times, it became clear to me that your quote from it contains the information needed for my context.I found some info on Wikipedia for fixed point iteration and Aitken's delta-squared acceleration.I have ordered the Haaser and Sulivan book in hopes of learning a bit.Of course none of the examples I have found are for Black Scholes. So to pull it off I suspect that I may need to find a recurrence relation or convergent series that represents Black Scholes?Pretty amazing work you guys do. This was just a bit of glue in that paper.

- Cuchulainn
**Posts:**59677**Joined:****Location:**Amsterdam-
**Contact:**

tthrift,I have some C++ code to calculate implied volatility for BS using fixed point that I can post. Let me know. In VBA it would look similar. Mahematically, you have to choose the parameter m such that the iteration function g(x) is a contraction i.e. abs(g'(x)) < 1So f(x) = 0 is same as x = g(x)whereg(x) = x - f(x)/mChoose m s.t. g is a contraction . AFAIR you bound vega to compute a suitable m. // Espen also uses the Bisection method for iv.

Last edited by Cuchulainn on November 25th, 2014, 11:00 pm, edited 1 time in total.

QuoteOriginally posted by: Cuchulainntthrift,I have some C++ code to calculate implied volatility for BS using fixed point that I can post. Let me know. In VBA it would look similar. Mahematically, you have to choose the parameter m such that the iteration function g(x) is a contraction i.e. abs(g'(x)) < 1So f(x) = 0 is same as x = g(x)whereg(x) = x - f(x)/mChoose m s.t. g is a contraction . AFAIR you bound vega to compute a suitable m. // Espen also uses the Bisection method for iv.Dr Duffy, Thankyou for the additional information and the offer.So Aitken's stuff is applied to g(x) to accelerate the already existing convergence?If you would, please post the c++ code.I should be able to translate it to VBA.I saw the bisection approach as well.

- Cuchulainn
**Posts:**59677**Joined:****Location:**Amsterdam-
**Contact:**

tthrift,What I have done is a self-contained C++11 to compute iv for calls and puts. The core algo is easy to port to VBA IMO:1. Linear fixed point iteration2. 1 + Aitken acceleration processBoth 1 and 2 converge for start guess v_0 and it is necessary to provide an estimate for that 'm' (that is just vega). m must be chosen to make it a contractionDid stress tests as well1. converges in 64 iterations2. converges in [3,5] iterationsCode on its way to you.

Last edited by Cuchulainn on November 27th, 2014, 11:00 pm, edited 1 time in total.

Peter Jaeckel has done a lot of work on efficient implied vol calculations. On his site you can find his reference implementationhttp://jaeckel.org/http://www.pjaeckel.webspace.virginmedi ... ational.7z

QuoteOriginally posted by: Cuchulainntthrift,What I have done is a self-contained C++11 to compute iv for calls and puts. The core algo is easy to port to VBA IMO:<snip>Code on its way to you.I got it running and will test it some more.Neat stuff!Thank You for taking the time to share it.

QuoteOriginally posted by: piterbargPeter Jaeckel has done a lot of work on efficient implied vol calculations. On his site you can find his reference implementationhttp://jaeckel.org/http://www.pjaeckel.webspace.virginmedi ... arg:Thanks for pointing out Peter Jaeckel's detailed implementation.I have it running as well and lightly tested.To make sure I knew how to call the code,I had to do some algebra to change the black pricing notation of Wilmott's book into the form Jaeckel is using.I thought I would work on the greeks a bit and tried to denormalize his normalized-vega.So far, I have not been clever enough to reproduce his normalized-vega.It looks like he is approximating it in different regions.// my denormalized vega in his form// where F = S*exp([r-d]*T), K is Wilmott's E, T is Wilmott's (T-t)EXPORT_EXTERN_C double vega(double F, double K, double sigma, double T, double r) { const double x = log(F / K); const double s = sigma*sqrt(T); // return (sqrt(F)*sqrt(K))*normalised_vega(x, s); // sqrt(F)*sqrt(K) is clearly the incorrect denormalization return (F*sqrt(T)*ONE_OVER_SQRT_TWO_PI*exp(-r*T - square(x / s + s / 2)))/100; //this is the closest I got to casting vega into PJ's form}Thanks for pointing out the excellent reference implementation he has shared and documented so well.Oops! I appreciate the grace and mercy that the senior members have been showing me in this thread.This thread is about Dr Haug's options formula book.In my enthusiasm I have overstepped my bounds.I realize that if I want to discuss IV implementations, I should start a separate thread in the beginner's forum.-Terry-

GZIP: On