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 |
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:
------------------------------------------------------------------------------ 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 |
In reply to this post by Pavan Shah-2
On Fri, Jan 4, 2013 at 11:54 AM, Pavan Shah <[hidden email]> wrote:
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 |
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:
------------------------------------------------------------------------------ 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 |
Free forum by Nabble | Edit this page |