Re: using QuantLib interpolator

Posted by Kyle Schlansker-2 on
URL: http://quantlib.414.s1.nabble.com/using-QuantLib-interpolator-tp13863p13866.html

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