QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
exchangerate.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 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_hpp
26#define quantlib_exchange_rate_hpp
27
28#include <ql/money.hpp>
29#include <ql/utilities/null.hpp>
30#include <utility>
31
32namespace QuantLib {
33
35
39 public:
40 enum Type { Direct,
41 Derived
43 };
45
52
54
55
56 const Currency& source() const;
58 const Currency& target() const;
60 Type type() const;
62 Decimal rate() const;
64
66
67
68 Money exchange(const Money& amount) const;
70 static ExchangeRate chain(const ExchangeRate& r1,
71 const ExchangeRate& r2);
73 private:
77 std::pair<ext::shared_ptr<ExchangeRate>,
78 ext::shared_ptr<ExchangeRate> > rateChain_;
79 };
80
81
82 // inline definitions
83
84 inline ExchangeRate::ExchangeRate() : rate_(Null<Decimal>()), type_(Direct) {}
85
87 : source_(std::move(source)), target_(std::move(target)), rate_(rate), type_(Direct) {}
88
89 inline const Currency& ExchangeRate::source() const {
90 return source_;
91 }
92
93 inline const Currency& ExchangeRate::target() const {
94 return target_;
95 }
96
98 return type_;
99 }
100
102 return rate_;
103 }
104
105}
106
107
108#endif
Currency specification
Definition: currency.hpp:36
exchange rate between two currencies
const Currency & target() const
the target currency.
std::pair< ext::shared_ptr< ExchangeRate >, ext::shared_ptr< ExchangeRate > > rateChain_
Decimal rate() const
the exchange rate (when available)
static ExchangeRate chain(const ExchangeRate &r1, const ExchangeRate &r2)
chain two exchange rates
const Currency & source() const
the source currency.
Money exchange(const Money &amount) const
apply the exchange rate to a cash amount
Type type() const
the type
amount of cash
Definition: money.hpp:38
template class providing a null value for a given type.
Definition: null.hpp:76
Real Decimal
decimal number
Definition: types.hpp:54
Definition: any.hpp:35
STL namespace.