Luca Billi | 5 Feb 21:26
Picon

Looping dependencies

I noticed that the current implementation of LazyObjects generates
infinite recursions
in the case the dependency hierarchy among Observer/Observable objects
contains loops.

A suggestion to break the infinite recursion is to replace the update()
method as follows:

 void LazyObject::update() {

      if (!frozen_&& calculated_){
        //
        // Set calculated_=false before calling notifyObservers()
        //
        calculated_ = false;

        notifyObservers();
      }

      calculated_ = false;
 }

Luca

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
(Continue reading)

Luigi Ballabio | 7 Feb 14:38
Picon

Re: Looping dependencies

Luca,
    thanks for the report.  Ferdinando applied your changes to the repository.

Luigi

On Sun, Feb 5, 2012 at 9:26 PM, Luca Billi <luca.billi <at> gmail.com> wrote:
> I noticed that the current implementation of LazyObjects generates
> infinite recursions
> in the case the dependency hierarchy among Observer/Observable objects
> contains loops.
>
> A suggestion to break the infinite recursion is to replace the update()
> method as follows:
>
>  void LazyObject::update() {
>
>      if (!frozen_&& calculated_){
>        //
>        // Set calculated_=false before calling notifyObservers()
>        //
>        calculated_ = false;
>
>        notifyObservers();
>      }
>
>      calculated_ = false;
>  }
>
>
> Luca
(Continue reading)

Luigi Ballabio | 7 Feb 14:59
Picon

Re: Is this design ok?

Hi Peter,
    apologies for the delay.

> 1. Why is CalibratedModel derived from Observer as "public" and not
> "public virtual" ?

It's probably an oversight.  Try changing it and running the test
suite; if it works, give me a shout and I'll correct it.

> 2. Why is update() and not generateArguments(); notifyObservers();
> called in CalibratedModel::setParams() ?

It might just be that whoever wrote the call didn't think that
update() could be extended.
On the other hand, it's been a while since I looked at that part of
the library, and I'm not sure that one wouldn't want the model to
update fully when parameters are set... Hmm. Again, you might try to
make the change and see what happens.

Another possibility is that you decouple the two updates entirely.
You might call update2 code from the model's update() method, and
manage update1() by using another observer. Something like:

class YourModel {
  private:
    class updateHelper : public Observer {
      public:
        updateHelper(YourModel* model) : model(model) {}
        void update() { model->update1(); }
    };
(Continue reading)

Re: Looping dependencies

Hi Luca


On Sun, Feb 5, 2012 at 9:26 PM, Luca Billi <luca.billi <at> gmail.com> wrote:
> I noticed that the current implementation of LazyObjects generates
> infinite recursions
> in the case the dependency hierarchy among Observer/Observable objects
> contains loops.
>
> A suggestion to break the infinite recursion is to replace the update()
> method as follows:
> [...]

good catch, even if on the 1.2.0 release branch it was already fixed as in the following

   inline void LazyObject::update() {
       // forwards notifications only the first time
       if (calculated_) {
           // set to false early, otherways non-lazy observers would be
           // served obsolete data because of calculated_ being still true
           calculated_ = false;
           // observers don't expect notifications from frozen objects
           if (!frozen_)
               notifyObservers();
       }
   }


I've added your "prevent infinite recursion" comment too

ciao -- Nando
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
QuantLib-dev mailing list
QuantLib-dev <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Peter Caspers | 7 Feb 22:22
Picon
Favicon

Re: Is this design ok?

Hi Luigi,

thank you for your answer. The test suite runs fine with both changes.

The order in which update1() and update2() are called is in fact 
crucial. The model is a markov functional one factor model. update1() 
precomputes arbitrage free smiles from a given volatility structure. 
update2() bootstraps a numeraire surface fitting these smiles. So 
update1() only depends on the market data input, while update2() in 
addition depends on the model parameters, i.e. the parameters describing 
the driving state process.

I would apreciate to have both changes in the code, if no one has second 
thoughts.

Thanks again,
Peter

Am 07.02.2012 14:59, schrieb Luigi Ballabio:
> Hi Peter,
>      apologies for the delay.
>
>> 1. Why is CalibratedModel derived from Observer as "public" and not
>> "public virtual" ?
> It's probably an oversight.  Try changing it and running the test
> suite; if it works, give me a shout and I'll correct it.
>
>> 2. Why is update() and not generateArguments(); notifyObservers();
>> called in CalibratedModel::setParams() ?
> It might just be that whoever wrote the call didn't think that
> update() could be extended.
> On the other hand, it's been a while since I looked at that part of
> the library, and I'm not sure that one wouldn't want the model to
> update fully when parameters are set... Hmm. Again, you might try to
> make the change and see what happens.
>
> Another possibility is that you decouple the two updates entirely.
> You might call update2 code from the model's update() method, and
> manage update1() by using another observer. Something like:
>
> class YourModel {
>    private:
>      class updateHelper : public Observer {
>        public:
>          updateHelper(YourModel* model) : model(model) {}
>          void update() { model->update1(); }
>      };
>      ...
>      updateHelper uh;
>    public:
>      YourModel(whatever) : uh(this) {
>          this->registerWith(a);  // triggers update2()
>          this->registerWith(b);  // triggers update2()...
>          uh->registerWith(b);   // ...and also update1()
>      }
> };
>
> The problem is, it's not guaranteed in what order update1() and
> update2() will be called, which might be a showstopper for you.
>
> In any case, let me know how it goes.
>
> Later,
>      Luigi
>
>
> On Sun, Jan 29, 2012 at 6:09 PM, Peter Caspers<pcaspers <at> vodafone.de>  wrote:
>> Hello Luigi,
>>
>> I want to add a new model to the lib. The model observes a yield term
>> structure and a volatility structure. Whenever one of them changes a
>> method update1() shall be called. Furthermore the model has a (piecewise
>> constant) parameter that can be calibrated to additional instruments.
>> When this parameter changes, another method update2() should be called.
>> In fact, update1() calls update2(). Both methods update1() and update2()
>> need some computation time, so in particular during calibration
>> update1() should _not_ be called. Finally, the model should be a
>> LazyObject, because multiple changes in market data (say a parallel
>> shift in the volatility surface) should trigger only one call of update1().
>>
>> I think I have a solution, but I want to learn a bit about the libs
>> design and I want to be sure to be in line with this design and not have
>> overseen something. So could you please have a look?
>>
>> My first attempt was the following: Let the model inherit from
>> TermstructureConsistentModel, CalibratedModel and LazyObject. However,
>> when calling registerWith(myYts's), this registration is ambiguous
>> because both LazyObject and CalibratedModel derive from Observer, but in
>> the case of CalibratedModel this is no virtual inheritance. So my first
>> question would be: Is there a special reason for that or could the
>> declaration also be CalibratedModel : public virtual Observer, ... ?
>> Given I would change that, I need to overwrite the update() method in my
>> model then basically calling LazyObject::update(). The
>> performCalculations() implementation in my model would call update1()
>> and update2().
>>
>> The next problem occurs in the setParams() method of CalibratedModel
>> which calls update() at the end, causing full recalculation (i.e. calls
>> of update1() and update2()) of the model, which I wanted to avoid. My
>> interpretation of the purpose of generateArguments() up to now was to
>> update the model w.r.t. changes in its parameters. So a call of
>> generateArguments() and notifyObservers() instead of update() in the
>> setParams() method would be enough (and produce the desired behaviour in
>> my case). The implementation of generateArguments() in my model would
>> then simply call update2(). In fact, a call of setParams() would
>> instantaneously trigger a call of update2(), which would not be
>> consistent with the lazy behaviour of the model w.r.t. market data
>> changes, but this is no serious problem I guess.
>>
>> Summarizing my questions:
>>
>> 1. Why is CalibratedModel derived from Observer as "public" and not
>> "public virtual" ?
>> 2. Why is update() and not generateArguments(); notifyObservers();
>> called in CalibratedModel::setParams() ?
>>
>> The solution I actually arrived at (requiring no adjustments in the lib)
>> is the following:
>>
>> - Use LazyObject::registerWith(myYts's), i.e. only let the Observer of
>> LazyObject observe the term structures and not the observers copy in
>> CalibratedModel.
>> - Do not implement an update() method in my model.
>> - Implement performCalculations() and generateArguments() just as
>> described above.
>>
>> Is this latter way correct ?
>>
>> Thanks a lot
>> Peter
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Try before you buy = See our experts in action!
>> The most comprehensive online learning library for Microsoft developers
>> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
>> Metro Style Apps, more. Free future releases when you subscribe now!
>> http://p.sf.net/sfu/learndevnow-dev2
>> _______________________________________________
>> QuantLib-dev mailing list
>> QuantLib-dev <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/quantlib-dev

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
cf16 | 8 Feb 01:51
Picon

test suite link error


hi all,
so at the beginning I was not able to build test suiteat all, but after
rebuild boost by running bootstrap libboost_unit_test_framework lib has been
created, but... now I get this linker error:

InitializeBuildStatus:
  Touching ".\build\vc100\Win32\Debug\testsuite.unsuccessfulbuild".
ClCompile:
  All outputs are up-to-date.
Link:
     Creating library bin\QuantLib-test-suite-vc100-mt-gd.lib and object
bin\QuantLib-test-suite-vc100-mt-gd.exp
hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
"public: __thiscall
QuantLib::SobolBrownianBridgeRsg::SobolBrownianBridgeRsg(unsigned
int,unsigned int,enum QuantLib::SobolBrownianGenerator::Ordering,unsigned
long,enum QuantLib::SobolRsg::DirectionIntegers)"
(??0SobolBrownianBridgeRsg <at> QuantLib@@QAE <at> IIW4Ordering <at> SobolBrownianGenerator <at> 1@KW4DirectionIntegers <at> SobolRsg <at> 1@@Z)
referenced in function "public: static void __cdecl
HybridHestonHullWhiteProcessTest::testZeroBondPricing(void)"
(?testZeroBondPricing <at> HybridHestonHullWhiteProcessTest@@SAXXZ)
hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
"public: unsigned int __thiscall
QuantLib::SobolBrownianBridgeRsg::dimension(void)const "
(?dimension <at> SobolBrownianBridgeRsg <at> QuantLib@@QBEIXZ) referenced in function
"public: __thiscall QuantLib::MultiPathGenerator<class
QuantLib::SobolBrownianBridgeRsg>::MultiPathGenerator<class
QuantLib::SobolBrownianBridgeRsg>(class boost::shared_ptr<class
QuantLib::StochasticProcess> const &,class QuantLib::TimeGrid const &,class
QuantLib::SobolBrownianBridgeRsg,bool)"
(??0?$MultiPathGenerator <at> VSobolBrownianBridgeRsg <at> QuantLib@@@QuantLib@@QAE <at> ABV?$shared_ptr <at> VStochasticProcess <at> QuantLib@@@boost@@ABVTimeGrid <at> 1@VSobolBrownianBridgeRsg <at> 1@_N <at> Z)
hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
"public: struct QuantLib::Sample<class std::vector<double,class
std::allocator<double> > > const & __thiscall
QuantLib::SobolBrownianBridgeRsg::nextSequence(void)const "
(?nextSequence <at> SobolBrownianBridgeRsg <at> QuantLib@@QBEABU?$Sample <at> V?$vector <at> NV?$allocator <at> N@std@@@std@@@2 <at> XZ)
referenced in function "private: struct QuantLib::Sample<class
QuantLib::MultiPath> const & __thiscall QuantLib::MultiPathGenerator<class
QuantLib::SobolBrownianBridgeRsg>::next(bool)const "
(?next@?$MultiPathGenerator <at> VSobolBrownianBridgeRsg <at> QuantLib@@@QuantLib@@ABEABU?$Sample <at> VMultiPath <at> QuantLib@@@2 <at> _N <at> Z)
hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
"public: struct QuantLib::Sample<class std::vector<double,class
std::allocator<double> > > const & __thiscall
QuantLib::SobolBrownianBridgeRsg::lastSequence(void)const "
(?lastSequence <at> SobolBrownianBridgeRsg <at> QuantLib@@QBEABU?$Sample <at> V?$vector <at> NV?$allocator <at> N@std@@@std@@@2 <at> XZ)
referenced in function "private: struct QuantLib::Sample<class
QuantLib::MultiPath> const & __thiscall QuantLib::MultiPathGenerator<class
QuantLib::SobolBrownianBridgeRsg>::next(bool)const "
(?next@?$MultiPathGenerator <at> VSobolBrownianBridgeRsg <at> QuantLib@@@QuantLib@@ABEABU?$Sample <at> VMultiPath <at> QuantLib@@@2 <at> _N <at> Z)
bin\QuantLib-test-suite-vc100-mt-gd.exe : fatal error LNK1120: 4 unresolved
externals

Build FAILED.

Time Elapsed 00:07:23.45
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

/////////////////

moreover, I'm building QuantLib_vc10.sln and every project is beeing created
with success, just this test suite becouse of Sobol. I have checked that
SobolBrownianBridgeRsg takes different parameters indeed in constructor, but
I think it'snot it as it was certainly investigated.
I use QuantLib on a regular basis - there have never been any problems that
some externals is unresolved, why this hybridhestonhullwhiteprocess.obj ?
please help.
--

-- 
View this message in context: http://old.nabble.com/test-suite-link-error-tp33282311p33282311.html
Sent from the quantlib-dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Luigi Ballabio | 8 Feb 13:14
Picon

Re: test suite link error

If you're using a checkout from Subversion, there's the chance that
the VC10 project is not updated.  Check if
<ql/math/randomnumbers/sobolbrownianbridgersg.cpp> is in the project,
and if not, add it.

Luigi

On Wed, Feb 8, 2012 at 1:51 AM, cf16 <cf16rocket <at> gmail.com> wrote:
>
> hi all,
> so at the beginning I was not able to build test suiteat all, but after
> rebuild boost by running bootstrap libboost_unit_test_framework lib has been
> created, but... now I get this linker error:
>
> InitializeBuildStatus:
>  Touching ".\build\vc100\Win32\Debug\testsuite.unsuccessfulbuild".
> ClCompile:
>  All outputs are up-to-date.
> Link:
>     Creating library bin\QuantLib-test-suite-vc100-mt-gd.lib and object
> bin\QuantLib-test-suite-vc100-mt-gd.exp
> hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
> "public: __thiscall
> QuantLib::SobolBrownianBridgeRsg::SobolBrownianBridgeRsg(unsigned
> int,unsigned int,enum QuantLib::SobolBrownianGenerator::Ordering,unsigned
> long,enum QuantLib::SobolRsg::DirectionIntegers)"
> (??0SobolBrownianBridgeRsg <at> QuantLib@@QAE <at> IIW4Ordering <at> SobolBrownianGenerator <at> 1@KW4DirectionIntegers <at> SobolRsg <at> 1@@Z)
> referenced in function "public: static void __cdecl
> HybridHestonHullWhiteProcessTest::testZeroBondPricing(void)"
> (?testZeroBondPricing <at> HybridHestonHullWhiteProcessTest@@SAXXZ)
> hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
> "public: unsigned int __thiscall
> QuantLib::SobolBrownianBridgeRsg::dimension(void)const "
> (?dimension <at> SobolBrownianBridgeRsg <at> QuantLib@@QBEIXZ) referenced in function
> "public: __thiscall QuantLib::MultiPathGenerator<class
> QuantLib::SobolBrownianBridgeRsg>::MultiPathGenerator<class
> QuantLib::SobolBrownianBridgeRsg>(class boost::shared_ptr<class
> QuantLib::StochasticProcess> const &,class QuantLib::TimeGrid const &,class
> QuantLib::SobolBrownianBridgeRsg,bool)"
> (??0?$MultiPathGenerator <at> VSobolBrownianBridgeRsg <at> QuantLib@@@QuantLib@@QAE <at> ABV?$shared_ptr <at> VStochasticProcess <at> QuantLib@@@boost@@ABVTimeGrid <at> 1@VSobolBrownianBridgeRsg <at> 1@_N <at> Z)
> hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
> "public: struct QuantLib::Sample<class std::vector<double,class
> std::allocator<double> > > const & __thiscall
> QuantLib::SobolBrownianBridgeRsg::nextSequence(void)const "
> (?nextSequence <at> SobolBrownianBridgeRsg <at> QuantLib@@QBEABU?$Sample <at> V?$vector <at> NV?$allocator <at> N@std@@@std@@@2 <at> XZ)
> referenced in function "private: struct QuantLib::Sample<class
> QuantLib::MultiPath> const & __thiscall QuantLib::MultiPathGenerator<class
> QuantLib::SobolBrownianBridgeRsg>::next(bool)const "
> (?next@?$MultiPathGenerator <at> VSobolBrownianBridgeRsg <at> QuantLib@@@QuantLib@@ABEABU?$Sample <at> VMultiPath <at> QuantLib@@@2 <at> _N <at> Z)
> hybridhestonhullwhiteprocess.obj : error LNK2019: unresolved external symbol
> "public: struct QuantLib::Sample<class std::vector<double,class
> std::allocator<double> > > const & __thiscall
> QuantLib::SobolBrownianBridgeRsg::lastSequence(void)const "
> (?lastSequence <at> SobolBrownianBridgeRsg <at> QuantLib@@QBEABU?$Sample <at> V?$vector <at> NV?$allocator <at> N@std@@@std@@@2 <at> XZ)
> referenced in function "private: struct QuantLib::Sample<class
> QuantLib::MultiPath> const & __thiscall QuantLib::MultiPathGenerator<class
> QuantLib::SobolBrownianBridgeRsg>::next(bool)const "
> (?next@?$MultiPathGenerator <at> VSobolBrownianBridgeRsg <at> QuantLib@@@QuantLib@@ABEABU?$Sample <at> VMultiPath <at> QuantLib@@@2 <at> _N <at> Z)
> bin\QuantLib-test-suite-vc100-mt-gd.exe : fatal error LNK1120: 4 unresolved
> externals
>
> Build FAILED.
>
> Time Elapsed 00:07:23.45
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
>
> /////////////////
>
> moreover, I'm building QuantLib_vc10.sln and every project is beeing created
> with success, just this test suite becouse of Sobol. I have checked that
> SobolBrownianBridgeRsg takes different parameters indeed in constructor, but
> I think it'snot it as it was certainly investigated.
> I use QuantLib on a regular basis - there have never been any problems that
> some externals is unresolved, why this hybridhestonhullwhiteprocess.obj ?
> please help.
>

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
cf16 | 8 Feb 22:27
Picon

Re: test suite link error


yes, these files are present in ql/math/randomnumbers/ 
--

-- 
View this message in context: http://old.nabble.com/test-suite-link-error-tp33282311p33289385.html
Sent from the quantlib-dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Luigi Ballabio | 8 Feb 22:41
Picon

Re: test suite link error

On Wed, Feb 8, 2012 at 10:27 PM, cf16 <cf16rocket <at> gmail.com> wrote:
> yes, these files are present in ql/math/randomnumbers/

I mean in the VC project.  Do you see them from Visual Studio when you
open the solution? They should be under the "QuantLib" project under
math/randomnumbers.

Luigi

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
cf16 | 9 Feb 00:03
Picon

Re: test suite link error


yes, it was it. I have added "existing item" to QuantLib project in
QuantLib_vc10 and it is OK now.
thank you very, very much.

Piotr
--

-- 
View this message in context: http://old.nabble.com/test-suite-link-error-tp33282311p33289908.html
Sent from the quantlib-dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/

Gmane