# st: solving for implied volatility

 From Christopher F Baum To statalist@hsphsun2.harvard.edu Subject st: solving for implied volatility Date Wed, 22 Sep 2004 07:57:22 -0400

Dan said
My problem is how to get implied volatilities out of option prices. I
have the options prices and I want to get implied volatilities out of
them. My variable 'x' contains option prices, variable 'y' contains only
missings. How do I get stata filling 'y' with values (volatility)
solving my option pricing formula (Black-Scholes) ?

Although (given a function that returns the Normal cdf) there is a closed form solution for C (the B-S Call price) in terms of its five arguments (one of which is S, the standard deviation of the underlying stock price), the solution of that function for S as a function of C and the other arguments must be solved by iteration. The foot of the page
http://finance.bi.no/~bernt/gcc_prog/recipes/recipes/node7.html
provides C code for two ways of solving for implied volatility: a bisection method and Newton-Raphson, taking advantage of the fact that the B-S derivative w.r.t. S (what non-classically-trained options traders call "vega") is also analytical. Both assume that you have a function to calculate the B-S C, which is given farther up on the page.

For a Stata data set containing option call prices (and the other four necessary arguments) you would have to solve for S for each observation in turn. This cannot be done with an egen function, but would require a program that took five variables (C, X, K, T-t, r) and looped over the observations, solving by iteration for the S and generating S as a new variable. My guess is that it would be pretty slow to do this in Stata code, so this would be a great application for a Stata plugin (http://www.stata.com/plugins/), which could just pass the five vectors to a C routine -- which is already written in that web page!--and return the S variable).

Kit Baum, Boston College Economics baum@bc.edu
http://fmwww.bc.edu/ec/baum.php

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/