19#include <boost/make_shared.hpp>
21#include <ql/errors.hpp>
22#include <ql/exercise.hpp>
23#include <ql/instruments/compositeinstrument.hpp>
24#include <ql/instruments/vanillaoption.hpp>
44 const string& currency, Real strike, Real payoff,
45 const boost::optional<bool>& isFuturePrice,
const Date& futureExpiryDate)
46 : optionData_(optionData), name_(
name), currency_(currency), strike_(strike), payoff_(payoff),
47 isFuturePrice_(isFuturePrice), futureExpiryDate_(futureExpiryDate) {
56 additionalData_[
"isdaSubProduct"] = std::string(
"Price Return Basic Performance");
68 const QuantLib::ext::shared_ptr<Market>& market = engineFactory->market();
82 QL_REQUIRE(expiryDates.size() == 1,
83 "Expected exactly one expiry date for CommodityDigitalOption but got " << expiryDates.size() <<
".");
88 index_ = index->clone(expiryDate);
93 QL_REQUIRE(et == Exercise::European,
"European style expected for CommodityDigitalOption");
94 if (et == Exercise::European && QuantLib::ext::dynamic_pointer_cast<CommodityFuturesIndex>(
index_)) {
100 Real strikeSpread =
strike_ * 0.01;
101 Real strike1 =
strike_ - strikeSpread/2;
102 Real strike2 =
strike_ + strikeSpread/2;
106 opt1.
build(engineFactory);
107 opt2.
build(engineFactory);
108 QuantLib::ext::shared_ptr<Instrument> inst1 = opt1.
instrument()->qlInstrument();
109 QuantLib::ext::shared_ptr<Instrument> inst2 = opt2.
instrument()->qlInstrument();
113 QuantLib::ext::shared_ptr<CompositeInstrument> composite = QuantLib::ext::make_shared<CompositeInstrument>();
116 composite->add(inst1);
117 composite->subtract(inst2);
120 composite->add(inst2);
121 composite->subtract(inst1);
124 QL_FAIL(
"OptionType Call or Put required in CommodityDigitalOption " <<
id());
128 Real bsIndicator = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
129 Real multiplier =
payoff_ * bsIndicator / strikeSpread;
130 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
131 std::vector<Real> additionalMultipliers;
138 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
139 new VanillaInstrument(composite, multiplier, additionalInstruments, additionalMultipliers));
146 if (
expiryDate_ > Settings::instance().evaluationDate()) {
148 <<
" and strike " <<
strike_ <<
" is "
158std::map<AssetClass, std::set<std::string>>
168 QL_REQUIRE(commodityNode,
"A commodity option needs a 'CommodityDigitalOptionData' node");
QuantLib::Date futureExpiryDate_
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
Add underlying Commodity names.
CommodityDigitalOption()
Default constructor.
QuantLib::Date expiryDate_
Store the option expiry date.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory) override
Build underlying instrument and link pricing engine.
boost::optional< bool > isFuturePrice_
QuantLib::ext::shared_ptr< QuantLib::Index > index_
An index is needed if the option is to be automatically exercised on expiry.
Commodity option trade representation.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory) override
Build underlying instrument and link pricing engine.
Serializable object holding generic trade data, reporting dimensions.
static const string defaultConfiguration
Default configuration label.
Serializable object holding option data.
const string & callPut() const
const string & longShort() const
const string & style() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
const std::string & sensitivityTemplate() const
virtual void fromXML(XMLNode *node) override
Date addPremiums(std::vector< QuantLib::ext::shared_ptr< Instrument > > &instruments, std::vector< Real > &multipliers, const Real tradeMultiplier, const PremiumData &premiumData, const Real premiumMultiplier, const Currency &tradeCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &factory, const string &configuration)
void setSensitivityTemplate(const EngineBuilder &builder)
virtual XMLNode * toXML(XMLDocument &doc) const override
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
const Envelope & envelope() const
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
Vanilla Instrument Wrapper.
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static string getNodeValue(XMLNode *node)
Get a node's value.
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
Commodity digital option representation as call spread.
Commodity option representation.
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
bool parseBool(const string &s)
Convert text to bool.
Classes and functions for log message handling.
#define DLOG(text)
Logging Macro (Level = Debug)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
std::string to_string(const LocationInfo &l)
Serializable Credit Default Swap.
string conversion utilities