21#include <ql/errors.hpp>
23#include <boost/algorithm/string.hpp>
24#include <boost/make_shared.hpp>
25#include <boost/tokenizer.hpp>
36 static map<string, CurveSpec::CurveType> b = {
59 QL_FAIL(
"Cannot convert \"" << s <<
"\" to CurveSpecType");
67 boost::escaped_list_separator<char> sep(
'\\',
'/',
'\"');
68 boost::tokenizer<boost::escaped_list_separator<char> > tokenSplit(s, sep);
70 vector<string> tokens(tokenSplit.begin(), tokenSplit.end());
72 QL_REQUIRE(tokens.size() > 1,
"number of tokens too small in curve spec " << s);
81 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
82 " of tokens in yield curve spec "
84 const string& ccy = tokens[1];
85 const string& curveConfigID = tokens[2];
86 return QuantLib::ext::make_shared<YieldCurveSpec>(ccy, curveConfigID);
91 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
92 " of tokens in default curve spec "
94 const string& ccy = tokens[1];
95 const string& curveConfigID = tokens[2];
96 return QuantLib::ext::make_shared<DefaultCurveSpec>(ccy, curveConfigID);
101 QL_REQUIRE(tokens.size() == 2,
"Unexpected number"
102 " of tokens in cds vol spec "
104 const string& curveConfigID = tokens[1];
105 return QuantLib::ext::make_shared<CDSVolatilityCurveSpec>(curveConfigID);
110 QL_REQUIRE(tokens.size() == 2,
"Unexpected number"
111 " of tokens in cds vol spec "
113 const string& curveConfigID = tokens[1];
114 return QuantLib::ext::make_shared<BaseCorrelationCurveSpec>(curveConfigID);
119 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
120 " of tokens in FX curve spec "
122 const string& unitCcy = tokens[1];
123 const string& ccy = tokens[2];
124 return QuantLib::ext::make_shared<FXSpotSpec>(unitCcy, ccy);
129 QL_REQUIRE(tokens.size() == 4,
"Unexpected number"
130 " of tokens in fx vol curve spec "
132 const string& unitCcy = tokens[1];
133 const string& ccy = tokens[2];
134 const string& curveConfigID = tokens[3];
135 return QuantLib::ext::make_shared<FXVolatilityCurveSpec>(unitCcy, ccy, curveConfigID);
140 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
141 " of tokens in swaption vol curve spec "
143 const string& key = tokens[1];
144 const string& curveConfigID = tokens[2];
145 return QuantLib::ext::make_shared<SwaptionVolatilityCurveSpec>(key, curveConfigID);
150 QL_REQUIRE(tokens.size() == 2,
"Unexpected number"
151 " of tokens in yield vol curve spec "
153 const string& curveConfigID = tokens[1];
154 return QuantLib::ext::make_shared<YieldVolatilityCurveSpec>(curveConfigID);
161 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
162 " of tokens in CapFloor volatility curve spec "
164 const string& key = tokens[1];
165 const string& curveConfigID = tokens[2];
166 return QuantLib::ext::make_shared<CapFloorVolatilityCurveSpec>(key, curveConfigID);
171 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
172 " of tokens in inflation curve spec "
174 const string& index = tokens[1];
175 const string& curveConfigID = tokens[2];
176 return QuantLib::ext::make_shared<InflationCurveSpec>(index, curveConfigID);
181 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
182 " of tokens in InflationCapFloor volatility curve spec "
184 const string& index = tokens[1];
185 const string& curveConfigID = tokens[2];
186 return QuantLib::ext::make_shared<InflationCapFloorVolatilityCurveSpec>(index, curveConfigID);
191 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
192 " of tokens in default curve spec "
194 const string& ccy = tokens[1];
195 const string& curveConfigID = tokens[2];
196 return QuantLib::ext::make_shared<EquityCurveSpec>(ccy, curveConfigID);
201 QL_REQUIRE(tokens.size() == 3,
"Unexpected number"
202 " of tokens in default curve spec "
204 const string& ccy = tokens[1];
205 const string& curveConfigID = tokens[2];
206 return QuantLib::ext::make_shared<EquityVolatilityCurveSpec>(ccy, curveConfigID);
211 QL_REQUIRE(tokens.size() == 2,
"Unexpected number"
212 " of tokens in Security Spread spec "
214 const string& securityID = tokens[1];
215 return QuantLib::ext::make_shared<SecuritySpec>(securityID);
220 QL_REQUIRE(tokens.size() == 3,
"Unexpected number of tokens in commodity curve spec " << s);
221 return QuantLib::ext::make_shared<CommodityCurveSpec>(tokens[1], tokens[2]);
226 QL_REQUIRE(tokens.size() == 3,
"Unexpected number of tokens in commodity volatility spec " << s);
227 return QuantLib::ext::make_shared<CommodityVolatilityCurveSpec>(tokens[1], tokens[2]);
232 QL_REQUIRE(tokens.size() == 2,
"Unexpected number of tokens in correlation spec " << s);
233 string id = tokens[1];
234 return QuantLib::ext::make_shared<CorrelationCurveSpec>(
id);
240 QL_FAIL(
"Unable to convert \"" << s <<
"\" into CurveSpec");
245 static const map<string, CurveSpec::CurveType> b = {
268 QL_FAIL(
"Cannot convert \"" << s <<
"\" to CurveSpecType");
CurveType
Supported curve types.
@ InflationCapFloorVolatility
QuantLib::ext::shared_ptr< CurveSpec > parseCurveSpec(const string &s)
function to convert a string into a curve spec
CurveSpec::CurveType parseCurveConfigurationType(const std::string &s)
function to convert a curve configuration node string into a curve spec type
Serializable Credit Default Swap.