Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
callableswap.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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
20
26
27namespace ore {
28namespace data {
29
30void CallableSwap::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) {
31 LOG("Building CallableSwap " << id());
32 swap_.reset();
34 // we need to do set the id manually because it otherwise remains blank
35 swap_.id() = id() + "_Swap";
36 swap_.build(engineFactory);
37 // likewise here, and now it is essential because the engine is stored by id if the option style is Bermudan
38 swaption_.id() = id() + "_Swaption";
39 swaption_.build(engineFactory);
40
42
43 instrument_ = QuantLib::ext::make_shared<CompositeInstrumentWrapper>(
44 std::vector<QuantLib::ext::shared_ptr<InstrumentWrapper>>{swap_.instrument(), swaption_.instrument()});
45
46 legs_ = swap_.legs();
49 if (swaption_.isExercised()) {
50 legs_.insert(legs_.end(), swaption_.legs().begin(), swaption_.legs().end());
52 bool isShort = parsePositionType(swaption_.optionData().longShort()) == QuantLib::Position::Short;
53 for (auto const& p : swaption_.legPayers()) {
54 legPayers_.push_back(isShort ? !p : p);
55 }
56 }
57
62
64}
65
66const std::map<std::string, boost::any>& CallableSwap::additionalData() const { return swap_.additionalData(); }
67
69 Trade::fromXML(node);
70 XMLNode* swapNode = XMLUtils::getChildNode(node, "CallableSwapData");
71
72 vector<LegData> legData;
73 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(swapNode, "LegData");
74 for (Size i = 0; i < nodes.size(); i++) {
75 auto ld = QuantLib::ext::make_shared<ore::data::LegData>();
76 ld->fromXML(nodes[i]);
77 legData.push_back(*ld);
78 }
79 swap_ = ore::data::Swap(envelope(), legData);
80
81 OptionData optionData;
82 optionData.fromXML(XMLUtils::getChildNode(swapNode, "OptionData"));
83 if (parsePositionType(optionData.longShort()) == QuantLib::Position::Long) {
84 vector<LegData> reversedLegData(legData);
85 for (auto& l : reversedLegData)
86 l.isPayer() = !l.isPayer();
87 swaption_ = ore::data::Swaption(envelope(), optionData, reversedLegData);
88 } else {
89 swaption_ = ore::data::Swaption(envelope(), optionData, legData);
90 }
91}
92
94 XMLNode* node = Trade::toXML(doc);
95 XMLNode* swapNode = doc.allocNode("CallableSwapData");
96 XMLUtils::appendNode(node, swapNode);
97
98 for (Size i = 0; i < swap_.legData().size(); i++) {
99 // poor const correctness in ORE, so we copy...
100 LegData ld = swap_.legData()[i];
101 XMLUtils::appendNode(swapNode, ld.toXML(doc));
102 }
103
104 // same as above...
106 XMLUtils::appendNode(swapNode, od.toXML(doc));
107
108 return node;
109}
110
111} // namespace data
112} // namespace ore
Callable Swap data model and serialization.
virtual void fromXML(ore::data::XMLNode *node) override
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
ore::data::Swaption swaption_
ore::data::Swap swap_
const std::map< std::string, boost::any > & additionalData() const override
returns all additional data returned by the trade once built
Serializable object holding leg data.
Definition: legdata.hpp:844
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: legdata.cpp:856
Serializable object holding option data.
Definition: optiondata.hpp:42
const string & longShort() const
Definition: optiondata.hpp:70
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
void addData(const RequiredFixings &requiredFixings)
Serializable Swap, Single and Cross Currency.
Definition: swap.hpp:36
const vector< LegData > & legData() const
Definition: swap.hpp:74
std::string notionalCurrency() const override
Definition: swap.cpp:286
QuantLib::Real notional() const override
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
Definition: swap.cpp:267
virtual void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Definition: swap.cpp:45
const std::map< std::string, boost::any > & additionalData() const override
returns all additional data returned by the trade once built
Definition: swap.cpp:228
Serializable Swaption.
Definition: swaption.hpp:39
bool isExercised() const
Definition: swaption.cpp:445
const OptionData & optionData() const
Definition: swaption.hpp:49
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Definition: swaption.cpp:62
string npvCurrency_
Definition: trade.hpp:201
const std::string & sensitivityTemplate() const
Definition: trade.cpp:305
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
const std::vector< QuantLib::Leg > & legs() const
Definition: trade.hpp:143
const Date & maturity() const
Definition: trade.hpp:157
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
const RequiredFixings & requiredFixings() const
Definition: trade.hpp:90
QuantLib::Real notional_
Definition: trade.hpp:202
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
const std::vector< string > & legCurrencies() const
Definition: trade.hpp:145
string & id()
Set the trade id.
Definition: trade.hpp:118
const std::vector< bool > & legPayers() const
Definition: trade.hpp:147
RequiredFixings requiredFixings_
Definition: trade.hpp:223
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
Definition: trade.hpp:141
const string & npvCurrency() const
Definition: trade.hpp:149
const Envelope & envelope() const
Definition: trade.hpp:135
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
void reset()
Reset trade, clear all base class data. This does not reset accumulated timings for this trade.
Definition: trade.cpp:130
string notionalCurrency_
Definition: trade.hpp:203
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
used to store multiple trade wrappers
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
leg data model and serialization
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
Size size(const ValueType &v)
Definition: value.cpp:145
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Wrapper for option instruments, tracks whether option has been exercised or not.
string conversion utilities