Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
indexparser.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/utilities/indexparser.hpp
20 \brief Map text representations to QuantLib/QuantExt types
21 \ingroup utilities
22*/
23
24#pragma once
25
26#include <ql/index.hpp>
27#include <ql/indexes/iborindex.hpp>
28#include <ql/indexes/inflationindex.hpp>
29#include <ql/indexes/swapindex.hpp>
35
36namespace ore {
37namespace data {
38using QuantLib::Handle;
39using QuantLib::IborIndex;
40using QuantLib::Index;
41using QuantLib::Quote;
42using QuantLib::SwapIndex;
43using QuantLib::YieldTermStructure;
44using QuantLib::ZeroInflationIndex;
45using QuantLib::ZeroInflationTermStructure;
46using std::string;
47
48//! Convert std::string to QuantExt::FxIndex
49/*!
50 \ingroup utilities
51*/
52QuantLib::ext::shared_ptr<QuantExt::FxIndex>
53parseFxIndex(const string& s, const Handle<Quote>& fxSpot = Handle<Quote>(),
54 const Handle<YieldTermStructure>& sourceYts = Handle<YieldTermStructure>(),
55 const Handle<YieldTermStructure>& targetYts = Handle<YieldTermStructure>(),
56 const bool useConventions = false);
57
58//! Convert std::string to QuantLib::IborIndex
59/*!
60 \ingroup utilities
61*/
62QuantLib::ext::shared_ptr<IborIndex> parseIborIndex(const string& s,
63 const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>());
64
65//! Convert std::string to QuantLib::IborIndex and return the tenor string component of the index
66/*! In some cases, after parsing the IborIndex, we would like to know the exact tenor string that was part of
67 the \p strIndex that was parsed. If we ask the resulting index for its tenor via the method
68 `Period InterestRateIndex::tenor()`, it can be difficult to deduce the original tenor string. A simple example of
69 this is `MXN-TIIE-28D` where if you call `tenor()` and then `to_string()`, you get `4W` which is different than
70 the original `28D` that is passed in.
71
72 \warning If the \p strIndex does not have a tenor component, as is the usual case for overnight indices,
73 \p outTenor will be populated with the empty string.
74
75 \ingroup utilities
76*/
77QuantLib::ext::shared_ptr<IborIndex> parseIborIndex(
78 const std::string& strIndex, std::string& outTenor,
79 const QuantLib::Handle<QuantLib::YieldTermStructure>& h = QuantLib::Handle<QuantLib::YieldTermStructure>());
80
81//! Try to convert std::string to QuantLib::IborIndex
82/*!
83 \ingroup utilities
84*/
85bool tryParseIborIndex(const string& s, QuantLib::ext::shared_ptr<IborIndex>& index);
86
87//! Return true if the \p indexName is that of a generic ibor index, otherwise false
88/*!
89 \ingroup utilities
90*/
91bool isGenericIborIndex(const string& indexName);
92
93/*! Returns true as the first element in the pair if the \p indexName is that of an InflationIndex. The second element
94 in the pair is an instance of the inflation index. If \p indexName is not an inflation index, the first element in
95 the pair is \c false and the second element is a \c nullptr.
96
97 If inflation indices have been set up via ZeroInflationIndex entries in the Conventions, the \p conventions
98 should be passed here. If not, the default \c nullptr parameter will be sufficient.
99
100 \ingroup utilities
101*/
102std::pair<bool, QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>> isInflationIndex(const std::string& indexName);
103
104//! Return true if the \p indexName is that of an EquityIndex, otherwise false
105/*!
106 \ingroup utilities
107*/
108bool isEquityIndex(const std::string& indexName);
109
110//! Return true if the \p indexName is that of an CommodityIndex, otherwise false
111/*!
112 \ingroup utilities
113*/
114bool isCommodityIndex(const std::string& indexName);
115
116/*! Return true if the \p indexName is that of an GenericIndex, otherwise false
117 \ingroup utilities
118*/
119bool isGenericIndex(const std::string& indexName);
120
121//! Convert std::string (e.g SP5) to QuantExt::EquityIndex
122/*!
123\ingroup utilities
124*/
125QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> parseEquityIndex(const string& s);
126
127//! Convert std::string to QuantLib::SwapIndex
128/*!
129 \ingroup utilities
130*/
131QuantLib::ext::shared_ptr<SwapIndex>
132parseSwapIndex(const string& s, const Handle<YieldTermStructure>& forwarding = Handle<YieldTermStructure>(),
133 const Handle<YieldTermStructure>& discounting = Handle<YieldTermStructure>());
134
135//! Convert std::string to QuantLib::ZeroInflationIndex
136/*!
137 \ingroup utilities
138 */
139QuantLib::ext::shared_ptr<ZeroInflationIndex>
140parseZeroInflationIndex(const string& s, const Handle<ZeroInflationTermStructure>& h = Handle<ZeroInflationTermStructure>());
141
142QL_DEPRECATED
143QuantLib::ext::shared_ptr<ZeroInflationIndex>
144parseZeroInflationIndex(const string& s, bool isInterpolated,
145 const Handle<ZeroInflationTermStructure>& h = Handle<ZeroInflationTermStructure>());
146
147//! Convert std::string to QuantExt::BondIndex
148/*!
149 \ingroup utilities
150 */
151QuantLib::ext::shared_ptr<QuantExt::BondIndex> parseBondIndex(const string& s);
152
153//! Convert std::string to QuantExt::ConstantMaturityBondIndex
154/*!
155 \ingroup utilities
156 */
157QuantLib::ext::shared_ptr<QuantExt::ConstantMaturityBondIndex> parseConstantMaturityBondIndex(const string& s);
158
159/*! Convert std::string to QuantExt::ComodityIndex
160
161 This function can be used to parse commodity spot \e indices or commodity future \e indices:
162 - for spot \e indices, the \p name is of the form <tt>COMM-EXCHANGE:COMMODITY</tt>
163 - for future \e indices, the \p name is of the form <tt>COMM-EXCHANGE:CONTRACT:YYYY-MM</tt> or
164 <tt>COMM-EXCHANGE:CONTRACT:YYYY-MM-DD</tt>
165
166 \ingroup utilities
167 */
168QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> parseCommodityIndex(
169 const std::string& name, bool hasPrefix = true,
170 const QuantLib::Handle<QuantExt::PriceTermStructure>& ts = QuantLib::Handle<QuantExt::PriceTermStructure>(),
171 const QuantLib::Calendar& cal = QuantLib::NullCalendar(), const bool enforceFutureIndex = true);
172
173//! Convert std::string (GENERIC-...) to QuantExt::Index
174/*!
175 \ingroup utilities
176*/
177QuantLib::ext::shared_ptr<QuantLib::Index> parseGenericIndex(const string& s);
178
179//! Convert std::string to QuantLib::Index
180/*!
181 \ingroup utilities
182*/
183QuantLib::ext::shared_ptr<Index> parseIndex(const string& s);
184
185//! Return true if the \p indexName is that of an overnight index, otherwise false
186/*! \ingroup utilities
187 */
188bool isOvernightIndex(const std::string& indexName);
189
190//! Return true if the \p indexName is that of an bma/sifma index, otherwise false
191/*! \ingroup utilities
192 */
193bool isBmaIndex(const std::string& indexName);
194
195/*! In some cases, we allow multiple external ibor index names to represent the same QuantLib index. This function
196 returns the unique index name that we use internally to represent the QuantLib index.
197
198 For example, we allow:
199 - \c USD-FedFunds-1D and \c USD-FedFunds externally but we use \c USD-FedFunds internally
200 - \c CAD-BA-tenor and \c CAD-CDOR-tenor externally but we use \c CAD-CDOR-tenor internally
201
202 \ingroup utilities
203*/
204std::string internalIndexName(const std::string& indexName);
205
206/*! Check if index is an fx index */
207bool isFxIndex(const std::string& indexName);
208
209/*! Invert an fx index */
210std::string inverseFxIndex(const std::string& indexName);
211
212} // namespace data
213} // namespace ore
QuantLib::ext::shared_ptr< ZeroInflationIndex > parseZeroInflationIndex(const string &s, const Handle< ZeroInflationTermStructure > &h)
Convert std::string to QuantLib::ZeroInflationIndex.
QuantLib::ext::shared_ptr< SwapIndex > parseSwapIndex(const string &s, const Handle< YieldTermStructure > &f, const Handle< YieldTermStructure > &d)
Convert std::string to QuantLib::SwapIndex.
bool isEquityIndex(const string &indexName)
Return true if the indexName is that of an EquityIndex, otherwise false.
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
bool isOvernightIndex(const string &indexName)
Return true if the indexName is that of an overnight index, otherwise false.
bool isBmaIndex(const string &indexName)
Return true if the indexName is that of an bma/sifma index, otherwise false.
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > parseEquityIndex(const string &s)
Convert std::string (e.g SP5) to QuantExt::EquityIndex.
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot, const Handle< YieldTermStructure > &sourceYts, const Handle< YieldTermStructure > &targetYts, const bool useConventions)
Convert std::string to QuantExt::FxIndex.
pair< bool, QuantLib::ext::shared_ptr< ZeroInflationIndex > > isInflationIndex(const string &indexName)
bool isCommodityIndex(const string &indexName)
Return true if the indexName is that of an CommodityIndex, otherwise false.
bool tryParseIborIndex(const string &s, QuantLib::ext::shared_ptr< IborIndex > &index)
Try to convert std::string to QuantLib::IborIndex.
string internalIndexName(const string &indexName)
bool isGenericIndex(const string &indexName)
QuantLib::ext::shared_ptr< BondIndex > parseBondIndex(const string &name)
Convert std::string to QuantExt::BondIndex.
bool isGenericIborIndex(const string &indexName)
Return true if the indexName is that of a generic ibor index, otherwise false.
QuantLib::ext::shared_ptr< Index > parseIndex(const string &s)
Convert std::string to QuantLib::Index.
QuantLib::ext::shared_ptr< QuantLib::Index > parseGenericIndex(const string &s)
Convert std::string (GENERIC-...) to QuantExt::Index.
QuantLib::ext::shared_ptr< ConstantMaturityBondIndex > parseConstantMaturityBondIndex(const string &name)
Convert std::string to QuantExt::ConstantMaturityBondIndex.
@ data
Definition: log.hpp:77
bool isFxIndex(const std::string &indexName)
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > parseCommodityIndex(const string &name, bool hasPrefix, const Handle< PriceTermStructure > &ts, const Calendar &cal, const bool enforceFutureIndex)
std::string inverseFxIndex(const std::string &indexName)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string name