Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equityfuturesoption.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17 */
18
19#include <boost/make_shared.hpp>
26#include <ql/errors.hpp>
27
28using namespace QuantLib;
29
30namespace ore {
31namespace data {
32
33EquityFutureOption::EquityFutureOption(Envelope& env, OptionData option, const string& currency, Real quantity,
34 const QuantLib::ext::shared_ptr<ore::data::Underlying>& underlying, TradeStrike strike,
35 QuantLib::Date forwardDate, const QuantLib::ext::shared_ptr<QuantLib::Index>& index,
36 const std::string& indexName)
37 : VanillaOptionTrade(env, AssetClass::EQ, option, underlying->name(), currency, quantity, strike, index, indexName,
38 forwardDate),
39 underlying_(underlying) {
40 tradeType_ = "EquityFutureOption";
41}
42
43void EquityFutureOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) {
44 QL_REQUIRE(quantity_ > 0, "Equity futures option requires a positive quantity");
45 assetName_ = name();
46 // FIXME: use index once implemented
47 // const QuantLib::ext::shared_ptr<Market>& market = engineFactory->market();
48 // Handle<PriceTermStructure> priceCurve =
49 // market->equityPriceCurve(underlying_->name(), engineFactory->configuration(MarketContext::pricing));
50 // index_ = QuantLib::ext::make_shared<EquityFuturesIndex>(underlying_->name(), forwardDate, NullCalendar(), priceCurve);
51
52 // FIXME: we set the automatic exercise to false until the Equity Futures Index is implemented
53
54 QuantLib::Exercise::Type exerciseType = parseExerciseType(option_.style());
55 QL_REQUIRE(exerciseType == Exercise::European, "only european option currently supported");
57 VanillaOptionTrade::build(engineFactory);
58}
59
61 Trade::fromXML(node);
62 XMLNode* eqNode = XMLUtils::getChildNode(node, "EquityFutureOptionData");
63 QL_REQUIRE(eqNode, "No EquityFutureOptionData Node");
64 option_.fromXML(XMLUtils::getChildNode(eqNode, "OptionData"));
65 currency_ = XMLUtils::getChildValue(eqNode, "Currency", true);
66 quantity_ = XMLUtils::getChildValueAsDouble(eqNode, "Quantity", true);
67
68 XMLNode* tmp = XMLUtils::getChildNode(eqNode, "Underlying");
69 if (!tmp)
70 tmp = XMLUtils::getChildNode(eqNode, "Name");
71 UnderlyingBuilder underlyingBuilder("Underlying", "Name");
72 underlyingBuilder.fromXML(tmp);
73 underlying_ = underlyingBuilder.underlying();
74
75 strike_.fromXML(eqNode);
76
77 forwardDate_ = parseDate(XMLUtils::getChildValue(eqNode, "FutureExpiryDate", true));
78}
79
81 XMLNode* node = Trade::toXML(doc);
82 XMLNode* eqNode = doc.allocNode("EquityFutureOptionData");
83 XMLUtils::appendNode(node, eqNode);
85
86 XMLUtils::addChild(doc, eqNode, "Currency", currency_);
87 XMLUtils::addChild(doc, eqNode, "Quantity", quantity_);
88
89 XMLUtils::appendNode(eqNode, underlying_->toXML(doc));
90
92 XMLUtils::addChild(doc, eqNode, "FutureExpiryDate", to_string(forwardDate_));
93
94 return node;
95}
96
97std::map<AssetClass, std::set<std::string>>
98EquityFutureOption::underlyingIndices(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager) const {
99 return {{AssetClass::EQ, std::set<std::string>({name()})}};
100}
101
102} // namespace data
103} // namespace ore
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
QuantLib::ext::shared_ptr< ore::data::Underlying > underlying_
const std::string & name() const
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
Add underlying Equity names.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
EquityFutureOption()
Default constructor.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Serializable object holding option data.
Definition: optiondata.hpp:42
void setAutomaticExercise(bool automaticExercise)
Definition: optiondata.hpp:100
const string & style() const
Definition: optiondata.hpp:74
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
string tradeType_
Definition: trade.hpp:196
XMLNode * toXML(XMLDocument &doc) const
Definition: tradestrike.cpp:86
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
Definition: tradestrike.cpp:50
const QuantLib::ext::shared_ptr< Underlying > & underlying()
Definition: underlying.hpp:266
void fromXML(XMLNode *node) override
Definition: underlying.cpp:305
Serializable Vanilla Option.
QuantLib::Date forwardDate_
Store the (optional) forward date.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
Pricing Engine Factory.
EQ Futures Option data model and serialization.
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Definition: parsers.cpp:466
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
string conversion utilities
string name