Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

After using RQuantLib and RCaller from Java I am desiring a bit more speed on my implied volatility calculations (for anyone who has used this knows it is quite slow).

I need to price a large number of options and in general would like to have a localized implied vol calculation that I have full control of.

Now, using some code from Princeton I have the normal distribution, and a basic implementation of Black Scholes.

When I price using theoretical I get:

(given):

double v = bs.optionPrice("C",112.73, 40, .005, .79, 1.2356,0);

and

public double optionPrice(String cP, double S, double X, double r, double sigma, double T, double q) {
    double d1 = (Math.log(S / X) + (r + sigma * sigma / 2) * T) / (sigma * Math.sqrt(T));
    double d2 = d1 - sigma * Math.sqrt(T);
    callPut = cP;

    if (cP.equals("C")) {
        return S * Gaussian.Phi(d1) - X * Math.exp(-r * T) * Gaussian.Phi(d2);
    } else {
        return X * Math.exp(-r * T) * Gaussian.Phi(-1 * d2) - S * Gaussian.Phi(-1 * d1);
    }

}

where Gaussian is defined here.

Now, the theoretical value I am getting is bit higher than I was getting from R (princeton: 76.15219293244613, R:73.1500005383227). So this is one point.


Secondly:

I am implementing a very crude implied volatility solver that I will improve once I have something that gets close to the right answer. Due to the fact that right now I am getting something off is why i truly am asking this question.

My method is as follows:

            public double impVol(String cP, double S, double K, double r, double sigma, double T, double optionValue, double q) {

                double v;
                callPut = cP;
                double diff = 1;
                double lastDiff;
                double dSigma=1.0;
                int i=0;

                while (diff > .0000005) { //1% diff
                    lastDiff = diff;

                    v = optionPrice(cP, S,  K,  r,  sigma,  T,0.0);

                    diff = (optionValue-v)/v;diff=Math.pow(diff, 2);

                    if(diff>lastDiff){
                        //move=-1;
                        dSigma=dSigma*1.1;
                    }else{
                        //move=1;
                        dSigma=dSigma*.90;
                    }

                    sigma = sigma*dSigma;
                    i++;
                    System.out.println(i + "," + v + "," + sigma);

                }
                return 0.0; //Dummy for now
            }

The output I get

1,76.15219293244613,0.7110000000000001 2,75.16852161673661,0.5759100000000001 3,73.87343738224003,0.4198383900000002 4,73.11210149228228,0.27545596767900016 The bid/ask I have for the option is the following: 71.3/75 The last solution for the implied volatility is relatively close in price (not close enough to be used, but good enough for my crude solver). The major issue I have is that the implied volatility from R is approx .43. Using an external website I find a very similar result to R. Even with the crudeness of my optimization eyeballing where the implied vol should be given my bid ask, it is obvious that the IV would come in low.

Any input on something that may be glaringly obvious to someone who has done this before?

Thanks

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.