Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxlinkedcashflow.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/cashflows/fxlinkedcashflow.hpp
20 \brief An FX linked cashflow
21
22 \ingroup cashflows
23*/
24
25#ifndef quantext_fx_linked_cashflow_hpp
26#define quantext_fx_linked_cashflow_hpp
27
28#include <ql/cashflow.hpp>
29#include <ql/handle.hpp>
30#include <ql/patterns/visitor.hpp>
31#include <ql/quote.hpp>
32#include <ql/time/date.hpp>
34
35namespace QuantExt {
36using namespace QuantLib;
37
38//! Base class for FX Linked cashflows
39class FXLinked {
40public:
41 FXLinked(const Date& fixingDate, Real foreignAmount, QuantLib::ext::shared_ptr<FxIndex> fxIndex);
42 virtual ~FXLinked() {}
43 Date fxFixingDate() const { return fxFixingDate_; }
44 Real foreignAmount() const { return foreignAmount_; }
45 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex() const { return fxIndex_; }
46 Real fxRate() const;
47
48 virtual QuantLib::ext::shared_ptr<FXLinked> clone(QuantLib::ext::shared_ptr<FxIndex> fxIndex) = 0;
49
50protected:
53 QuantLib::ext::shared_ptr<FxIndex> fxIndex_;
54};
55
57public:
58 // if inverted = true, the arithmetic averaging is done over the inverted fixings and the reciprocal of the result
59 // is taken to compute the rate
60 AverageFXLinked(const std::vector<Date>& fixingDates, Real foreignAmount, QuantLib::ext::shared_ptr<FxIndex> fxIndex,
61 const bool inverted = false);
62 virtual ~AverageFXLinked() {}
63 const std::vector<Date>& fxFixingDates() const { return fxFixingDates_; }
64 Real foreignAmount() const { return foreignAmount_; }
65 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex() const { return fxIndex_; }
66 Real fxRate() const;
67
68 virtual QuantLib::ext::shared_ptr<AverageFXLinked> clone(QuantLib::ext::shared_ptr<FxIndex> fxIndex) = 0;
69
70protected:
71 std::vector<Date> fxFixingDates_;
73 QuantLib::ext::shared_ptr<FxIndex> fxIndex_;
74 bool inverted_ = false;
75};
76
77//! FX Linked cash-flow
78/*!
79 * Cashflow of Domestic currency where the amount is fx linked
80 * to some fixed foreign amount.
81 *
82 * For example: a JPY flow based off 1M USD, if the USDJPY FX rate
83 * is 123.45 then the JPY amount is 123.45 M JPY.
84 *
85 * FXLinkedCashFlow checks the FX fixing date against the eval date
86 *
87 * For future fixings (date > eval) this class calculates the FX Fwd
88 * rate (using the provided FX Spot rate and FOR and DOM yield curves)
89 *
90 * For todays fixing (date = eval) this class converts the foreign
91 * amount using the provided FX Spot rate.
92 *
93 * For previous fixings (date < eval) this class checks the QuantLib
94 * IndexManager to get the FX fixing at which the foreign rate should be
95 * converted at. The name of the index is a parameter to the constructor.
96 *
97 * This is not a lazy object.
98
99 \ingroup cashflows
100 */
101class FXLinkedCashFlow : public CashFlow, public FXLinked, public Observer {
102public:
103 FXLinkedCashFlow(const Date& cashFlowDate, const Date& fixingDate, Real foreignAmount,
104 QuantLib::ext::shared_ptr<FxIndex> fxIndex);
105
106 //! \name CashFlow interface
107 //@{
108 Date date() const override { return cashFlowDate_; }
109 Real amount() const override { return foreignAmount() * fxRate(); }
110 //@}
111
112 //! \name Visitability
113 //@{
114 void accept(AcyclicVisitor&) override;
115 //@}
116
117 //! \name Observer interface
118 //@{
119 void update() override { notifyObservers(); }
120 //@}
121
122 //! \name FXLinked interface
123 //@{
124 QuantLib::ext::shared_ptr<FXLinked> clone(QuantLib::ext::shared_ptr<FxIndex> fxIndex) override;
125 //@}
126
127private:
129};
130
131// inline definitions
132
133inline void FXLinkedCashFlow::accept(AcyclicVisitor& v) {
134 Visitor<FXLinkedCashFlow>* v1 = dynamic_cast<Visitor<FXLinkedCashFlow>*>(&v);
135 if (v1 != 0)
136 v1->visit(*this);
137 else
138 CashFlow::accept(v);
139}
140
141//! Average FX Linked cash-flow
142/*!
143 * Cashflow of Domestic currency where the amount is fx linked
144 * to some fixed foreign amount.
145 *
146 * Difference to the FX Linked cash-flow: The FX rate is an
147 * arithmetic average across observation dates.
148 *
149 * This is not a lazy object.
150
151 \ingroup cashflows
152 */
153class AverageFXLinkedCashFlow : public CashFlow, public AverageFXLinked, public Observer {
154public:
155 AverageFXLinkedCashFlow(const Date& cashFlowDate, const std::vector<Date>& fixingDates, Real foreignAmount,
156 QuantLib::ext::shared_ptr<FxIndex> fxIndex, const bool inverted = false);
157
158 //! \name CashFlow interface
159 //@{
160 Date date() const override { return cashFlowDate_; }
161 Real amount() const override { return foreignAmount() * fxRate(); }
162 //@}
163
164 //! \name Visitability
165 //@{
166 void accept(AcyclicVisitor&) override;
167 //@}
168
169 //! \name Observer interface
170 //@{
171 void update() override { notifyObservers(); }
172 //@}
173
174 //! \name FXLinked interface
175 //@{
176 QuantLib::ext::shared_ptr<AverageFXLinked> clone(QuantLib::ext::shared_ptr<FxIndex> fxIndex) override;
177 //@}
178
179 // get single fixing dates and values
180 std::map<Date, Real> fixings() const;
181
182private:
184};
185
186inline void AverageFXLinkedCashFlow::accept(AcyclicVisitor& v) {
187 Visitor<AverageFXLinkedCashFlow>* v1 = dynamic_cast<Visitor<AverageFXLinkedCashFlow>*>(&v);
188 if (v1 != 0)
189 v1->visit(*this);
190 else
191 CashFlow::accept(v);
192}
193} // namespace QuantExt
194
195#endif
Average FX Linked cash-flow.
QuantLib::ext::shared_ptr< AverageFXLinked > clone(QuantLib::ext::shared_ptr< FxIndex > fxIndex) override
std::map< Date, Real > fixings() const
void accept(AcyclicVisitor &) override
std::vector< Date > fxFixingDates_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
virtual QuantLib::ext::shared_ptr< AverageFXLinked > clone(QuantLib::ext::shared_ptr< FxIndex > fxIndex)=0
const std::vector< Date > & fxFixingDates() const
QuantLib::ext::shared_ptr< FXLinked > clone(QuantLib::ext::shared_ptr< FxIndex > fxIndex) override
Real amount() const override
void accept(AcyclicVisitor &) override
Date date() const override
Base class for FX Linked cashflows.
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
virtual QuantLib::ext::shared_ptr< FXLinked > clone(QuantLib::ext::shared_ptr< FxIndex > fxIndex)=0
Real foreignAmount() const
Date fxFixingDate() const
FX index class.