Hell
I am in Canada. I just finished a project for Equity option analysis and management system.
I send you my algorithm to you for free.
Good luck!
Daxin
Here is a C++ algorithm to calculate implied volatility by bisection method.
To realize the algorithm, first, you need a pricing model for options such as European BS, Binomial tree, trinomial tree models. In my algorithm, I use American style trinomial tree pricing model( I did not give you this algorithm). The easest way is using European BS model. Suppose that you already have a European BS pricing model. Now you can use my following algorithm to calculate implied volatility(you can change the function names if you like):
double impliedVolContDivTrinomial (double pricing_value, double price, double strike, double rate, double div, double T, int N, int optionType) {
//Input
//pricing_value: usually represent the market value for the option
//price: current stock price
// strike: strike price
//rate: interest rate
//div: continuous dividend rate. if it is zero, you can not consider this parameter in you algorithm
// T: the time from today to expire date in year
//N: step for time, you do not need this parameter if you use BS pricing model
// optionType: if it is 0, that means call option, if it is 1, that means put option. //output: implied volatility
double desired_accuracy=0.0001; // error limit for calculating implied volatility double low_vol=0.001; // lower volatility bound, can be adjusted double high_vol=1.0; //high volatility bound, can be adjusted
double low_pricing_value =contDivTrinomialTree (price, strike, low_vol, rate, div, T, N, optionType); double high_pricing_value =contDivTrinomialTree (price, strike, high_vol, rate, div, T, N, optionType); double new_vol=low_vol + (pricing_value-low_pricing_value)*(high_vol-low_vol)/(high_pricing_value -low_pricing_value); double new_pricing_value=contDivTrinomialTree (price, strike, new_vol, rate, div, T, N, optionType); while((pricing_value-new_pricing_value>desired_accuracy)||(pricing_value-new_pricing_value<-desired_accuracy)) { if(new_pricing_value<pricing_value) { low_vol=new_vol; low_pricing_value =contDivTrinomialTree (price, strike, low_vol, rate, div, T, N, optionType); //update } else { high_vol=new_vol; high_pricing_value =contDivTrinomialTree (price, strike, high_vol, rate, div, T, N, optionType); }
new_vol=low_vol + (pricing_value-low_pricing_value)*(high_vol-low_vol)/(high_pricing_value -low_pricing_value); new_pricing_value = contDivTrinomialTree (price, strike, new_vol, rate, div, T, N, optionType); }
return new_vol;
}