Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
representativefxoption.cpp File Reference
#include <qle/models/representativefxoption.hpp>
#include <oret/toplevelfixture.hpp>
#include <qle/cashflows/floatingratefxlinkednotionalcoupon.hpp>
#include <qle/indexes/fxindex.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/cashflows/iborcoupon.hpp>
#include <ql/cashflows/simplecashflow.hpp>
#include <ql/currencies/america.hpp>
#include <ql/currencies/europe.hpp>
#include <ql/indexes/iborindex.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/time/daycounters/actual365fixed.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testSimpleCashflows)
 
 BOOST_AUTO_TEST_CASE (testFxLinkedCashflow)
 
 BOOST_AUTO_TEST_CASE (testFxLinkedFloatingRateCoupon)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( testSimpleCashflows  )

Definition at line 59 of file representativefxoption.cpp.

59 {
60
61 BOOST_TEST_MESSAGE("test reproducing simple cashflows");
62
63 Real tol = 1E-12, tol2 = 1E-10;
64
65 Date refDate = today + 5 * Years;
66
67 Real eurAmount = 35000.0;
68 Real usdAmount = 14222.0;
69 Leg eurLeg = {QuantLib::ext::make_shared<SimpleCashFlow>(eurAmount, refDate)};
70 Leg usdLeg = {QuantLib::ext::make_shared<SimpleCashFlow>(usdAmount, refDate)};
71
72 RepresentativeFxOptionMatcher matcher1({eurLeg, usdLeg}, {true, false}, {"EUR", "USD"}, refDate, "EUR", "USD",
73 eurCurve, usdCurve, eurUsdSpot, true);
74
75 BOOST_CHECK_EQUAL(matcher1.currency1(), "EUR");
76 BOOST_CHECK_EQUAL(matcher1.currency2(), "USD");
77 BOOST_CHECK_CLOSE(matcher1.amount1(), -eurAmount, tol);
78 BOOST_CHECK_CLOSE(matcher1.amount2(), usdAmount, tol);
79
80 RepresentativeFxOptionMatcher matcher2({eurLeg, usdLeg}, {false, true}, {"EUR", "USD"}, refDate, "EUR", "USD",
81 eurCurve, usdCurve, eurUsdSpot, true);
82
83 BOOST_CHECK_EQUAL(matcher2.currency1(), "EUR");
84 BOOST_CHECK_EQUAL(matcher2.currency2(), "USD");
85 BOOST_CHECK_CLOSE(matcher2.amount1(), eurAmount, tol);
86 BOOST_CHECK_CLOSE(matcher2.amount2(), -usdAmount, tol);
87
88 RepresentativeFxOptionMatcher matcher3({eurLeg, usdLeg}, {false, false}, {"EUR", "USD"}, refDate, "EUR", "USD",
89 eurCurve, usdCurve, eurUsdSpot, true);
90
91 BOOST_CHECK_EQUAL(matcher3.currency1(), "EUR");
92 BOOST_CHECK_EQUAL(matcher3.currency2(), "USD");
93 BOOST_CHECK_CLOSE(matcher3.amount1(), eurAmount, tol);
94 BOOST_CHECK_CLOSE(matcher3.amount2(), usdAmount, tol);
95
96 RepresentativeFxOptionMatcher matcher4({eurLeg, usdLeg}, {true, true}, {"EUR", "USD"}, refDate, "EUR", "USD",
97 eurCurve, usdCurve, eurUsdSpot, true);
98
99 BOOST_CHECK_EQUAL(matcher4.currency1(), "EUR");
100 BOOST_CHECK_EQUAL(matcher4.currency2(), "USD");
101 BOOST_CHECK_CLOSE(matcher4.amount1(), -eurAmount, tol);
102 BOOST_CHECK_CLOSE(matcher4.amount2(), -usdAmount, tol);
103
104 RepresentativeFxOptionMatcher matcher5({eurLeg}, {true}, {"EUR"}, refDate, "EUR", "USD", eurCurve, usdCurve,
105 eurUsdSpot, true);
106
107 BOOST_CHECK_EQUAL(matcher5.currency1(), "EUR");
108 BOOST_CHECK_EQUAL(matcher5.currency2(), "USD");
109 BOOST_CHECK_CLOSE(matcher5.amount1(), -eurAmount, tol);
110 BOOST_CHECK_SMALL(matcher5.amount2(), tol2);
111
112 RepresentativeFxOptionMatcher matcher6({}, {}, {}, refDate, "EUR", "USD", eurCurve, usdCurve, eurUsdSpot, true);
113
114 BOOST_CHECK_EQUAL(matcher6.currency1(), "EUR");
115 BOOST_CHECK_EQUAL(matcher6.currency2(), "USD");
116 BOOST_CHECK_SMALL(matcher6.amount1(), tol2);
117 BOOST_CHECK_SMALL(matcher6.amount2(), tol2);
118}

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( testFxLinkedCashflow  )

Definition at line 120 of file representativefxoption.cpp.

120 {
121
122 BOOST_TEST_MESSAGE("test fx linked cashflow");
123
124 Real tol = 1E-12;
125
126 Date refDate = today + 5 * Years;
127 Date fixDate = UnitedStates(UnitedStates::Settlement).advance(refDate, -2 * Days);
128
129 auto fxSpotScen = QuantLib::ext::make_shared<SimpleQuote>(eurUsdSpot->value());
130 auto fxIndex = QuantLib::ext::make_shared<FxIndex>("dummy", 2, EURCurrency(), USDCurrency(), UnitedStates(UnitedStates::Settlement),
131 Handle<Quote>(fxSpotScen), eurCurve, usdCurve);
132 Real forAmount = 100000.0;
133
134 Leg leg = {QuantLib::ext::make_shared<FXLinkedCashFlow>(refDate, fixDate, forAmount, fxIndex)};
135
136 RepresentativeFxOptionMatcher matcher({leg}, {false}, {"USD"}, today, "EUR", "USD", eurCurve, usdCurve, eurUsdSpot);
137
138 BOOST_CHECK_EQUAL(matcher.currency1(), "EUR");
139 BOOST_CHECK_EQUAL(matcher.currency2(), "USD");
140
141 Real eurAmount = matcher.amount1();
142 Real usdAmount = matcher.amount2();
143
144 // check npv matches
145
146 BOOST_CHECK_CLOSE(eurAmount * eurUsdSpot->value() + usdAmount, leg.front()->amount() * usdCurve->discount(refDate),
147 tol);
148
149 // check fx delta matches
150
151 fxSpotScen->setValue(eurUsdSpot->value() * 1.01);
152 Real upNpv = leg.front()->amount() * usdCurve->discount(refDate);
153
154 fxSpotScen->setValue(eurUsdSpot->value() * 0.99);
155 Real downNpv = leg.front()->amount() * usdCurve->discount(refDate);
156
157 BOOST_CHECK_CLOSE(eurAmount, (upNpv - downNpv) / (eurUsdSpot->value() * 0.02), tol);
158}

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( testFxLinkedFloatingRateCoupon  )

Definition at line 160 of file representativefxoption.cpp.

160 {
161
162 BOOST_TEST_MESSAGE("test fx linked floating rate coupon");
163
164 Real tol = 1E-12;
165
166 Date refDate = today + 5 * Years;
167 Date fixDate = UnitedStates(UnitedStates::Settlement).advance(refDate, -2 * Days);
168
169 auto fxSpotScen = QuantLib::ext::make_shared<SimpleQuote>(eurUsdSpot->value());
170 auto fxIndex = QuantLib::ext::make_shared<FxIndex>("dummy", 2, EURCurrency(), USDCurrency(), UnitedStates(UnitedStates::Settlement),
171 Handle<Quote>(fxSpotScen), eurCurve, usdCurve);
172 Real forAmount = 100000.0;
173
174 auto iborIndex = QuantLib::ext::make_shared<IborIndex>("dummyIbor", 6 * Months, 2, EURCurrency(), TARGET(), Following,
175 false, Actual360(), eurCurve);
176 Date start(refDate - 6 * Months), end(refDate);
177 auto iborCoupon = QuantLib::ext::make_shared<IborCoupon>(refDate, 1.0, start, end, 2, iborIndex, 1.0, 0.0);
178 iborCoupon->setPricer(QuantLib::ext::make_shared<BlackIborCouponPricer>());
179
180 Leg leg = {QuantLib::ext::make_shared<FloatingRateFXLinkedNotionalCoupon>(fixDate, forAmount, fxIndex, iborCoupon)};
181
182 RepresentativeFxOptionMatcher matcher({leg}, {false}, {"USD"}, today, "EUR", "USD", eurCurve, usdCurve, eurUsdSpot);
183
184 BOOST_CHECK_EQUAL(matcher.currency1(), "EUR");
185 BOOST_CHECK_EQUAL(matcher.currency2(), "USD");
186
187 Real eurAmount = matcher.amount1();
188 Real usdAmount = matcher.amount2();
189
190 // check npv matches
191
192 BOOST_CHECK_CLOSE(eurAmount * eurUsdSpot->value() + usdAmount, leg.front()->amount() * usdCurve->discount(refDate),
193 tol);
194
195 // check fx delta matches
196
197 fxSpotScen->setValue(eurUsdSpot->value() * 1.01);
198 Real upNpv = leg.front()->amount() * usdCurve->discount(refDate);
199
200 fxSpotScen->setValue(eurUsdSpot->value() * 0.99);
201 Real downNpv = leg.front()->amount() * usdCurve->discount(refDate);
202
203 BOOST_CHECK_CLOSE(eurAmount, (upNpv - downNpv) / (eurUsdSpot->value() * 0.02), tol);
204}