Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
todaysmarketparameters.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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/*! \file ored/marketdata/todaysmarketparameters.hpp
20 \brief A class to hold todays market configuration(s)
21 \ingroup marketdata
22*/
23
24#pragma once
25
30#include <unordered_map>
31
32namespace ore {
33namespace data {
37using std::pair;
38using std::string;
39using std::vector;
40
41//! Market Configuration structure
42/*!
43 The Market Configuration bundles configurations for each of the market objects
44 and assigns a configuration ID.
45
46 Several Market Configurations can be specified and held in a market object in parallel.
47 Applications then need to specify the desired market configuration ID when making calls
48 to any of the term structures provided by the market object.
49
50 \ingroup marketdata
51 */
52
53std::ostream& operator<<(std::ostream& out, const MarketObject& o);
54
55std::set<MarketObject> getMarketObjectTypes();
56
58public:
59 MarketConfiguration(map<MarketObject, string> marketObjectIds = {});
60 string operator()(const MarketObject o) const;
61 void setId(const MarketObject o, const string& id);
62 void add(const MarketConfiguration& o);
63
64private:
65 map<MarketObject, string> marketObjectIds_;
66};
67
68//! Today's Market Parameters
69/*!
70 This class is a container of instructions (all text) for how to build
71 a market object.
72
73 An instance of this object is needed in order to call a TodaysMarket
74 constructor.
75
76 \ingroup curves
77 */
79public:
80 //! Default constructor
82
83 //! \name Inspectors
84 //@{
85 const vector<pair<string, MarketConfiguration>>& configurations() const;
86 bool hasConfiguration(const string& configuration) const;
87 bool hasMarketObject(const MarketObject& o) const;
88
89 //! EUR => Yield/EUR/EUR6M, USD => Yield/USD/USD3M etc.
90 const map<string, string>& mapping(const MarketObject o, const string& configuration) const;
91
92 //! return a mapping reference for modification
93 map<string, string>& mappingReference(const MarketObject o, const string& configuration);
94
95 //! Build a vector of all the curve specs (may contain duplicates)
96 vector<string> curveSpecs(const string& configuration) const;
97
98 //! Intermediate id for a given market object and configuration, see the description of configurations_ below
99 string marketObjectId(const MarketObject o, const string& configuration) const;
100 //@}
101
102 //! Clear the contents
103 void clear();
104
105 //! Check if any parameters
106 bool empty();
107
108 //! \name Setters
109 //@{
110 void addConfiguration(const string& name, const MarketConfiguration& configuration);
111 void addMarketObject(const MarketObject o, const string& id, const map<string, string>& assignments);
112 //@}
113
114 //! \name Serialisation
115 //@{
116 void fromXML(XMLNode* node) override;
117 XMLNode* toXML(XMLDocument& doc) const override;
118 //@}
119
120private:
121 /* Maps a configuration label to a MarketConfiguration instance. For the command line application, the configuration
122 label is specified under the Markets node in ore.xml. An example is given by:
123
124 default => (DiscountCurve => xois_eur)
125 collateral_inccy => (DiscountCurve => ois)
126 collateral_eur => (DiscountCurve => xois_eur)
127 ...
128
129 The RHS maps each market object to a configuration id, which is an intermediate identifier used to group
130 assignments for each market object together, see the description of marketObjects_ below. Missing market objects
131 are mapped to the market default configuration "default". The latter is defined as a constant in
132 Market::defaultConfiguration.
133
134 A configuration label "default" is always added, which maps all market objects to the market default
135 configuration "default". The entries for the configuration label "default" can be overwritten though. */
136 vector<pair<string, MarketConfiguration>> configurations_;
137
138 /* For each market object type, maps the intermediate configuration id to a list of assignments, e.g.
139
140 DiscountCurve => (xois_eur => (EUR => Yield/EUR/EUR1D,
141 USD => Yield/USD/USD-IN_EUR)
142 ois => (EUR => Yield/EUR/EUR1D,
143 USD => Yield/USD/USD1D))
144 IndexCurve => ...
145
146 For each pair (market object, intermediate configuration id) defined in the rhs of the configurations_ map, a
147 mapping should be defined in marketObjects_). */
148 map<MarketObject, map<string, map<string, string>>> marketObjects_;
149
150 void curveSpecs(const map<string, map<string, string>>&, const string&, vector<string>&) const;
151};
152
153// inline
154
155inline const vector<pair<string, MarketConfiguration>>& TodaysMarketParameters::configurations() const {
156 return configurations_;
157}
158
159inline bool TodaysMarketParameters::hasConfiguration(const string& configuration) const {
160 auto it = find_if(configurations_.begin(), configurations_.end(),
161 [&configuration](const pair<string, MarketConfiguration>& s) { return s.first == configuration; });
162 return it != configurations_.end();
163}
164
166 auto it = marketObjects_.find(o);
167 return it != marketObjects_.end();
168}
169
170inline string TodaysMarketParameters::marketObjectId(const MarketObject o, const string& configuration) const {
171 QL_REQUIRE(hasConfiguration(configuration), "configuration " << configuration << " not found");
172 auto it = find_if(configurations_.begin(), configurations_.end(),
173 [&configuration](const pair<string, MarketConfiguration>& s) { return s.first == configuration; });
174 return it->second(o);
175}
176
177} // namespace data
178} // namespace ore
void setId(const MarketObject o, const string &id)
map< MarketObject, string > marketObjectIds_
string operator()(const MarketObject o) const
void add(const MarketConfiguration &o)
vector< pair< string, MarketConfiguration > > configurations_
vector< string > curveSpecs(const string &configuration) const
Build a vector of all the curve specs (may contain duplicates)
bool hasConfiguration(const string &configuration) const
void addMarketObject(const MarketObject o, const string &id, const map< string, string > &assignments)
const vector< pair< string, MarketConfiguration > > & configurations() const
bool empty()
Check if any parameters.
const map< string, string > & mapping(const MarketObject o, const string &configuration) const
EUR => Yield/EUR/EUR6M, USD => Yield/USD/USD3M etc.
map< MarketObject, map< string, map< string, string > > > marketObjects_
bool hasMarketObject(const MarketObject &o) const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
void addConfiguration(const string &name, const MarketConfiguration &configuration)
map< string, string > & mappingReference(const MarketObject o, const string &configuration)
return a mapping reference for modification
string marketObjectId(const MarketObject o, const string &configuration) const
Intermediate id for a given market object and configuration, see the description of configurations_ b...
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
XML Utilities Class.
Definition: xmlutils.hpp:119
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
Base Market class.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
MarketObject
Definition: market.hpp:65
std::set< MarketObject > getMarketObjectTypes()
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
string name
XML utility functions.