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? #include "QuantlibWrapper.h" // the only header you need to use QuantLib #define BOOST_LIB_DIAGNOSTIC # include <ql/quantlib.hpp> #undef BOOST_LIB_DIAGNOSTIC #ifdef BOOST_MSVC /* Uncomment the following lines to unmask floating-point exceptions. Warning: unpredictable results can arise... See
http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481 Is there anyone with a definitive word about this? */ // #include <float.h> // namespace { unsigned int u = _controlfp(_EM_INEXACT,
_MCW_EM); } #endif #include <boost/timer.hpp> #include <iostream> #include <iomanip> using namespace QuantLib; #if defined(QL_ENABLE_SESSIONS) namespace QuantLib { Integer sessionId() { return 0; } } #endif double QuantlibWrapper::BlackScholesCall(double underlying,
double strike, double volatility, double riskFreeRate, double DaysToMature) { double ret = 0; try { QL_IO_INIT boost::timer timer; std::cout << std::endl; // our options Option::Type type(Option::Call); Spread dividendYield = 0.00; Date todaysDate = Date::todaysDate(); Date settlementDate = todaysDate + (int)
DaysToMature; Settings::instance().evaluationDate() =
todaysDate; Date maturity = todaysDate + (int)
DaysToMature; DayCounter dayCounter = Actual365Fixed(); std::string method; std::vector<Date> exerciseDates; exerciseDates.push_back(settlementDate); boost::shared_ptr<Exercise> europeanExercise( new EuropeanExercise(maturity)); Handle<Quote> underlyingH( boost::shared_ptr<Quote>(new
SimpleQuote(underlying))); // 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))); boost::shared_ptr<StrikedTypePayoff>
payoff( new PlainVanillaPayoff(type,
strike)); boost::shared_ptr<StochasticProcess>
stochasticProcess( new
BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS)); // options VanillaOption
europeanOption(stochasticProcess, payoff, europeanExercise); // Analytic formulas: // Black-Scholes for European method = "Black-Scholes";
europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new AnalyticEuropeanEngine)); ret = europeanOption.NPV(); } catch (std::exception& e) { std::cout << e.what() << std::endl; return 1; } catch (...) { std::cout << "unknown error"
<< std::endl; return 1; } return ret; } I get zero
for any pricing I use.. Can you
please help how to use Quantlib? Please send
reply to : [hidden email] Regards Ibrahim
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. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
On Tue, 2007-03-20 at 18:24 +1100, Ibrahim ElFayoumi wrote:
> 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? > > Date settlementDate = todaysDate + (int) DaysToMature; > > Date maturity = todaysDate + (int) DaysToMature; The settlement date is the date to which the option value is discounted to get its NPV---depending on where you are based, it might be today's date or a couple of days from today. Setting it to be the same as the maturity is probably causing the option to be seen as expired. Luigi ---------------------------------------- All parts should go together without forcing. You must remember that the parts you are reassembling were disassembled by you. Therefore, if you can't get them together again, there must be a reason. By all means, do not use a hammer. -- IBM maintenance manual, 1925 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |