|
From: Ibrahim E. <Ibr...@au...> - 2007-03-20 07:24:45
|
Hello I am trying to write a wrapper around quantlib to do various simple things. I wanted to be able to use black school formulae to calculate the call Primium at a given date given the various Required values, like underlying, strike, volatility and rate... Why I get zero at the end? =20 =20 #include "QuantlibWrapper.h" =20 // the only header you need to use QuantLib #define BOOST_LIB_DIAGNOSTIC # include <ql/quantlib.hpp> #undef BOOST_LIB_DIAGNOSTIC =20 #ifdef BOOST_MSVC /* Uncomment the following lines to unmask floating-point exceptions. Warning: unpredictable results can arise... =20 See http://www.wilmott.com/messageview.cfm?catid=3D10&threadid=3D9481 Is there anyone with a definitive word about this? */ // #include <float.h> // namespace { unsigned int u =3D _controlfp(_EM_INEXACT, _MCW_EM); } #endif =20 #include <boost/timer.hpp> #include <iostream> #include <iomanip> =20 using namespace QuantLib; =20 #if defined(QL_ENABLE_SESSIONS) namespace QuantLib { =20 Integer sessionId() { return 0; } =20 } #endif =20 =20 double QuantlibWrapper::BlackScholesCall(double underlying, double strike, double volatility, double riskFreeRate, double DaysToMature) { double ret =3D 0; =20 try { QL_IO_INIT =20 boost::timer timer; std::cout << std::endl; =20 // our options Option::Type type(Option::Call); Spread dividendYield =3D 0.00; =20 =20 Date todaysDate =3D Date::todaysDate(); Date settlementDate =3D todaysDate + (int) DaysToMature; Settings::instance().evaluationDate() =3D todaysDate; =20 Date maturity =3D todaysDate + (int) DaysToMature; DayCounter dayCounter =3D Actual365Fixed(); =20 =20 std::string method; =20 std::vector<Date> exerciseDates; exerciseDates.push_back(settlementDate); =20 boost::shared_ptr<Exercise> europeanExercise( new EuropeanExercise(maturity)); =20 Handle<Quote> underlyingH( boost::shared_ptr<Quote>(new SimpleQuote(underlying))); =20 // bootstrap the yield/dividend/vol curves Handle<YieldTermStructure> flatTermStructure( boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, riskFreeRate, dayCounter))); Handle<YieldTermStructure> flatDividendTS( boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, dividendYield, dayCounter))); Handle<BlackVolTermStructure> flatVolTS( boost::shared_ptr<BlackVolTermStructure>( new BlackConstantVol(settlementDate, volatility, dayCounter))); =20 boost::shared_ptr<StrikedTypePayoff> payoff( new PlainVanillaPayoff(type, strike)); =20 boost::shared_ptr<StochasticProcess> stochasticProcess( new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS)); =20 // options =20 VanillaOption europeanOption(stochasticProcess, payoff, europeanExercise); =20 // Analytic formulas: =20 // Black-Scholes for European method =3D "Black-Scholes"; =20 europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new AnalyticEuropeanEngine)); ret =3D europeanOption.NPV(); } catch (std::exception& e) { std::cout << e.what() << std::endl; return 1; } catch (...) { std::cout << "unknown error" << std::endl; return 1; } =20 return ret; } =20 =20 I get zero for any pricing I use..=20 Can you please help how to use Quantlib? Please send reply to : elf...@gm... Regards Ibrahim =20 This e-mail and any files transmitted with it are confidential and are = only for the use of the person to whom they are addressed. If you are = not the intended recipient, you are hereby notified that any use, = dissemination, forwarding, printing, copying or dealing in any way = whatsoever with this e-mail is strictly prohibited. If you have = received this e-mail in error, please reply to us immediately and delete = the document. It is the recipient's duty to virus-scan and otherwise = test the enclosed information before using the information or loading = attached files onto any computer system. Australian Investment Exchange = Ltd does not warrant that the information contained in this e-mail is = free from viruses, defects, errors, interception or interference. = Australian Investment Exchange Ltd, and each of its related companies = each reserve the right to monitor all e-mail communications through its = networks. Any views expressed in this message are those of the = individual sender, except where that sender specifically states them to = be the views of Australian Investment Exchange Ltd. Your private = information is only used and disclosed for the intention which you have = provided it for. This information is not disclosed or used unless your = consent has been provided or in the case that Australian Investment = Exchange Ltd is permitted to do so under the Privacy Act of 1988. |