Hi,
I've been struggling to recreate an old functionality in the new version 0.9.7. In an old post from 2002, an American implied volatility could be solved with the maturity argument in floating-point years. All recent examples I've seen use a specific evaluation date and maturity date with no concept of fractional days. This functionality is valuable for near-maturity options when time-of-day matters. I don't need any dividends, so I'm just using the BlackProcess right now. Any help would be appreciated, thanks in advance. Below is a copy of the old post (See maturity=.25 for 3 months): 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; } } ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |