Implied Volatility Review

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Implied Volatility Review

Sumit Gupta-5
I tried to write a simple program to calculate IV for both - American and European options. I am simply recalculating the theoretical price and comparing it with the required price of the user. It is more like a binary search algorithm where I divide the difference between volatility range by two and apply it, until I find the matching price. I checked with a couple of examples and got my answer reasonably close (3 decimals) to the values from www.ASX.com.au

Please review it and provide me with your valuable insight.

Regards,
Sumit Gupta

          /*************************************************************************
         * Calculating Implied Volatility for American Options CRR using
         * multiple evaluations. The process will evaluate the IV by setting a range of
         * minimum and maximum volatilty of 0.0000001% and 400% respectivally.
         * The process divide the range by 2 everytime it calculates new theoretical
         * price from the extremes of the range, and then selects the new range based
         * value of new theoretical price. i.e. if new Theoretical price is greater
         * than required price then we move down to lower range else vice versa.
         *
         * Rest all information is given.
         *
         *************************************************************************/
        public double CalculateImpliedVolatility(double newPrice, double minVol, double maxVol, Calendar calendar, Date todaysDate, Date settlementDate, Date maturity, Option.Type type, double underlying, double strike, double dividendYield, double riskFreeRate, double volatility, DayCounter dayCounter, int timeSteps, Exercise ExOption)
        {
            if (!(volatility <= maxVol && volatility >= minVol))
            {
                throw new ArgumentException("Value of Volatility is out of bound of minimum and maximum given values:");
            }

            List<Date> exerciseDates = new List<Date>(); ;
            for (int i = 1; i <= 4; i++)
                exerciseDates.Add(settlementDate + new Period(3 * i, TimeUnit.Months));

            Handle<Quote> underlyingH = new Handle<Quote>(new SimpleQuote(underlying));

            // bootstrap the yield/dividend/vol curves
            var flatTermStructure = new Handle<YieldTermStructure>(new FlatForward(todaysDate, riskFreeRate, dayCounter));
            var flatDividendTS = new Handle<YieldTermStructure>(new FlatForward(todaysDate, dividendYield, dayCounter));
            var flatVolTS = new Handle<BlackVolTermStructure>(new BlackConstantVol(todaysDate, calendar, volatility, dayCounter));
            StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);
            var bsmProcess = new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS);
            VanillaOption americanOption = new VanillaOption(payoff, ExOption);
            VanillaOption europeanOption = new VanillaOption(payoff, ExOption);
            double NPVal;

            switch (ExOption.type())
            {
                case Exercise.Type.American:
                    americanOption.setPricingEngine(new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, timeSteps));
                    NPVal = americanOption.NPV();
                    break;
                case Exercise.Type.European:

                    europeanOption.setPricingEngine(new AnalyticEuropeanEngine(bsmProcess));
                    NPVal = europeanOption.NPV();
                    break;
                default:
                    throw new ArgumentException("unknown exercise type");
            }


            double newVol = 0.00;

            double loopCount = 0;

            while (Math.Round(NPVal,4) != Math.Round(newPrice, 4))
            {

                if (NPVal > newPrice)
                {
                    maxVol = volatility;
                }
                else // if(NPV < newPrice)
                {
                    minVol = volatility;
                }

                volatility = (maxVol + minVol) / 2;
                flatVolTS = new Handle<BlackVolTermStructure>(new BlackConstantVol(todaysDate, calendar, volatility, dayCounter));
                bsmProcess = new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS);

                switch (ExOption.type())
                {
                    case Exercise.Type.American:
                        americanOption.setPricingEngine(new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, timeSteps));
                        NPVal = americanOption.NPV();
                        break;
                    case Exercise.Type.European:
                        europeanOption.setPricingEngine(new AnalyticEuropeanEngine(bsmProcess));
                        NPVal = europeanOption.NPV();
                        break;
                }
            }
            double IV = volatility;
            return IV;
        }

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Implied Volatility Review

Luigi Ballabio
On Tue, 2009-04-07 at 13:30 +1000, Sumit Gupta wrote:
> I tried to write a simple program to calculate IV for both - American
> and European options. I am simply recalculating the theoretical price
> and comparing it with the required price of the user. It is more like
> a binary search algorithm where I divide the difference between
> volatility range by two and apply it, until I find the matching price.
> I checked with a couple of examples and got my answer reasonably close
> (3 decimals) to the values from www.ASX.com.au
>
> Please review it and provide me with your valuable insight.

Looks ok. How different were the results for European options if you
called

europeanOption.impliedVolatility(newPrice, bsmProcess);

instead of running the loop? Namely, how different were the implied
volatilities and how different were the prices you obtained if you fed
the implied volatilities back into the process?

Luigi


--

Can't act. Slightly bald. Also dances.
-- RKO executive, reacting to Fred Astaire's screen test.
Cerf/Navasky, "The Experts Speak"



------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users