Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxlinkedcashflow.cpp
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#include <ql/indexes/indexmanager.hpp>
21
22namespace QuantExt {
23
24FXLinked::FXLinked(const Date& fxFixingDate, Real foreignAmount, QuantLib::ext::shared_ptr<FxIndex> fxIndex)
25 : fxFixingDate_(fxFixingDate), foreignAmount_(foreignAmount), fxIndex_(fxIndex) {}
26
27AverageFXLinked::AverageFXLinked(const std::vector<Date>& fxFixingDates, Real foreignAmount,
28 QuantLib::ext::shared_ptr<FxIndex> fxIndex, const bool inverted)
29 : fxFixingDates_(fxFixingDates), foreignAmount_(foreignAmount), fxIndex_(fxIndex), inverted_(inverted) {}
30
31Real FXLinked::fxRate() const {
32 return fxIndex_->fixing(fxFixingDate_);
33}
34
36 Real fx = 0;
37 for (auto const& d: fxFixingDates_)
38 fx += inverted_ ? 1.0 / fxIndex_->fixing(d) : fxIndex_->fixing(d);
39 fx /= fxFixingDates_.size();
40 return inverted_ ? 1.0 / fx : fx;
41}
42
43FXLinkedCashFlow::FXLinkedCashFlow(const Date& cashFlowDate, const Date& fxFixingDate, Real foreignAmount,
44 QuantLib::ext::shared_ptr<FxIndex> fxIndex)
45 : FXLinked(fxFixingDate, foreignAmount, fxIndex), cashFlowDate_(cashFlowDate) {
46 registerWith(FXLinked::fxIndex());
47}
48
49AverageFXLinkedCashFlow::AverageFXLinkedCashFlow(const Date& cashFlowDate, const std::vector<Date>& fxFixingDates,
50 Real foreignAmount, QuantLib::ext::shared_ptr<FxIndex> fxIndex,
51 const bool inverted)
52 : AverageFXLinked(fxFixingDates, foreignAmount, fxIndex, inverted), cashFlowDate_(cashFlowDate) {
53 registerWith(AverageFXLinked::fxIndex());
54}
55
56QuantLib::ext::shared_ptr<FXLinked> FXLinkedCashFlow::clone(QuantLib::ext::shared_ptr<FxIndex> fxIndex) {
57 return QuantLib::ext::make_shared<FXLinkedCashFlow>(date(), fxFixingDate(), foreignAmount(), fxIndex);
58}
59
60QuantLib::ext::shared_ptr<AverageFXLinked> AverageFXLinkedCashFlow::clone(QuantLib::ext::shared_ptr<FxIndex> fxIndex) {
61 return QuantLib::ext::make_shared<AverageFXLinkedCashFlow>(date(), fxFixingDates(), foreignAmount(), fxIndex);
62}
63
64std::map<Date, Real> AverageFXLinkedCashFlow::fixings() const {
65 std::map<Date, Real> result;
66 for (auto const& d : fxFixingDates_)
67 result[d] = inverted_ ? 1.0 / fxIndex_->fixing(d) : fxIndex_->fixing(d);
68 return result;
69}
70
71} // namespace QuantExt
QuantLib::ext::shared_ptr< AverageFXLinked > clone(QuantLib::ext::shared_ptr< FxIndex > fxIndex) override
std::map< Date, Real > fixings() const
AverageFXLinkedCashFlow(const Date &cashFlowDate, const std::vector< Date > &fixingDates, Real foreignAmount, QuantLib::ext::shared_ptr< FxIndex > fxIndex, const bool inverted=false)
std::vector< Date > fxFixingDates_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
const std::vector< Date > & fxFixingDates() const
AverageFXLinked(const std::vector< Date > &fixingDates, Real foreignAmount, QuantLib::ext::shared_ptr< FxIndex > fxIndex, const bool inverted=false)
QuantLib::ext::shared_ptr< FXLinked > clone(QuantLib::ext::shared_ptr< FxIndex > fxIndex) override
FXLinkedCashFlow(const Date &cashFlowDate, const Date &fixingDate, Real foreignAmount, QuantLib::ext::shared_ptr< FxIndex > fxIndex)
Date date() const override
Base class for FX Linked cashflows.
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
FXLinked(const Date &fixingDate, Real foreignAmount, QuantLib::ext::shared_ptr< FxIndex > fxIndex)
Real foreignAmount() const
Date fxFixingDate() const
An FX linked cashflow.