LazyObject exception

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

LazyObject exception

andrea loddo-2
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
Reply | Threaded
Open this post in threaded view
|

Re: LazyObject exception

Luigi Ballabio
On Tue, 2007-05-15 at 17:04 +0100, andrea loddo wrote:
> I am experiencing some problems in pricing a vanilla option. When I
> run it an exception of access violation reading location is thrown.

Andrea,
        what version of QuantLib are you using, and with what compiler?

Thanks,
        Luigi


----------------------------------------

It is always the best policy to tell the truth, unless, of course,
you are an exceptionally good liar.
-- Jerome K. Jerome



-------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: LazyObject exception

andrea loddo-2
Hi Luigi,

thanks for your mail.

I am using  QuantLib-0.4.0  and I compiled them with vc8.

Andrea

On 5/15/07, Luigi Ballabio <[hidden email]> wrote:
On Tue, 2007-05-15 at 17:04 +0100, andrea loddo wrote:
> I am experiencing some problems in pricing a vanilla option. When I
> run it an exception of access violation reading location is thrown.

Andrea,
        what version of QuantLib are you using, and with what compiler?

Thanks,
        Luigi


----------------------------------------

It is always the best policy to tell the truth, unless, of course,
you are an exceptionally good liar.
-- Jerome K. Jerome




-------------------------------------------------------------------------
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