Re: Persistancy example
Posted by Andre Louw-2 on Apr 10, 2002; 3:06am
URL: http://quantlib.414.s1.nabble.com/Re-Persistancy-example-tp1971.html
Sorry my reply to Luigi's was mistakely posted directly to him. Here it is
again.
Luigi,
Let me go at this using an example.
Say you want a piece of code used to price any swap instrument. The calendar
to use being passed in as a parameter.
One way of doing it would be:
double priceSwap(Calendar aCal)
{
Code goes here to price...
}
int main(argc, argv[])
{
if (!strcmp(argv[1], "JHB"))
std::cout << priceSwap(Johannesburg());
else if (!strcmp(argv[1], "HLK"))
std::cout << priceSwap(Helsinki());
etc...
}
Unfortunately each time a new calendar is added you would need to change the
code.
I realize that Calendar is only one example, but similarily it could apply
to an Index, and probably a few other data-dependant objects as well. In my
mind by writing the Calendar data to some persistant store and reading it
when needed you could have one generic Calendar class that instantiates
itself from this as needed? This would the reduce the above to:
int main(argc, argv[])
{
std::cout << priceSwap(Calendar(argv[1])); // where the Calendar
constructor would build itself from the data written away previously.
}
I realize this is not a QuantLib issue, but was wondering how you guys
handle it? Remember also that I come from an Objective-C background, maybe
C++ offers a different, as yet undiscovered, way of doing something like
this?
Thanx
Andre
-------------------------------------------------------------------------
This e-mail is intended only for the use of the individual or entity named
above and may contain information that is confidential and privileged,
proprietary to the company and protected by law. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of this e-mail is strictly prohibited. Opinions, conclusions and
other information in this message that do not relate to the official
business of our company shall be understood as neither given nor endorsed by
it.