using QuantLib interpolator

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

using QuantLib interpolator

Pavan Shah-2
how can i convert a string from my map to a Real that I can then use as a value in a vector <Real> to be passed into QuantLib's interpolator constructor.

for example
i have

string testvol = Input_Vols["GBPUSDV9M CMPN Curncy"].at(1);

 vector <Real> xvec (10), yvec(10);
xvec[0]=1; yvec[0]= atof(testvol);


this doesn't work.  should i be using something other than atof()?

It says "no suitable conversion function from string to const char *."

Input_Vols above is a map <srting <vector <string> > .

any ideas ?

thanks
Pavan

------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: using QuantLib interpolator

Peter Caspers-4
Hi Pavan,

this is quite nice http://www.boost.org/doc/libs/1_52_0/doc/html/boost_lexical_cast.html

kind regards
Peter

Am 04.01.2013 17:54, schrieb Pavan Shah:
how can i convert a string from my map to a Real that I can then use as a value in a vector <Real> to be passed into QuantLib's interpolator constructor.

for example
i have

string testvol = Input_Vols["GBPUSDV9M CMPN Curncy"].at(1);

 vector <Real> xvec (10), yvec(10);
xvec[0]=1; yvec[0]= atof(testvol);


this doesn't work.  should i be using something other than atof()?

It says "no suitable conversion function from string to const char *."

Input_Vols above is a map <srting <vector <string> > .

any ideas ?

thanks
Pavan


------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812


_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: using QuantLib interpolator

Kyle Schlansker-2
In reply to this post by Pavan Shah-2
On Fri, Jan 4, 2013 at 11:54 AM, Pavan Shah <[hidden email]> wrote:
how can i convert a string from my map to a Real that I can then use as a value in a vector <Real> to be passed into QuantLib's interpolator constructor.

string testvol = Input_Vols["GBPUSDV9M CMPN Curncy"].at(1);

 vector <Real> xvec (10), yvec(10);
xvec[0]=1; yvec[0]= atof(testvol);

this doesn't work.  should i be using something other than atof()?
It says "no suitable conversion function from string to const char *."

Input_Vols above is a map <srting <vector <string> > .

any ideas ?

atof(testvol.c_str()) will solve your compilation issue, but that's not the approach I would take.


I would recommend creating some sort of model for your data and doing all type conversions during the parsing phase when reading from your input data source.  This ensures you only have to do a type conversion once ...

something as simple as this may work in your case:

// model your data with a simple struct
struct input_vol {
   Date d;
   Real p;
};

map<string, input_vol> vol_data;
std::string key;
std::string datestr;
double price;

// replace cin and while loop with whatever input loop you are using ...
while (cin >> key >> datestr >> price) {
   input_vol iv = { 
      DateParser::parseISO(datestr), 
      price 
   };
   vol_data[key] = iv;
}


//
// then, whenever you want to use your data ...
//
vector <Real> xvec (10), yvec(10);
xvec[0]=1;
yvec[0] = vol_data["GBPUSDV9M CMPN Curncy"].p;


-- 
Kyle Schlansker
Partner
Parametros Capital LLC
978.500.0388


------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: using QuantLib interpolator

Pavan Shah-2
thank you very much Kyle for the response

I certainly get your point.

However, in my case, once the data is parsed I am storing the data into maps and in some case multimaps.  The thing I should tell you is that
some of the mapped values are numeric and some are string. 
For example,  one row from in my csv file is 

25  EUR  450,000 1.45 12/23/2012  BANKA  

Lets say 25 is my key.  It seems like in your example above, I would create a struct that has all of these data types in the struct.  And then pass the struct into the map or multimap. And do the conversion as I am parsing the data.  I guess that would solve my problem.
Is that right Kyle?

I can certainly explore this approach as well. 

Thanks a  lot
Pavan


On Fri, Jan 4, 2013 at 1:23 PM, Kyle Schlansker <[hidden email]> wrote:
On Fri, Jan 4, 2013 at 11:54 AM, Pavan Shah <[hidden email]> wrote:
how can i convert a string from my map to a Real that I can then use as a value in a vector <Real> to be passed into QuantLib's interpolator constructor.

string testvol = Input_Vols["GBPUSDV9M CMPN Curncy"].at(1);

 vector <Real> xvec (10), yvec(10);
xvec[0]=1; yvec[0]= atof(testvol);

this doesn't work.  should i be using something other than atof()?
It says "no suitable conversion function from string to const char *."

Input_Vols above is a map <srting <vector <string> > .

any ideas ?

atof(testvol.c_str()) will solve your compilation issue, but that's not the approach I would take.


I would recommend creating some sort of model for your data and doing all type conversions during the parsing phase when reading from your input data source.  This ensures you only have to do a type conversion once ...

something as simple as this may work in your case:

// model your data with a simple struct
struct input_vol {
   Date d;
   Real p;
};

map<string, input_vol> vol_data;
std::string key;
std::string datestr;
double price;

// replace cin and while loop with whatever input loop you are using ...
while (cin >> key >> datestr >> price) {
   input_vol iv = { 
      DateParser::parseISO(datestr), 
      price 
   };
   vol_data[key] = iv;
}


//
// then, whenever you want to use your data ...
//
vector <Real> xvec (10), yvec(10);
xvec[0]=1;
yvec[0] = vol_data["GBPUSDV9M CMPN Curncy"].p;


-- 
Kyle Schlansker
Partner
Parametros Capital LLC
<a href="tel:978.500.0388" value="+19785000388" target="_blank">978.500.0388



------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users