Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
ccyswapwithresets.cpp File Reference
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ored/marketdata/marketimpl.hpp>
#include <ored/portfolio/builders/swap.hpp>
#include <ored/portfolio/enginedata.hpp>
#include <ored/portfolio/portfolio.hpp>
#include <ored/portfolio/swap.hpp>
#include <ored/utilities/indexparser.hpp>
#include <ored/utilities/log.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/termstructures/yield/discountcurve.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actual360.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCcySwapWithResetsPrice)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testCcySwapWithResetsPrice  )

Definition at line 131 of file ccyswapwithresets.cpp.

131 {
132
133 BOOST_TEST_MESSAGE("Testing CcySwapWithResets Price...");
134
135 // Bloomberg CCYswap and CCYswapReset prices (in USD)
136 Real npvCCYswap = -349.69;
137 Real npvCCYswapReset = 0;
138
139 // build market
140 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
141 Settings::instance().evaluationDate() = market->asofDate();
142
143 // test asof date
144 Date today = market->asofDate();
145 BOOST_CHECK_EQUAL(today, Date(22, Aug, 2016));
146
147 // Test if EUR discount curve is empty
148 Handle<YieldTermStructure> dts = market->discountCurve("EUR");
149 QL_REQUIRE(!dts.empty(), "EUR discount curve not found");
150
151 // Test EUR discount(today+3*Years)) against base value
152 BOOST_CHECK_CLOSE(market->discountCurve("EUR")->discount(today + 3 * Years), 1.006005, 0.0001);
153
154 // Test USD discount(today+3*Years)) against base value
155 BOOST_CHECK_CLOSE(market->discountCurve("USD")->discount(today + 3 * Years), 0.96908, 0.0001);
156
157 // Test EURUSD fx spot object against base value
158 BOOST_CHECK_EQUAL(market->fxSpot("EURUSD")->value(), 1.1306);
159
160 // envelope
161 Envelope env("CP");
162
163 // Start/End date
164 Date startDate = today;
165 Date endDate = today + 5 * Years;
166
167 // date 2 string
168 std::ostringstream oss;
169 oss << io::iso_date(startDate);
170 string start(oss.str());
171 oss.str("");
172 oss.clear();
173 oss << io::iso_date(endDate);
174 string end(oss.str());
175
176 // Schedules
177 string conv = "MF";
178 string rule = "Forward";
179 ScheduleData scheduleEUR(ScheduleRules(start, end, "6M", "TARGET", conv, conv, rule));
180 ScheduleData scheduleUSD(ScheduleRules(start, end, "3M", "US", conv, conv, rule));
181
182 // EUR Leg without and with Notional resets
183 bool isPayerEUR = true;
184 string indexEUR = "EUR-EURIBOR-6M";
185 bool isInArrears = false;
186 int days = 2;
187 vector<Real> spreadEUR(1, 0.000261);
188 string dc = "ACT/360";
189 vector<Real> notionalEUR(1, 8833141.95);
190 string paymentConvention = "F";
191 bool notionalInitialXNL = true;
192 bool notionalFinalXNL = true;
193 bool notionalAmortizingXNL = false;
194 string foreignCCY = "USD";
195 Real foreignAmount = 10000000;
196 string fxIndex = "FX-ECB-EUR-USD";
197 auto legdataEUR = QuantLib::ext::make_shared<FloatingLegData>(indexEUR, days, isInArrears, spreadEUR);
198 LegData legEUR1(legdataEUR, isPayerEUR, "EUR", scheduleEUR, dc, notionalEUR, vector<string>(), paymentConvention,
199 notionalInitialXNL, notionalFinalXNL, notionalAmortizingXNL, notionalFinalXNL, foreignCCY,
200 foreignAmount, fxIndex);
201 LegData legEUR2(legdataEUR, isPayerEUR, "EUR", scheduleEUR, dc, notionalEUR, vector<string>(), paymentConvention,
202 notionalInitialXNL, notionalFinalXNL, notionalAmortizingXNL, false, foreignCCY, foreignAmount,
203 fxIndex);
204
205 // USD Leg without notional resets
206 bool isPayerUSD = false;
207 string indexUSD = "USD-LIBOR-3M";
208 vector<Real> spreadUSD(1, 0);
209 vector<Real> notionalUSD(1, 10000000);
210 auto legdataUSD = QuantLib::ext::make_shared<FloatingLegData>(indexUSD, days, isInArrears, spreadUSD);
211 LegData legUSD(legdataUSD, isPayerUSD, "USD", scheduleUSD, dc, notionalUSD, vector<string>(), paymentConvention,
212 notionalInitialXNL, notionalFinalXNL, notionalAmortizingXNL);
213
214 // Build swap trades
215 QuantLib::ext::shared_ptr<Trade> swap1(new ore::data::Swap(env, legUSD, legEUR1));
216 QuantLib::ext::shared_ptr<Trade> swap2(new ore::data::Swap(env, legUSD, legEUR2));
217
218 // engine data and factory
219 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
220 engineData->model("CrossCurrencySwap") = "DiscountedCashflows";
221 engineData->engine("CrossCurrencySwap") = "DiscountingCrossCurrencySwapEngine";
222 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
223
224 // build swaps and portfolio
225 QuantLib::ext::shared_ptr<Portfolio> portfolio(new Portfolio());
226 swap1->id() = "XCCY_Swap_EUR_USD";
227 swap2->id() = "XCCY_Swap_EUR_USD_RESET";
228
229 portfolio->add(swap1);
230 portfolio->add(swap2);
231 portfolio->build(engineFactory);
232
233 // check CCYswap NPV
234 BOOST_TEST_MESSAGE("CcySwap Price = " << swap1->instrument()->NPV() << " " << swap1->npvCurrency()
235 << ". BBG Price = " << npvCCYswap << " USD");
236 // check if difference between ore and bbg NPV does not exceed 250 USD (on 10M notional)
237 BOOST_CHECK_CLOSE(std::abs(swap1->instrument()->NPV() - npvCCYswap), 250, 5);
238
239 // check CCYswapReset NPV
240 BOOST_TEST_MESSAGE("CcySwapReset Price = " << swap2->instrument()->NPV() << " " << swap2->npvCurrency()
241 << ". BBG Price = " << npvCCYswapReset << " USD");
242 // check if difference between ore and bbg NPV does not exceed 250 USD (on 10M notional)
243 BOOST_CHECK_CLOSE(std::abs(swap2->instrument()->NPV() - npvCCYswapReset), 250, 5);
244
245 // check if sum(XNL) on resetting leg is zero
246 Real sumXNL = 0;
247 const vector<Leg>& legs = swap2->legs();
248 for (Size i = 3; i < legs.size(); i++) {
249 const QuantLib::Leg& leg = legs[i];
250 for (Size j = 0; j < leg.size(); j++) {
251 QuantLib::ext::shared_ptr<QuantLib::CashFlow> ptrFlow = leg[j];
252 sumXNL += ptrFlow->amount();
253 }
254 }
255 BOOST_CHECK_EQUAL(sumXNL, 0);
256}
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable object holding leg data.
Definition: legdata.hpp:844
Serializable portfolio.
Definition: portfolio.hpp:43
Serializable schedule data.
Definition: schedule.hpp:202
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
Serializable Swap, Single and Cross Currency.
Definition: swap.hpp:36