24#include <boost/algorithm/string.hpp>
25#include <boost/archive/binary_iarchive.hpp>
26#include <boost/archive/binary_oarchive.hpp>
27#include <boost/serialization/export.hpp>
31using std::ostringstream;
52 return close(
strike_, p->strike());
61 : deltaType_(deltaType), optionType_(optionType), delta_(delta) {}
72 vector<string> tokens;
73 boost::split(tokens, strStrike, boost::is_any_of(
"/"));
74 QL_REQUIRE(tokens.size() == 4,
"DeltaStrike::fromString expects 4 tokens.");
75 QL_REQUIRE(tokens[0] ==
"DEL",
"DeltaStrike::fromString expects 1st token to equal 'DEL'.");
100AtmStrike::AtmStrike(DeltaVolQuote::AtmType atmType, boost::optional<DeltaVolQuote::DeltaType> deltaType)
101 : atmType_(atmType), deltaType_(deltaType) {
114 vector<string> tokens;
115 boost::split(tokens, strStrike, boost::is_any_of(
"/"));
116 QL_REQUIRE(tokens.size() == 2 || tokens.size() == 4,
"AtmStrike::fromString expects 2 or 4 tokens.");
117 QL_REQUIRE(tokens[0] ==
"ATM",
"AtmStrike::fromString expects 1st token to equal 'ATM'.");
122 if (tokens.size() == 4) {
123 QL_REQUIRE(tokens[2] ==
"DEL",
"AtmStrike::fromString expects 3rd token to equal 'DEL'.");
139 oss <<
"/DEL/" << (*deltaType_);
147 return (
atmType_ == p->atmType()) &&
155 QL_REQUIRE(
atmType_ != DeltaVolQuote::AtmNull,
"AtmStrike type must not be AtmNull.");
156 if (
atmType_ == DeltaVolQuote::AtmDeltaNeutral) {
157 QL_REQUIRE(
deltaType_,
"If AtmStrike type is AtmDeltaNeutral, we need a delta type.");
159 QL_REQUIRE(!
deltaType_,
"If AtmStrike type is not AtmDeltaNeutral, delta type should not be given.");
161 if (
atmType_ == DeltaVolQuote::AtmPutCall50) {
163 "If AtmStrike type is AtmPutCall50, delta type must be AtmFwd.");
178 vector<string> tokens;
179 boost::split(tokens, strStrike, boost::is_any_of(
"/"));
180 QL_REQUIRE(tokens.size() == 3,
"MoneynessStrike::fromString expects 3 tokens.");
181 QL_REQUIRE(tokens[0] ==
"MNY",
"MoneynessStrike::fromString expects 1st token to equal 'MNY'.");
205ostream&
operator<<(ostream& os, DeltaVolQuote::DeltaType type) {
207 case DeltaVolQuote::Spot:
209 case DeltaVolQuote::Fwd:
211 case DeltaVolQuote::PaSpot:
212 return os <<
"PaSpot";
213 case DeltaVolQuote::PaFwd:
214 return os <<
"PaFwd";
216 QL_FAIL(
"Unknown delta type");
220ostream&
operator<<(ostream& os, DeltaVolQuote::AtmType type) {
222 case DeltaVolQuote::AtmNull:
223 return os <<
"AtmNull";
224 case DeltaVolQuote::AtmSpot:
225 return os <<
"AtmSpot";
226 case DeltaVolQuote::AtmFwd:
227 return os <<
"AtmFwd";
228 case DeltaVolQuote::AtmDeltaNeutral:
229 return os <<
"AtmDeltaNeutral";
230 case DeltaVolQuote::AtmVegaMax:
231 return os <<
"AtmVegaMax";
232 case DeltaVolQuote::AtmGammaMax:
233 return os <<
"AtmGammaMax";
234 case DeltaVolQuote::AtmPutCall50:
235 return os <<
"AtmPutCall50";
237 QL_FAIL(
"Unknown atm type");
248 QL_FAIL(
"Unknown moneyness type");
253 if (type ==
"Spot") {
255 }
else if (type ==
"Fwd") {
258 QL_FAIL(
"Moneyness type '" << type <<
"' not recognized");
264 QuantLib::ext::shared_ptr<BaseStrike> strike;
269 vector<string> tokens;
270 boost::split(tokens, strStrike, boost::is_any_of(
"/"));
272 if (tokens.size() == 1) {
273 strike = QuantLib::ext::make_shared<AbsoluteStrike>();
274 }
else if (tokens[0] ==
"DEL") {
275 strike = QuantLib::ext::make_shared<DeltaStrike>();
276 }
else if (tokens[0] ==
"ATM") {
277 strike = QuantLib::ext::make_shared<AtmStrike>();
278 }
else if (tokens[0] ==
"MNY") {
279 strike = QuantLib::ext::make_shared<MoneynessStrike>();
281 QL_FAIL(
"Could not parse strike string '" << strStrike <<
"'.");
284 strike->fromString(strStrike);
292 ar& boost::serialization::base_object<BaseStrike>(*
this);
297 ar& boost::serialization::base_object<BaseStrike>(*
this);
304 ar& boost::serialization::base_object<BaseStrike>(*
this);
310 ar& boost::serialization::base_object<BaseStrike>(*
this);
319template void AtmStrike::serialize(boost::archive::binary_oarchive& ar,
const unsigned int version);
320template void AtmStrike::serialize(boost::archive::binary_iarchive& ar,
const unsigned int version);
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
void serialize(Archive &ar, const unsigned int version)
void fromString(const std::string &strStrike) override
QuantLib::Real strike() const
Return the absolute strike level.
std::string toString() const override
AbsoluteStrike()
Default constructor.
QuantLib::DeltaVolQuote::AtmType atmType_
void check() const
Perform validation.
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
void fromString(const std::string &strStrike) override
boost::optional< QuantLib::DeltaVolQuote::DeltaType > deltaType() const
Return the delta type.
AtmStrike()
Default constructor.
QuantLib::DeltaVolQuote::AtmType atmType() const
Return the ATM type.
std::string toString() const override
void serialize(Archive &ar, const unsigned int version)
boost::optional< QuantLib::DeltaVolQuote::DeltaType > deltaType_
virtual bool equal_to(const BaseStrike &other) const =0
Override in derived classes to compare specific Strikes.
virtual std::string toString() const =0
Write the Strike object to string.
void serialize(Archive &ar, const unsigned int version)
QuantLib::Real delta() const
Return the delta level.
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
DeltaStrike()
Default constructor.
void fromString(const std::string &strStrike) override
QuantLib::DeltaVolQuote::DeltaType deltaType_
QuantLib::Option::Type optionType_
QuantLib::DeltaVolQuote::DeltaType deltaType() const
Return the delta type.
std::string toString() const override
QuantLib::Option::Type optionType() const
Return the option type.
void serialize(Archive &ar, const unsigned int version)
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
void fromString(const std::string &strStrike) override
QuantLib::Real moneyness_
QuantLib::Real moneyness() const
Return the moneyness level.
std::string toString() const override
MoneynessStrike()
Default constructor.
Type type() const
Return the moneyness type.
void serialize(Archive &ar, const unsigned int version)
DeltaVolQuote::AtmType parseAtmType(const std::string &s)
Convert text to QuantLib::DeltaVolQuote::AtmType.
Real parseReal(const string &s)
Convert text to Real.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
DeltaVolQuote::DeltaType parseDeltaType(const std::string &s)
Convert text to QuantLib::DeltaVolQuote::DeltaType.
Classes for representing a strike using various conventions.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
bool operator==(const Dividend &d1, const Dividend &d)
MoneynessStrike::Type parseMoneynessType(const string &type)
Parse MoneynessStrike::Type from type.
std::string to_string(const LocationInfo &l)
QuantLib::ext::shared_ptr< BaseStrike > parseBaseStrike(const string &strStrike)
Parse a Strike from its string representation, strStrike.
Serializable Credit Default Swap.
BOOST_CLASS_EXPORT_IMPLEMENT(ore::data::AbsoluteStrike)
Map text representations to QuantLib/QuantExt types.
string conversion utilities