Sunday, July 30, 2017

programming - What is an efficient method to find implied volatility?


I have a code that finds the implied volatility using the Newton-Raphson method.


I set the number of trial to 1000 but sometimes it fails to converge and doesn't find the result.


Is there a better method to find the result? Are there any technical conditions in which this numerical method is expected to fail to converge to the solution?


Here is the C# code:



    public double findIV(double S, double K, double r, double time, string type, double optionPrice)
{
int trial= 1000;
double ACCURACY = 1.0e-5;
double t_sqrt = Math.Sqrt(time);

double sigma = (optionPrice / S) / (0.398 * t_sqrt); // find initial value
for (int i = 0; i < trial; i++)
{
Option myCurrentOpt = new Option(type, S, K, time, r, 0, sigma); // create an Option object

double price = myCurrentOpt.BlackScholes();
double diff = optionPrice - price;
if (Math.Abs(diff) < ACCURACY)
return sigma;
double d1 = (Math.Log(S / K) + r * time) / (sigma * t_sqrt) + 0.5 * sigma * t_sqrt;
double vega = S * t_sqrt * ND(d1);
sigma = sigma + diff / vega;
}
throw new Exception("Failed to converge.");
}


public double ND(double X)
{
return (1.0 / Math.Sqrt(2.0 * Math.PI)) * Math.Exp(-0.5 * X * X);
}

Answer



Peter Jaeckel wrote a paper just on how to solve this problem:


By Implication (July 2006; Wilmott, pages 60-66, November 2006). Probably the most complicated trivial issue in financial mathematics: how to compute Black's implied volatility robustly, simply, efficiently, and fast


downloadable from jaeckel.org


In my experience the most important thing is to make sure that you are working with an option out of the money. If the option is in the money use put-call parity to transform to the other case.



No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...