Re: Behavior of (ql)TimeSeries

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Behavior-of-ql-TimeSeries-tp7536p7537.html

On Thu, May 24, 2012 at 2:32 PM, Ballabio Gerardo
<[hidden email]> wrote:
> Hi all,
> I'm exploring time series in QuantLibXL. I discovered an aspect of their
> behavior that I find puzzling.
>
> When a date
> doesn't belong to the input set [...] it always returns 3.40282E+38, which I suppose is an exceptional
> value meaning "no valid value"

Yes, that's known as Null<double>() in the library. See <ql/utilities/null.hpp>.

> Then came the real surprise. I discovered that, when I call
> qlTimeSeriesValue on a nonexistent date, that date together with the
> value of 3.40282E+38 _get added to the time series_!!!

That's because of the behavior of the std::map<Date, double> underneath.
If you look at the implementation of TimeSeries in C++, you'll see
that the const version of operator[] returns Null without adding it,
but the non-const has to return a reference and therefore needs an
entry in the map to refer to.  If you didn't add it, you couldn't
write "series[d] = v;" to add a new value.

The real question (but I'm not overly familiar with that part, so
we'll have to rely on someone else) might be: why qlTimeSeriesValue,
which should only read from the time series, uses the non-const
version of operator[] instead of the const version?

Luigi

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users