Login  Register

Re: implied volatility of american options

Posted by Ferdinando M. Ametrano-2 on Feb 28, 2002; 9:51am
URL: http://quantlib.414.s1.nabble.com/implied-volatility-of-american-options-tp1872p1873.html

At 02:43 PM 2/26/02 -0600, Vadim Ogranovich wrote:
>Before I go and read the source code I wonder
>if someone can save me time and tell how easy/difficult it is with QuantLib
>to compute implied volatility of an American option on a divident paying
>stock (either cash or stock).
Below I give you an example with continuous dividends. The class
FdDividendAmericanOption handle discrete dividends

hope this helps

ciao -- Nando

==============================

#include <ql/quantlib.hpp>

using namespace QuantLib;

using QuantLib::Pricers::FdAmericanOption;


int main(int argc, char* argv[])
{
     try {
         // our option
         double underlying = 102;
         double strike = 100;      // at the money
         Spread dividendYield = 0.03; // no dividends
         Rate riskFreeRate = 0.05; // 5%
         Time maturity = 0.25;      // 3 months
         double volatility = 0.20; // 20%
         std::cout << "Time to maturity = "        << maturity
                   << std::endl;
         std::cout << "Underlying price = "        << underlying
                   << std::endl;
         std::cout << "Strike = "                  << strike
                   << std::endl;
         std::cout << "Risk-free interest rate = " << riskFreeRate
                   << std::endl;
         std::cout << "Volatility = "              << volatility
                   << std::endl;
         std::cout << std::endl;


         Size timeSteps=100, assetSteps = 20;
         FdAmericanOption myAmericanOption(Option::Call, underlying, strike,
             dividendYield, riskFreeRate, maturity, volatility, timeSteps,
assetSteps);
         double value = myAmericanOption.value();
         std::cout
             <<  "vol " << DoubleFormatter::toString(volatility, 6)
             <<  " value " << DoubleFormatter::toString(value, 6)
             << std::endl;

         double impliedVol = myAmericanOption.impliedVolatility(value*1.1);
         std::cout
             <<  "a value of " << DoubleFormatter::toString(value*1.1, 6)
             <<  " implies a vol " << DoubleFormatter::toString(impliedVol, 6)
             << std::endl;


         return 0;
     } catch (std::exception& e) {
         std::cout << e.what() << std::endl;
         return 1;
     } catch (...) {
         std::cout << "unknown error" << std::endl;
         return 1;
     }
}