evaluationDate problem

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

evaluationDate problem

Stefano Portolan
Hello,

I have a question related to the usage of QuantLib with respect to the library that I am writing.

I am writing a specific library for quantitative development purposes and I am using quite heavily QuantLib features (no reason to re-write something myself if Quantlib already does these things very well!)

My problem is related to the settings of the static variable Quantlib::Settings::evaluationDate_ .
As I learnt from the QuantLib website, I need to set this variable which is then used by every QuantLib class, so that if I instanciate a rateHelper, for instance, specifiying a maturity, then the scheduling is calculated (at least in the standard situation) from the evaluationDate to the maturity that I set in the rateHelper constructor.

Therefore (without my library):
I write my main (where I include quantLib)
I use the method
QuantLib::Date ValuationDate(30, QuantLib::October, 2014);
QuantLib::Settings::instance().evaluationDate() = valuationDate;

And then the QuantLib evaluationDate_ is set to the variable valuationDate that I choose.
I can retrieve the dates with the 2 methods RateHelper::earliestDate() and RateHelper::latestDate()  (right?)
So far so good.

If now I try to do the same thing BUT the rate helpers are packaged inside my own library (which has QuantLib included) something goes wrong and my evaluation date for my rateHelpers is always today date (the default date)

I try to write a method INSIDE my library that I call from my main(), where the two lines above are executed.
I thought that, in doing so, I would change the evaluationDate “of the library” and not only that of the main() …
… but it does not work and it seems there is something I am missing.

I read once that when working with precompile libraries and with “libraries to be compiled” there are kind of more than 1 environment and static variables can be different for the precompiled library and for the one I am writing.

Could somebody help me?
Could somebody explain “straight” (in plain words) this issue and/or give me some link where I can find something?

Thank you very much for your help.
Cheers.
Stefano
Reply | Threaded
Open this post in threaded view
|

Re: evaluationDate problem (MAJOR CHANGED and solved)

Stefano Portolan
Hello everybody,

After one day long in the fight I understood that my problem WAS NOT what I thought and wrote.
Excuse for this.

Besides, understanding my problem I found out the answer and I would like to put it here, maybe it will be useful for the other users.
I will probably use inexact informatics wording. Anyone who wants to put forward good knowledge, please take a sit.

My problem was related to the singleton (static … ok, almost) nature of the class where valuationDate_ resides.
When I link my DLL library to my main(), I have 2 environments of static variables : one for the DLL and the other for the main().
When I write inside the DLL, (method Session::valuationDateDLL(valuationDate) )
QuantLib::Settings::instance().evaluationDate() = valuationDate;

I am setting the valuationDate_ of the DLL.
So far so good,
but for some reasons which still are a little bit out of my knowledge, everything you write in the .hpp and not in the .cpp (as template methods) is linked/compiled/attached to the main() and sees the main() environment!

I solved my problem in setting TWICE my evaluation date:
(1) once in the main():
QuantLib::Date valuationDate(30, QuantLib::October, 2014);
QuantLib::Settings::instance().evaluationDate() = valuationDate;

(2) And once in the DLL:
Session::setValuationDateDLL(valuationDate) ;

Like this when I call QuantLib methods in the .cpp’s of my DLL I see (2), when I call QuantLib methods inside my template methods which is in the .hpp I see (1).
Now that the two instances (if I can call them like this) are consistent and my simulation is consistent as well.

Any sensible explanation clearer than mine from some wiser QuantLib users or informatics guru is more than welcome.

Cheers.
Stefano