Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxforward.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/event.hpp>
20
22
23using namespace QuantLib;
24
25namespace QuantExt {
26
27FxForward::FxForward(const Real& nominal1, const Currency& currency1, const Real& nominal2, const Currency& currency2,
28 const Date& maturityDate, const bool& payCurrency1, const bool isPhysicallySettled,
29 const Date& payDate, const Currency& payCcy, const Date& fixingDate,
30 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndex,
31 bool includeSettlementDateFlows)
32 : nominal1_(nominal1), currency1_(currency1), nominal2_(nominal2), currency2_(currency2),
33 maturityDate_(maturityDate), payCurrency1_(payCurrency1), isPhysicallySettled_(isPhysicallySettled),
34 payDate_(payDate), payCcy_(payCcy), fxIndex_(fxIndex), fixingDate_(fixingDate),
35 includeSettlementDateFlows_(includeSettlementDateFlows) {
36
37 if (payDate_ == Date())
39
40 if (fixingDate_ == Date())
42
43 if (!isPhysicallySettled && payDate_ > fixingDate_) {
44 QL_REQUIRE(fxIndex_, "FxForward: no FX index given for non-deliverable forward.");
45 QL_REQUIRE(fixingDate_ != Date(), "FxForward: no FX fixing date given for non-deliverable forward.");
46 registerWith(fxIndex_);
47 }
48}
49
50FxForward::FxForward(const Money& nominal1, const ExchangeRate& forwardRate, const Date& maturityDate,
51 bool sellingNominal, const bool isPhysicallySettled, const Date& payDate, const Currency& payCcy,
52 const Date& fixingDate, const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndex,
53 bool includeSettlementDateFlows)
54 : nominal1_(nominal1.value()), currency1_(nominal1.currency()), maturityDate_(maturityDate),
55 payCurrency1_(sellingNominal), isPhysicallySettled_(isPhysicallySettled), payDate_(payDate), payCcy_(payCcy),
56 fxIndex_(fxIndex), fixingDate_(fixingDate), includeSettlementDateFlows_(includeSettlementDateFlows) {
57
58 QL_REQUIRE(currency1_ == forwardRate.target(), "Currency of nominal1 does not match target (domestic) "
59 "currency in the exchange rate.");
60
61 Money otherNominal = forwardRate.exchange(nominal1);
62 nominal2_ = otherNominal.value();
63 currency2_ = otherNominal.currency();
64
65 if (payDate_ == Date())
67
68 if (fixingDate_ == Date())
70
71 if (!isPhysicallySettled && payDate_ > fixingDate_) {
72 QL_REQUIRE(fxIndex_, "FxForward: no FX index given for non-deliverable forward.");
73 QL_REQUIRE(fixingDate_ != Date(), "FxForward: no FX fixing date given for non-deliverable forward.");
74 registerWith(fxIndex_);
75 }
76}
77
78FxForward::FxForward(const Money& nominal1, const Handle<Quote>& fxForwardQuote, const Currency& currency2,
79 const Date& maturityDate, bool sellingNominal, const bool isPhysicallySettled, const Date& payDate,
80 const Currency& payCcy, const Date& fixingDate,
81 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndex,
82 bool includeSettlementDateFlows)
83 : nominal1_(nominal1.value()), currency1_(nominal1.currency()), currency2_(currency2), maturityDate_(maturityDate),
84 payCurrency1_(sellingNominal), isPhysicallySettled_(isPhysicallySettled), payDate_(payDate), payCcy_(payCcy),
85 fxIndex_(fxIndex), fixingDate_(fixingDate), includeSettlementDateFlows_(includeSettlementDateFlows) {
86
87 QL_REQUIRE(fxForwardQuote->isValid(), "The FX Forward quote is not valid.");
88
89 nominal2_ = nominal1_ / fxForwardQuote->value();
90
91 if (payDate_ == Date())
93
94 if (fixingDate_ == Date())
96
97 if (!isPhysicallySettled && payDate_ > fixingDate_) {
98 QL_REQUIRE(fxIndex_, "FxForward: no FX index given for non-deliverable forward.");
99 QL_REQUIRE(fixingDate_ != Date(), "FxForward: no FX fixing date given for non-deliverable forward.");
100 registerWith(fxIndex_);
101 }
102}
103
105 Date p = includeSettlementDateFlows_ ? payDate_ + 1*Days : payDate_;
106 return detail::simple_event(p).hasOccurred();
107}
108
110 Instrument::setupExpired();
111 npv_ = Money(0.0, Currency());
112 fairForwardRate_ = ExchangeRate();
113}
114
116
118
119 QL_REQUIRE(arguments, "wrong argument type in fxforward");
120
133}
134
135void FxForward::fetchResults(const PricingEngine::results* r) const {
136
137 Instrument::fetchResults(r);
138
139 const FxForward::results* results = dynamic_cast<const FxForward::results*>(r);
140
141 QL_REQUIRE(results, "wrong result type");
142
143 npv_ = results->npv;
145}
146
148 QL_REQUIRE(nominal1 >= 0.0, "nominal1 should be non-negative: " << nominal1);
149 QL_REQUIRE(nominal2 >= 0.0, "nominal2 should be non-negative: " << nominal2);
150}
151
153
154 Instrument::results::reset();
155
156 npv = Money(0.0, Currency());
157 fairForwardRate = ExchangeRate();
158}
159} // namespace QuantExt
QuantLib::ext::shared_ptr< FxIndex > fxIndex
Definition: fxforward.hpp:206
void validate() const override
Definition: fxforward.cpp:147
ExchangeRate fairForwardRate_
Definition: fxforward.hpp:191
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
Definition: fxforward.hpp:185
void setupArguments(PricingEngine::arguments *) const override
Definition: fxforward.cpp:115
bool isExpired() const override
Definition: fxforward.cpp:104
const ExchangeRate & fairForwardRate() const
Return the fair FX forward rate.
Definition: fxforward.hpp:144
void setupExpired() const override
Definition: fxforward.cpp:109
FxForward(const Real &nominal1, const Currency &currency1, const Real &nominal2, const Currency &currency2, const Date &maturityDate, const bool &payCurrency1, const bool isPhysicallySettled=true, const Date &payDate=Date(), const Currency &payCcy=Currency(), const Date &fixingDate=Date(), const QuantLib::ext::shared_ptr< QuantExt::FxIndex > &fxIndex=nullptr, bool includeSettlementDateFlows=false)
Definition: fxforward.cpp:27
void fetchResults(const PricingEngine::results *) const override
Definition: fxforward.cpp:135
bool includeSettlementDateFlows_
Definition: fxforward.hpp:187
defaultable fxforward instrument