QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
exchangeratemanager.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004, 2005 StatPro Italia srl
5 Copyright (C) 2004 Decillion Pty(Ltd)
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file exchangeratemanager.hpp
22 \brief exchange-rate repository
23*/
24
25#ifndef quantlib_exchange_rate_manager_hpp
26#define quantlib_exchange_rate_manager_hpp
27
28#include <ql/exchangerate.hpp>
30#include <ql/time/date.hpp>
31#include <list>
32#include <map>
33#include <utility>
34
35namespace QuantLib {
36
37 //! exchange-rate repository
38 /*! \test lookup of direct, triangulated, and derived exchange
39 rates is tested.
40 */
41 class ExchangeRateManager : public Singleton<ExchangeRateManager> {
42 friend class Singleton<ExchangeRateManager>;
43 private:
45 public:
46 //! Add an exchange rate.
47 /*! The given rate is valid between the given dates.
48
49 \note If two rates are given between the same currencies
50 and with overlapping date ranges, the latest one
51 added takes precedence during lookup.
52 */
53 void add(const ExchangeRate&,
54 const Date& startDate = Date::minDate(),
55 const Date& endDate = Date::maxDate());
56 /*! Lookup the exchange rate between two currencies at a given
57 date. If the given type is Direct, only direct exchange
58 rates will be returned if available; if Derived, direct
59 rates are still preferred but derived rates are allowed.
60
61 \warning if two or more exchange-rate chains are possible
62 which allow to specify a requested rate, it is
63 unspecified which one is returned.
64 */
65 ExchangeRate lookup(const Currency& source,
66 const Currency& target,
67 Date date = Date(),
70 //! remove the added exchange rates
71 void clear();
72
73 struct Entry {
74 Entry() = default;
75 Entry(ExchangeRate rate, const Date& start, const Date& end)
76 : rate(std::move(rate)), startDate(start), endDate(end) {}
79 };
80 private:
81 typedef BigInteger Key;
82 mutable std::map<Key, std::list<Entry> > data_;
83 Key hash(const Currency&, const Currency&) const;
84 bool hashes(Key, const Currency&) const;
85 void addKnownRates();
87 const Currency& target,
88 const Date& date) const;
89 ExchangeRate smartLookup(const Currency& source,
90 const Currency& target,
91 const Date& date,
92 std::list<Integer> forbiddenCodes
93 = std::list<Integer>()) const;
94 const ExchangeRate* fetch(const Currency& source,
95 const Currency& target,
96 const Date& date) const;
97 };
98
99}
100
101
102#endif
Currency specification
Definition: currency.hpp:36
Concrete date class.
Definition: date.hpp:125
static Date minDate()
earliest allowed date
Definition: date.cpp:766
static Date maxDate()
latest allowed date
Definition: date.cpp:771
exchange rate between two currencies
void add(const ExchangeRate &, const Date &startDate=Date::minDate(), const Date &endDate=Date::maxDate())
Add an exchange rate.
ExchangeRate lookup(const Currency &source, const Currency &target, Date date=Date(), ExchangeRate::Type type=ExchangeRate::Derived) const
ExchangeRate smartLookup(const Currency &source, const Currency &target, const Date &date, std::list< Integer > forbiddenCodes=std::list< Integer >()) const
std::map< Key, std::list< Entry > > data_
ExchangeRate directLookup(const Currency &source, const Currency &target, const Date &date) const
bool hashes(Key, const Currency &) const
Key hash(const Currency &, const Currency &) const
void clear()
remove the added exchange rates
const ExchangeRate * fetch(const Currency &source, const Currency &target, const Date &date) const
Basic support for the singleton pattern.
Definition: singleton.hpp:58
date- and time-related classes, typedefs and enumerations
exchange rate between two currencies
QL_BIG_INTEGER BigInteger
large integer number
Definition: types.hpp:39
Definition: any.hpp:35
STL namespace.
basic support for the singleton pattern
Entry(ExchangeRate rate, const Date &start, const Date &end)
Date startDate
Date endDate
ExchangeRate rate
Entry()=default