22#include <ql/errors.hpp>
23#include <boost/thread/mutex.hpp>
24#include <boost/thread/lock_guard.hpp>
25#include <boost/regex.hpp>
31 static boost::mutex mutex_;
32 boost::lock_guard<boost::mutex> lock(mutex_);
34 boost::regex m1(
"^(ATM|atm)");
35 boost::regex m1b(
"^(ATMF|atmf)");
36 boost::regex m2(
"^(ATM|atm)(\\+|\\-)([0-9]+[.]?[0-9]*)");
37 boost::regex m3(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)");
38 boost::regex m4(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(d|D)");
39 boost::regex m4b(
"(d|D)");
40 boost::regex m5(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(c|C)");
41 boost::regex m5b(
"^(c|C)");
42 boost::regex m6(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(p|P)");
43 boost::regex m6b(
"^(p|P)");
44 boost::regex m7(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(bf|BF)");
45 boost::regex m7b(
"^(bf|BF)");
46 boost::regex m8(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(rr|RR)");
47 boost::regex m8b(
"^(rr|RR)");
48 boost::regex m9(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(ATMF|atmf)");
49 boost::regex m9b(
"(ATMF|atmf)");
50 boost::regex m10(
"^(\\+|\\-)?([0-9]+[.]?[0-9]*)(ATM|atm)");
51 boost::regex m10b(
"(ATM|atm)");
53 if (boost::regex_match(s, m1)) {
58 if (boost::regex_match(s, m1b)) {
63 if (boost::regex_match(s, m2)) {
68 if (boost::regex_match(s, m3)) {
73 if (boost::regex_match(s, m4)) {
78 if (boost::regex_match(s, m5)) {
83 if (boost::regex_match(s, m6)) {
88 if (boost::regex_match(s, m7)) {
93 if (boost::regex_match(s, m8)) {
98 if (boost::regex_match(s, m9)) {
103 if (boost::regex_match(s, m10)) {
105 result.
value =
parseReal(regex_replace(s, m10b, std::string(
"")));
108 QL_FAIL(
"could not parse strike given by " << s);
129 out <<
"ATMF_Moneyness";
132 out <<
"ATM_Moneyness";
162 Strike tmp1 = normaliseStrike(s1);
163 Strike tmp2 = normaliseStrike(s2);
174 return atm + s.
value;
178 QL_FAIL(
"can not compute absolute strike for type delta");
180 return atmf * s.
value;
182 return atm * s.
value;
184 QL_FAIL(
"can not compute strike for unknown type " << s);
189 QL_REQUIRE(!s.empty() && (s.back() ==
'P' || s.back() ==
'C' || s ==
"ATM"),
190 "invalid delta quote, expected ATM, 10P, 25C, ...");
192 isPut_ = !s.empty() && s.back() ==
'P';
193 isCall_ = !s.empty() && s.back() ==
'C';
197 }
catch (
const std::exception& e) {
198 QL_FAIL(
"DeltaString: can not convert call / put delta '" << s <<
"' to numeric value: " << e.what());
DeltaString(const std::string &s)
Strike parseStrike(const std::string &s)
Convert text to Strike.
QuantLib::Real computeAbsoluteStrike(const Strike &s, const QuantLib::Real atm, const QuantLib::Real atmf)
Convenience function that computes an absolute strike.
Real parseReal(const string &s)
Convert text to Real.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
bool operator==(const Dividend &d1, const Dividend &d)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.