QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
exchangeratemanager.hpp
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
25#ifndef quantlib_exchange_rate_manager_hpp
26#define quantlib_exchange_rate_manager_hpp
27
28#include <ql/exchangerate.hpp>
29#include <ql/patterns/singleton.hpp>
30#include <ql/time/date.hpp>
31#include <list>
32#include <map>
33#include <utility>
34
35namespace QuantLib {
36
38
41 class ExchangeRateManager : public Singleton<ExchangeRateManager> {
42 friend class Singleton<ExchangeRateManager>;
43 private:
45 public:
47
53 void add(const ExchangeRate&,
54 const Date& startDate = Date::minDate(),
55 const Date& endDate = Date::maxDate());
65 ExchangeRate lookup(const Currency& source,
66 const Currency& target,
67 Date date = Date(),
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
QL_BIG_INTEGER BigInteger
large integer number
Definition: types.hpp:39
Definition: any.hpp:35
STL namespace.
Entry(ExchangeRate rate, const Date &start, const Date &end)
Date startDate
Date endDate
ExchangeRate rate
Entry()=default