Posted by
andrea loddo-2 on
May 15, 2007; 5:04pm
URL: http://quantlib.414.s1.nabble.com/LazyObject-exception-tp867.html
Hi,
I am experiencing some problems in pricing a vanilla option.
When I run it an exception of access violation reading location is
thrown. I also run it in debug mode and there are some problems in the
objects Observer and Observable . The exception is thrown when
option.setPricingEngine(boost::shared_ptr<PricingEngine>(new AnalyticEuropeanEngine))
is executed and more precisely when the virtual member function implemented in LazyObject
inline void LazyObject::update() {
calculated_ = false;
// observers don't expect notifications from frozen objects
if (!frozen_)
notifyObservers();
}
is
called. The problem arises when notifyObservers() is executed, as both
Observer and Observable don't seem to have been initialized properly.
I will appreciate any suggestions.
I should better post the code I am using :)
#define BOOST_LIB_DIAGNOSTIC
#include <ql/quantlib.hpp>
#undef BOOST_LIB_DIAGNOSTIC
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
}
#endif
int main(int, char* [])
{
try {
QL_IO_INIT
std::cout << "Using " << QL_VERSION << std::endl << std::endl;
// our option
Option::Type type(Option::Call);
Real underlying = 36;
Real strike = 40;
Spread dividendYield = 0.00;
Rate riskFreeRate = 0.06;
Volatility volatility =
0.20;
Date maturity(17, May, 1999);
Date settlementDate(17, May, 1998);
DayCounter dayCounter = Actual365Fixed();
Handle<Quote> underlyingH( boost::shared_ptr<Quote>(new SimpleQuote(underlying)));
boost::shared_ptr<Exercise> europeanExercise(new EuropeanExercise(maturity));
// 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<BlackScholesMertonProcess> stochasticProcess(new
BlackScholesMertonProcess(underlyingH, flatDividendTS,
flatTermStructure,flatVolTS));
VanillaOption option(stochasticProcess, payoff, europeanExercise);
//pricing
option.setPricingEngine(boost::shared_ptr<PricingEngine>(new AnalyticEuropeanEngine));
//PRICE
double ret;
ret = option.NPV
();
return 0 ;
}
catch (std::exception& e) {
std::cout << e.what() << std::endl;
return 1;
}
catch (...) {
std::cout << "unknown error" << std::endl;
return 1;
}
}
Thanks,
Andrea.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users