Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
forwardrateagreement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017, 2023 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
24
25using namespace QuantLib;
26using namespace std;
27
28namespace ore {
29namespace data {
30
31void ForwardRateAgreement::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) {
32
33 // ISDA taxonomy
34 additionalData_["isdaAssetClass"] = string("Interest Rate");
35 additionalData_["isdaBaseProduct"] = string("FRA");
36 additionalData_["isdaSubProduct"] = string("");
37 additionalData_["isdaTransaction"] = string("");
38
39 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
40
41 Date startDate = parseDate(startDate_);
42 Date endDate = parseDate(endDate_);
43 Position::Type positionType = parsePositionType(longShort_);
44 auto index = market->iborIndex(index_);
45
46 QuantLib::ext::shared_ptr<FloatingRateCoupon> cpn;
47 if (auto overnightIndex = QuantLib::ext::dynamic_pointer_cast<QuantLib::OvernightIndex>(*index)) {
48 cpn = QuantLib::ext::make_shared<QuantExt::OvernightIndexedCoupon>(endDate, amount_, startDate, endDate, overnightIndex,
49 1.0, -strike_);
50 cpn->setPricer(QuantLib::ext::make_shared<QuantExt::OvernightIndexedCouponPricer>());
51 } else {
52 bool useIndexedCoupon = true;
53 cpn = QuantLib::ext::make_shared<QuantExt::IborFraCoupon>(startDate, endDate, amount_, *index, strike_);
54 cpn->setPricer(QuantLib::ext::make_shared<BlackIborCouponPricer>(
55 Handle<OptionletVolatilityStructure>(), BlackIborCouponPricer::TimingAdjustment::Black76,
56 Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(1.0))), useIndexedCoupon));
57 }
58 legs_.push_back({cpn});
59
60 Currency npvCcy = parseCurrency(currency_);
61 legCurrencies_.push_back(npvCcy.code());
62 legPayers_ = vector<bool>(1, positionType == Position::Type::Short);
63 isXCCY_ = false;
65 npvCurrency_ = npvCcy.code();
66 notionalCurrency_ = npvCcy.code();
67
68 QuantLib::ext::shared_ptr<QuantLib::Swap> swap(new QuantLib::Swap(legs_, legPayers_));
69 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("Swap");
70 QuantLib::ext::shared_ptr<SwapEngineBuilderBase> swapBuilder = QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
71 QL_REQUIRE(swapBuilder, "No Builder found for Swap " << id());
72 swap->setPricingEngine(swapBuilder->engine(npvCcy, std::string(), std::string()));
73 setSensitivityTemplate(*swapBuilder);
74 instrument_.reset(new VanillaInstrument(swap));
75 maturity_ = endDate;
76}
77
79 Trade::fromXML(node);
80 XMLNode* fNode = XMLUtils::getChildNode(node, "ForwardRateAgreementData");
81 startDate_ = XMLUtils::getChildValue(fNode, "StartDate", true);
82 endDate_ = XMLUtils::getChildValue(fNode, "EndDate", true);
83 currency_ = XMLUtils::getChildValue(fNode, "Currency", true);
84 index_ = XMLUtils::getChildValue(fNode, "Index", true);
85 longShort_ = XMLUtils::getChildValue(fNode, "LongShort", true);
86 strike_ = XMLUtils::getChildValueAsDouble(fNode, "Strike", true);
87 amount_ = XMLUtils::getChildValueAsDouble(fNode, "Notional", true);
88}
89
91 XMLNode* node = Trade::toXML(doc);
92 XMLNode* fNode = doc.allocNode("ForwardRateAgreementData");
93 XMLUtils::appendNode(node, fNode);
94 XMLUtils::addChild(doc, fNode, "StartDate", startDate_);
95 XMLUtils::addChild(doc, fNode, "EndDate", endDate_);
96 XMLUtils::addChild(doc, fNode, "Currency", currency_);
97 XMLUtils::addChild(doc, fNode, "Index", index_);
98 XMLUtils::addChild(doc, fNode, "LongShort", longShort_);
99 XMLUtils::addChild(doc, fNode, "Strike", strike_);
100 XMLUtils::addChild(doc, fNode, "Notional", amount_);
101 return node;
102}
103} // namespace data
104} // namespace ore
Engine builder for Swaps.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory) override
Build QuantLib/QuantExt instrument, link pricing engine.
bool isXCCY_
Definition: swap.hpp:84
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
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
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Vanilla Instrument Wrapper.
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
ForwardRateAgreement data model and serialization.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.