About QuantLib::TimeSeries

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

About QuantLib::TimeSeries

tallent_e
Hi all.

I am having a rough time with the QuantLib::TimeSeries class.

I pasted my snippet code below.

I don't get (at all!) the result I expect. (See code the console output at the bottom of the code).

Can anyone provide a bit of help on this, please?

#include<vector>

#include<iostream>

#include<ql\quantlib.hpp>

 

int main()

{

       std::vector<QuantLib::Date> dates;

       std::vector<double> quotes;

 

       dates.push_back(QuantLib::Date(12, QuantLib::Nov, 2012));

       dates.push_back(QuantLib::Date(13, QuantLib::Nov, 2012));

       dates.push_back(QuantLib::Date(14, QuantLib::Nov, 2012));

 

       quotes.push_back(40.05);

       quotes.push_back(40.84);

       quotes.push_back(41.03);

 

       QuantLib::TimeSeries<double> series(dates.begin(), dates.begin(), quotes.end());

 

       // Is my time series empty?

       std::cout << "Is series empty?\t" << series.empty() << std::endl;


       // What was the value on November 14th, 2012?       

       std::cout << "Value on November 14th, 2012?\t" << series[QuantLib::Date(14, QuantLib::Nov, 2012)] << std::endl;

 

    return 0;

}

 

/*

Console Output:

Is series empty?     1

Value on November 14th 2012?      3.40282e +038

*/


Thank you very much, indeed.
Édouard

http://quantcorner.wordpress.com/.


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: About QuantLib::TimeSeries

alexandre p

Most likely you wanted quotes.begin() I should think.

Alexander

On Feb 10, 2013 1:34 PM, "Edouard Tallent" <[hidden email]> wrote:
Hi all.

I am having a rough time with the QuantLib::TimeSeries class.

I pasted my snippet code below.

I don't get (at all!) the result I expect. (See code the console output at the bottom of the code).

Can anyone provide a bit of help on this, please?

#include<vector>

#include<iostream>

#include<ql\quantlib.hpp>

 

int main()

{

       std::vector<QuantLib::Date> dates;

       std::vector<double> quotes;

 

       dates.push_back(QuantLib::Date(12, QuantLib::Nov, 2012));

       dates.push_back(QuantLib::Date(13, QuantLib::Nov, 2012));

       dates.push_back(QuantLib::Date(14, QuantLib::Nov, 2012));

 

       quotes.push_back(40.05);

       quotes.push_back(40.84);

       quotes.push_back(41.03);

 

       QuantLib::TimeSeries<double> series(dates.begin(), dates.begin(), quotes.end());

 

       // Is my time series empty?

       std::cout << "Is series empty?\t" << series.empty() << std::endl;


       // What was the value on November 14th, 2012?       

       std::cout << "Value on November 14th, 2012?\t" << series[QuantLib::Date(14, QuantLib::Nov, 2012)] << std::endl;

 

    return 0;

}

 

/*

Console Output:

Is series empty?     1

Value on November 14th 2012?      3.40282e +038

*/


Thank you very much, indeed.
Édouard

http://quantcorner.wordpress.com/.


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users