1

%d/%m%/%y.csv または .txt ファイルからそのような文字列を読み取ることがよくあるため、文字列(または他の同様の形式) を取得し、それをQuantLib::Dateobject constructorに適したものに変換する最も簡単な方法を知りたいと思います。

以下にコード例を示します。

#include <ql/quantlib.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
#include <boost/algorithm/string.hpp>

int main() {

  boost::timer timer;
  std::cout << 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<std::string> expiryDates;
  boost::split(expiryDates, datesString, boost::is_any_of(","));
  for(int i = 0; i < expiryDates.size(); i++)
  {
    std::cout << expiryDates[i] << std::endl;
  }
  // 17/10/2014
  // 21/11/2014
  // 19/12/2014
  // 20/03/2015
  // 19/06/2015
  // 18/09/2015
  // 18/12/2015
  // 17/06/2016

  // QuantLib::Date myQLDate(?);

  return 0;

  }
4

2 に答える 2

5

それは一種の非表示ですが、含める<ql/utilities/dataparsers.hpp>と次を使用できます。

Date d = DateParser::parseFormatted(expiryDates[i], format);

ここformatで、Boost.Date フォーマット文字列です。あなたの場合、

Date d = DateParser::parseFormatted(expiryDates[i], "%d/%m/%Y");

トリックを行う必要があります。

于 2014-10-10T20:20:23.663 に答える
3
  for(int i = 0; i < expiryDates.size(); i++)
  {
    int day, month, year;
    sscanf(expiryDates[i].c_str(), "%d/%d/%d", &day, &month, &year);
    QuantLib::Date myQLDate(day, month, year);
  }
于 2014-10-10T14:22:37.490 に答える