Hi all,
I'm exploring time series in QuantLibXL. I discovered an aspect of their behavior that I find puzzling. To start, I built a TimeSeries object by calling qlTimeSeries on a pair of dates/values vectors. Then I called qlTimeSeriesValue on various dates. Of course when a date belongs to the input dates set that I built the TimeSeries from, the corresponding value is returned. When a date doesn't belong to the input set, I was expecting to obtain the value on the latest previous date, or maybe some kind of interpolated value. Instead it always returns 3.40282E+38, which I suppose is an exceptional value meaning "no valid value" (if I remember correctly it is the largest possible value for 32-bit IEEE floats). As far as I can see there is no way, at least in QuantLibXL, to change that behavior (if there is one please tell me). I don't like it very much but I understand that, as the most conservative choice, you can argue it's the right thing to do. 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_!!! (The attached excel file demonstrates that.) I can't think of a good reason for doing that. If the function returned an interpolated value, I see how caching it could give a performance improvement, especially if the interpolation formula was complex. But how is it useful to cache the value if it's always 3.40282E+38??? I don't think there's any performance gain to be obtained from that. Finding whether a date is already there takes almost the same time if it's there as if it isn't (I'm assuming some kind of binary search is used). In fact the performance might even get worse, because you have to insert the new date/value pair, and the vectors might have to be reallocated. Instead I can think of at least one reason why it seems a bad idea: logically qlTimeSeriesValue should be a read-only operation which leaves the target object unmodified, but in fact it isn't. Caching the date isn't just a hidden implementation detail, it can have side effects. For example if I call it on a date that is outside the current range, the range is extended, thus the return value of either qlTimeSeriesFirstDate or qlTimeSeriesLastDate changes (this actually happened to me, that's how I noticed). Or if I want to interpolate in my excel sheet between available dates, I must be very careful to _never_ call qlTimeSeriesValue on missing dates, or I'd spoil it. Thanks Gerardo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <div style="font-family:Calibri;font-size:10px"> Banca Profilo S.p.A. Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057 Capitale Sociale Euro 136.794.106,00 i.v. Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email] Iscritta all’Albo delle Banche e dei Gruppi bancari Aderente al Fondo Interbancario di Tutela dei depositi Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A. DISCLAIMER: The information transmitted may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. </div> </body> </html> ------------------------------------------------------------------------------ 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 timeseries.xlsx (13K) Download Attachment |
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 |
Da: Luigi Ballabio [mailto:[hidden email]]
> > 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? You're saying that wasn't intentional, aren't you? Gerardo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <div style="font-family:Calibri;font-size:10px"> Banca Profilo S.p.A. Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057 Capitale Sociale Euro 136.794.106,00 i.v. Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email] Iscritta all’Albo delle Banche e dei Gruppi bancari Aderente al Fondo Interbancario di Tutela dei depositi Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A. DISCLAIMER: The information transmitted may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. </div> </body> </html> ------------------------------------------------------------------------------ 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 |
On Thu, May 24, 2012 at 3:57 PM, Ballabio Gerardo
<[hidden email]> wrote: >> 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? > > You're saying that wasn't intentional, aren't you? It might be, but I'm not positive. There might be a reason that escapes me. 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 |
Free forum by Nabble | Edit this page |