c++ - Convert a date std::string into a QuantLib::Date object -


As often happens to read such strings from .csv or .txt files, I know the easiest way to get Want to convert to a % d /% m% /% y (or any other similar format) string and do something suitable for the QuantLib :: Date object .

Below one example code:

  #include & lt; Ql / quantlib.hpp & gt; # Include & lt; Boost / timer.hpp & gt; # Include & lt; Iostream & gt; # Include & lt; Iomanip & gt; # Include & lt; Boost / algorithm / string HP & gt; Int main () {boost :: timer timer; Std :: cout & lt; & Lt; Std :: endl; Std :: string datesString = {", 17/10 / 2014/21/11 / 2014,19 / 12/2014/20/03/2015, 19/06/2015, 18/09/2015, 18 / 12/2015 , 17/06/2016, "}; Std :: vector & lt; Std :: string & gt; ExpiryDates; Promotion: Partition (end date, date string, boost: is_any_of (",")); For (int i = 0; i    

It is hidden, but once you & lt; Ql / utilities / dataprurs HP & gt; You can use:

  date d = date parser :: parformatted (expiration date [i], format);   

Where format is a boost.adet format string. In your case,

  date d = date parser :: parformatted (expiration date [i], "% d /% m /% y");   

should do the trick.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -