131 {
132
133 BOOST_TEST_MESSAGE("Testing CcySwapWithResets Price...");
134
135
136 Real npvCCYswap = -349.69;
137 Real npvCCYswapReset = 0;
138
139
140 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
141 Settings::instance().evaluationDate() = market->asofDate();
142
143
144 Date today = market->asofDate();
145 BOOST_CHECK_EQUAL(today, Date(22, Aug, 2016));
146
147
148 Handle<YieldTermStructure> dts = market->discountCurve("EUR");
149 QL_REQUIRE(!dts.empty(), "EUR discount curve not found");
150
151
152 BOOST_CHECK_CLOSE(market->discountCurve("EUR")->discount(today + 3 * Years), 1.006005, 0.0001);
153
154
155 BOOST_CHECK_CLOSE(market->discountCurve("USD")->discount(today + 3 * Years), 0.96908, 0.0001);
156
157
158 BOOST_CHECK_EQUAL(market->fxSpot("EURUSD")->value(), 1.1306);
159
160
162
163
164 Date startDate = today;
165 Date endDate = today + 5 * Years;
166
167
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
177 string conv = "MF";
178 string rule = "Forward";
181
182
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
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
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
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
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
234 BOOST_TEST_MESSAGE("CcySwap Price = " << swap1->instrument()->NPV() << " " << swap1->npvCurrency()
235 << ". BBG Price = " << npvCCYswap << " USD");
236
237 BOOST_CHECK_CLOSE(std::abs(swap1->instrument()->NPV() - npvCCYswap), 250, 5);
238
239
240 BOOST_TEST_MESSAGE("CcySwapReset Price = " << swap2->instrument()->NPV() << " " << swap2->npvCurrency()
241 << ". BBG Price = " << npvCCYswapReset << " USD");
242
243 BOOST_CHECK_CLOSE(std::abs(swap2->instrument()->NPV() - npvCCYswapReset), 250, 5);
244
245
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.
Serializable object holding leg data.
Serializable schedule data.
Serializable object holding schedule Rules data.
Serializable Swap, Single and Cross Currency.