Re: FW: LazyObject exception

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

Re: FW: LazyObject exception

frederic.degraeve (Bugzilla)
Hello Andrew,
 
I've tried your code on a 0.4.0-debug with vc8 and no problem has happened. It seems curious. Check your compile. My QuantLib was a one without any modifications. I've used the Swap's vcproj. Else, this problem is typically a kind of bad registered observers.
 
I've also noticed then that your evaluationDate has not been set.
 
Regards
 
Frédéric Degraeve
 

 

 


From: [hidden email] [mailto:[hidden email]] On Behalf Of andrea loddo
Sent: mardi 15 mai 2007 18:04
To: [hidden email]
Subject: [Quantlib-users] LazyObject exception

 

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.
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://sourceforge.net/powerbar/db2/" target="_blank">http://sourceforge.net/powerbar/db2/



-------------------------------------------------------------------------
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: FW: LazyObject exception

andrea loddo-2
Hello Frédéric,

thanks for your mail.

So what you suggest me is to recompile the library, I guess. Is there any particular suggestion in order to do that in the correct way?It seemed to me to be pretty straightforward, but probably there might be something which I did not take into account.

Andrea.

On 5/15/07, Frédéric Degraeve <[hidden email]> wrote:
Hello Andrew,
 
I've tried your code on a 0.4.0-debug with vc8 and no problem has happened. It seems curious. Check your compile. My QuantLib was a one without any modifications. I've used the Swap's vcproj. Else, this problem is typically a kind of bad registered observers.
 
I've also noticed then that your evaluationDate has not been set.
 
Regards
 
Frédéric Degraeve
 

 

 


From: [hidden email] [mailto:[hidden email]] On Behalf Of andrea loddo
Sent: mardi 15 mai 2007 18:04
To: [hidden email]
Subject: [Quantlib-users] LazyObject exception

 

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.
<a href="http://sourceforge.net/powerbar/db2/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://sourceforge.net/powerbar/db2/



-------------------------------------------------------------------------
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.
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://sourceforge.net/powerbar/db2/" target="_blank">http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/quantlib-users" target="_blank"> https://lists.sourceforge.net/lists/listinfo/quantlib-users



-------------------------------------------------------------------------
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: FW: LazyObject exception

Luigi Ballabio

Hi Andrea,
        I haven't been able to try and reproduce the error yet (I've a Mac at
home.)

In the meantime:

On May 15, 2007, at 8:55 PM, andrea loddo wrote:
> So what you suggest me is to recompile the library, I guess. Is there
> any particular suggestion in order to do that in the correct way?It
> seemed to me to be pretty straightforward, but probably there might be
> something which I did not take into account.

Straightforward indeed. Open the QuantLib_vc8.sln solution, select
"Release", "Debug" or whatever configuration you're interested in, and
choose "Rebuild solution." It will recompile everything.

Later,
        Luigi


-------------------------------------------------------------------------
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: FW: LazyObject exception

andrea loddo-2
Hi Luigi, Frédéric,

thanks very much for your suggestion!I recompiled the lib and now it's perfect. I just did the typical newbie mistake, and definitely I  am. I did not pay attention to the warnings the compiler was reporting. One was very bad. Library conflict. So I recompiled everything with the right options and that's it. perfect.

Thanks again.

Andrea

 

On 5/15/07, Luigi Ballabio <[hidden email]> wrote:

Hi Andrea,
        I haven't been able to try and reproduce the error yet (I've a Mac at
home.)

In the meantime:

On May 15, 2007, at 8:55 PM, andrea loddo wrote:
> So what you suggest me is to recompile the library, I guess. Is there
> any particular suggestion in order to do that in the correct way?It
> seemed to me to be pretty straightforward, but probably there might be
> something which I did not take into account.

Straightforward indeed. Open the QuantLib_vc8.sln solution, select
"Release", "Debug" or whatever configuration you're interested in, and
choose "Rebuild solution." It will recompile everything.

Later,
        Luigi



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