Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxindex.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2015 Peter Caspers
3 This file is part of QuantLib, a free-software/open-source library
4 for financial quantitative analysts and developers - http://quantlib.org/
5 QuantLib is free software: you can redistribute it and/or modify it
6 under the terms of the QuantLib license. You should have received a
7 copy of the license along with this program.
8 <quantlib-dev@lists.sf.net>. The license is also available online at
9 <http://quantlib.org/license.shtml>.
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the license for more details.
13*/
14
15/*
16 Copyright (C) 2016 Quaternion Risk Management Ltd
17 All rights reserved.
18
19 This file is part of ORE, a free-software/open-source library
20 for transparent pricing and risk analysis - http://opensourcerisk.org
21
22 ORE is free software: you can redistribute it and/or modify it
23 under the terms of the Modified BSD License. You should have received a
24 copy of the license along with this program.
25 The license is also available online at <http://opensourcerisk.org>
26
27 This program is distributed on the basis that it will form a useful
28 contribution to risk analytics and model standardisation, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
31*/
32
33/*! \file fxindex.hpp
34 \brief FX index class
35 \ingroup indexes
36*/
37
38#ifndef quantext_fxindex_hpp
39#define quantext_fxindex_hpp
40
41#include <ql/currency.hpp>
42#include <ql/exchangerate.hpp>
43#include <ql/handle.hpp>
44#include <ql/termstructures/yieldtermstructure.hpp>
45#include <ql/time/calendar.hpp>
47
48namespace QuantExt {
49using namespace QuantLib;
50
51class FxRateQuote : public Quote, public Observer {
52public:
53 //! if sourceYts, targetYts are not given, the non-discounted spot quote will be returned as a fallback
54 FxRateQuote(Handle<Quote> spotQuote, const Handle<YieldTermStructure>& sourceYts,
55 const Handle<YieldTermStructure>& targetYts, Natural fixingDays, const Calendar& fixingCalendar);
56 //! \name Quote interface
57 //@{
58 Real value() const override;
59 bool isValid() const override;
60 //@}
61 //! \name Observer interface
62 //@{
63 void update() override;
64 //@}
65private:
66 const Handle<Quote> spotQuote_;
67 const Handle<YieldTermStructure> sourceYts_, targetYts_;
68 Natural fixingDays_;
70};
71
72class FxSpotQuote : public Quote, public Observer {
73public:
74 FxSpotQuote(Handle<Quote> todaysQuote, const Handle<YieldTermStructure>& sourceYts,
75 const Handle<YieldTermStructure>& targetYts, Natural fixingDays, const Calendar& fixingCalendar);
76 //! \name Quote interface
77 //@{
78 Real value() const override;
79 bool isValid() const override;
80 //@}
81 //! \name Observer interface
82 //@{
83 void update() override;
84 //@}
85private:
86 const Handle<Quote> todaysQuote_;
87 const Handle<YieldTermStructure> sourceYts_, targetYts_;
88 Natural fixingDays_;
90};
91
92//! FX Index
93/*! \ingroup indexes */
94class FxIndex : public EqFxIndexBase {
95public:
96 /*! familyName may be e.g. ECB
97 fixingDays determine the spot date of the currency pair
98 source is the asset or foreign currency
99 target is the numeraire or domestic currency
100 fixingCalendar is the calendar defining good days for the pair
101 this class uses the exchange rate manager to retrieve spot values
102 fxSpot is the fx rate settled at today + fixingDays */
103 FxIndex(const std::string& familyName, Natural fixingDays, const Currency& source, const Currency& target,
104 const Calendar& fixingCalendar, const Handle<YieldTermStructure>& sourceYts = Handle<YieldTermStructure>(),
105 const Handle<YieldTermStructure>& targetYts = Handle<YieldTermStructure>(),
106 bool fixingTriangulation = false);
107 FxIndex(const std::string& familyName, Natural fixingDays, const Currency& source, const Currency& target,
108 const Calendar& fixingCalendar, const Handle<Quote> fxSpot,
109 const Handle<YieldTermStructure>& sourceYts = Handle<YieldTermStructure>(),
110 const Handle<YieldTermStructure>& targetYts = Handle<YieldTermStructure>(),
111 bool fixingTriangulation = true);
112 //! \name Index interface
113 //@{
114 std::string name() const override;
115 Calendar fixingCalendar() const override;
116 bool isValidFixingDate(const Date& fixingDate) const override;
117 Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
118 //@}
119 //! \name Observer interface
120 //@{
121 void update() override;
122 //@}
123 //! \name Inspectors
124 //@{
125 std::string familyName() const { return familyName_; }
126 std::string oreName() const { return oreName_; }
127 Natural fixingDays() const { return fixingDays_; }
128 Date fixingDate(const Date& valueDate) const;
129 const Currency& sourceCurrency() const { return sourceCurrency_; }
130 const Currency& targetCurrency() const { return targetCurrency_; }
131 const Handle<YieldTermStructure>& sourceCurve() const { return sourceYts_; }
132 const Handle<YieldTermStructure>& targetCurve() const { return targetYts_; }
133
134 //! fxQuote returns instantaneous Quote by default, otherwise settlement after fixingDays
135 const Handle<Quote> fxQuote(bool withSettlementLag = false) const;
136 const bool useQuote() const { return useQuote_; }
137 //@}
138 /*! \name Date calculations */
139 virtual Date valueDate(const Date& fixingDate) const;
140 //! \name Fixing calculations
141 //@{
142 //! It can be overridden to implement particular conventions
143 virtual Real forecastFixing(const Time& fixingTime) const override;
144 virtual Real forecastFixing(const Date& fixingDate) const;
145 Real pastFixing(const Date& fixingDate) const override;
146 // @}
147
148 //! clone the index, the clone will be linked to the provided handles
149 QuantLib::ext::shared_ptr<FxIndex> clone(const Handle<Quote> fxQuote = Handle<Quote>(),
150 const Handle<YieldTermStructure>& sourceYts = Handle<YieldTermStructure>(),
151 const Handle<YieldTermStructure>& targetYts = Handle<YieldTermStructure>(),
152 const std::string& familyName = std::string());
153
154protected:
155 std::string familyName_, oreName_;
156 Natural fixingDays_;
158 const Handle<YieldTermStructure> sourceYts_, targetYts_;
159 std::string name_;
160 // Spot as quoted in market
161 const Handle<Quote> fxSpot_;
162 // instantaneous fx rate
163 mutable Handle<Quote> fxRate_;
165
166private:
169
170 void initialise();
171};
172
173} // namespace QuantExt
174
175#endif
FX Index.
Definition: fxindex.hpp:94
Handle< Quote > fxRate_
Definition: fxindex.hpp:163
const Handle< Quote > fxQuote(bool withSettlementLag=false) const
fxQuote returns instantaneous Quote by default, otherwise settlement after fixingDays
Definition: fxindex.cpp:135
const bool useQuote() const
Definition: fxindex.hpp:136
QuantLib::ext::shared_ptr< FxIndex > clone(const Handle< Quote > fxQuote=Handle< Quote >(), const Handle< YieldTermStructure > &sourceYts=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &targetYts=Handle< YieldTermStructure >(), const std::string &familyName=std::string())
clone the index, the clone will be linked to the provided handles
Definition: fxindex.cpp:257
virtual Real forecastFixing(const Time &fixingTime) const override
It can be overridden to implement particular conventions.
Definition: fxindex.cpp:190
Natural fixingDays() const
Definition: fxindex.hpp:127
const Currency & sourceCurrency() const
Definition: fxindex.hpp:129
void update() override
Definition: fxindex.cpp:273
std::string oreName_
Definition: fxindex.hpp:155
Calendar fixingCalendar() const override
Definition: fxindex.cpp:269
std::string name_
Definition: fxindex.hpp:159
const Handle< Quote > fxSpot_
Definition: fxindex.hpp:161
Currency sourceCurrency_
Definition: fxindex.hpp:157
const Handle< YieldTermStructure > & sourceCurve() const
Definition: fxindex.hpp:131
bool fixingTriangulation_
Definition: fxindex.hpp:168
const Handle< YieldTermStructure > & targetCurve() const
Definition: fxindex.hpp:132
Natural fixingDays_
Definition: fxindex.hpp:156
std::string oreName() const
Definition: fxindex.hpp:126
const Handle< YieldTermStructure > targetYts_
Definition: fxindex.hpp:158
std::string name() const override
Definition: fxindex.cpp:267
virtual Date valueDate(const Date &fixingDate) const
Definition: fxindex.cpp:283
std::string familyName_
Definition: fxindex.hpp:155
bool isValidFixingDate(const Date &fixingDate) const override
Definition: fxindex.cpp:271
const Currency & targetCurrency() const
Definition: fxindex.hpp:130
const Handle< YieldTermStructure > sourceYts_
Definition: fxindex.hpp:158
Currency targetCurrency_
Definition: fxindex.hpp:157
Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
Definition: fxindex.cpp:290
Calendar fixingCalendar_
Definition: fxindex.hpp:167
Date fixingDate(const Date &valueDate) const
Definition: fxindex.cpp:278
std::string familyName() const
Definition: fxindex.hpp:125
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
Definition: fxindex.cpp:158
void update() override
Definition: fxindex.cpp:70
const Handle< Quote > spotQuote_
Definition: fxindex.hpp:66
const Handle< YieldTermStructure > targetYts_
Definition: fxindex.hpp:67
const Handle< YieldTermStructure > sourceYts_
Definition: fxindex.hpp:67
Real value() const override
Definition: fxindex.cpp:55
Calendar fixingCalendar_
Definition: fxindex.hpp:69
bool isValid() const override
Definition: fxindex.cpp:68
void update() override
Definition: fxindex.cpp:99
const Handle< YieldTermStructure > targetYts_
Definition: fxindex.hpp:87
const Handle< Quote > todaysQuote_
Definition: fxindex.hpp:86
const Handle< YieldTermStructure > sourceYts_
Definition: fxindex.hpp:87
Real value() const override
Definition: fxindex.cpp:82
Calendar fixingCalendar_
Definition: fxindex.hpp:89
bool isValid() const override
Definition: fxindex.cpp:95
A common base class for the FX and Equity Indices. Provides a forecast fixing method for time so the ...