Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxtriangulation.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 marketdata/fxtriangulation.hpp
20 \brief Intelligent FX price repository
21 \ingroup marketdata
22*/
23
24#pragma once
25
27
29
30#include <ql/handle.hpp>
31#include <ql/quote.hpp>
32#include <ql/types.hpp>
33
34#include <vector>
35
36namespace ore {
37namespace data {
38
40public:
41 /*! Set up empty repository */
43
44 /*! Set up fx quote repository with available market quotes ccypair => quote */
45 explicit FXTriangulation(std::map<std::string, QuantLib::Handle<QuantLib::Quote>> quotes);
46
47 /*! Get quote, possibly via triangulation
48 If you need an exact handling of spot lag differences, use getIndex() instead.
49 */
50 QuantLib::Handle<QuantLib::Quote> getQuote(const std::string& pair) const;
51
52 /*! Get fx index, possibly via triangulation. The index name can be of the form FX-TAG-CCY1-CCY2 or also
53 be just a currency pair CCY1CCY2. In the latter case, the fixing source is set to TAG = GENERIC.
54 The fx index requires discount curves from a market. The assumption is that the market provides discount
55 curves consistent with cross-currency discounting under the specified configuration. If the triangulation
56 is not possible or required curves are not available an exception is thrown.
57 */
58 QuantLib::Handle<QuantExt::FxIndex> getIndex(const std::string& indexOrPair, const Market* market,
59 const std::string& configuration) const;
60
61private:
62 /* get path for conversion forCcy => domCcy, throws if such a path does not exist */
63 std::vector<std::string> getPath(const std::string& forCcy, const std::string& domCcy) const;
64
65 /* return quote or inverse quote to convert forCcy => domCcy, there must be an input quote for the pair in either
66 order, otherwise throws */
67 Handle<Quote> getQuote(const std::string& forCcy, const std::string& domCcy) const;
68
69 /* return a string enumerating all quotes as a comma separated list (for error messages) */
70 std::string getAllQuotes() const;
71
72 // the input quotes
73 std::map<std::string, QuantLib::Handle<QuantLib::Quote>> quotes_;
74
75 // caches to improve perfomance
76 mutable std::map<std::string, QuantLib::Handle<QuantLib::Quote>> quoteCache_;
77 mutable std::map<std::pair<std::string, std::string>, QuantLib::Handle<QuantExt::FxIndex>> indexCache_;
78
79 // internal data structure to represent the undirected graph of currencies
80 std::vector<std::string> nodeToCcy_;
81 std::map<std::string, std::size_t> ccyToNode_;
82 std::vector<std::set<std::size_t>> neighbours_;
83};
84
85} // namespace data
86} // namespace ore
QuantLib::Handle< QuantExt::FxIndex > getIndex(const std::string &indexOrPair, const Market *market, const std::string &configuration) const
std::map< std::string, QuantLib::Handle< QuantLib::Quote > > quoteCache_
std::map< std::pair< std::string, std::string >, QuantLib::Handle< QuantExt::FxIndex > > indexCache_
std::string getAllQuotes() const
FXTriangulation(std::map< std::string, QuantLib::Handle< QuantLib::Quote > > quotes)
std::map< std::string, std::size_t > ccyToNode_
std::vector< std::set< std::size_t > > neighbours_
std::vector< std::string > getPath(const std::string &forCcy, const std::string &domCcy) const
std::map< std::string, QuantLib::Handle< QuantLib::Quote > > quotes_
QuantLib::Handle< QuantLib::Quote > getQuote(const std::string &pair) const
std::vector< std::string > nodeToCcy_
@ data
Definition: log.hpp:77
Base Market class.
Serializable Credit Default Swap.
Definition: namespaces.docs:23