QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
exchangerate.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 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 exchangerate.hpp
22 \brief exchange rate between two currencies
23*/
24
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
34 //! exchange rate between two currencies
35 /*! \test application of direct and derived exchange rate is
36 tested against calculations.
37 */
39 public:
40 enum Type { Direct, /*!< given directly by the user */
41 Derived /*!< derived from exchange rates between
42 other currencies */
43 };
44 //! \name Constructors
45 //@{
47 /*! the rate \f$ r \f$ is given with the convention that a
48 unit of the source is worth \f$ r \f$ units of the target.
49 */
51 //@}
52
53 //! \name Inspectors
54 //@{
55 //! the source currency.
56 const Currency& source() const;
57 //! the target currency.
58 const Currency& target() const;
59 //! the type
60 Type type() const;
61 //! the exchange rate (when available)
62 Decimal rate() const;
63 //@}
64
65 //! \name Utility methods
66 //@{
67 //! apply the exchange rate to a cash amount
68 Money exchange(const Money& amount) const;
69 //! chain two exchange rates
70 static ExchangeRate chain(const ExchangeRate& r1,
71 const ExchangeRate& r2);
72 //@}
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
cash amount in a given currency
Definition: any.hpp:35
STL namespace.
null values
Real target_