Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
equityswap.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 <oret/toplevelfixture.hpp>
#include <ql/cashflows/iborcoupon.hpp>
#include <ql/termstructures/yield/discountcurve.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actual365fixed.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <qle/cashflows/equitycoupon.hpp>
#include <qle/indexes/equityindex.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testEquitySwapPriceReturn)
 
 BOOST_AUTO_TEST_CASE (testEquitySwapTotalReturn)
 
 BOOST_AUTO_TEST_CASE (testEquitySwapNotionalReset)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( testEquitySwapPriceReturn  )

Definition at line 185 of file equityswap.cpp.

185 {
186
187 BOOST_TEST_MESSAGE("Testing Equity Swap Price Return...");
188
189 // build market
190 QuantLib::ext::shared_ptr<TestMarket> market = QuantLib::ext::make_shared<TestMarket>();
191 Date today = market->asofDate();
192 Settings::instance().evaluationDate() = today;
193
194 CommonVars vars;
195 QuantLib::ext::shared_ptr<ore::data::Swap> eqSwap = vars.makeEquitySwap(EquityReturnType::Price);
196
197 // engine data and factory
198 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
199 engineData->model("Swap") = "DiscountedCashflows";
200 engineData->engine("Swap") = "DiscountingSwapEngine";
201 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
202
203 // build swaps and portfolio
204 QuantLib::ext::shared_ptr<Portfolio> portfolio(new Portfolio());
205 eqSwap->id() = "EQ_Swap";
206
207 portfolio->add(eqSwap);
208 portfolio->build(engineFactory);
209
210 QuantLib::ext::shared_ptr<QuantLib::Swap> qlSwap = vars.qlEquitySwap(EquityReturnType::Price);
211
212 auto dscEngine = QuantLib::ext::make_shared<DiscountingSwapEngine>(market->discountCurve("USD"));
213 qlSwap->setPricingEngine(dscEngine);
214 BOOST_TEST_MESSAGE("Leg 1 NPV: ORE = "
215 << QuantLib::ext::static_pointer_cast<QuantLib::Swap>(eqSwap->instrument()->qlInstrument())->legNPV(0)
216 << " QL = " << qlSwap->legNPV(0));
217 BOOST_TEST_MESSAGE("Leg 2 NPV: ORE = "
218 << QuantLib::ext::static_pointer_cast<QuantLib::Swap>(eqSwap->instrument()->qlInstrument())->legNPV(1)
219 << " QL = " << qlSwap->legNPV(1));
220 BOOST_CHECK_CLOSE(eqSwap->instrument()->NPV(), qlSwap->NPV(), 1E-8); // this is 1E-10 rel diff
221}
Serializable portfolio.
Definition: portfolio.hpp:43

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( testEquitySwapTotalReturn  )

Definition at line 223 of file equityswap.cpp.

223 {
224
225 BOOST_TEST_MESSAGE("Testing Equity Swap Total Return...");
226
227 // build market
228 QuantLib::ext::shared_ptr<TestMarket> market = QuantLib::ext::make_shared<TestMarket>();
229 Date today = market->asofDate();
230 Settings::instance().evaluationDate() = today;
231
232 CommonVars vars;
233 QuantLib::ext::shared_ptr<ore::data::Swap> eqSwap = vars.makeEquitySwap(EquityReturnType::Total);
234
235 // engine data and factory
236 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
237 engineData->model("Swap") = "DiscountedCashflows";
238 engineData->engine("Swap") = "DiscountingSwapEngine";
239 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
240
241 // build swaps and portfolio
242 QuantLib::ext::shared_ptr<Portfolio> portfolio(new Portfolio());
243 eqSwap->id() = "EQ_Swap";
244
245 portfolio->add(eqSwap);
246 portfolio->build(engineFactory);
247
248 QuantLib::ext::shared_ptr<QuantLib::Swap> qlSwap = vars.qlEquitySwap(EquityReturnType::Total);
249
250 auto dscEngine = QuantLib::ext::make_shared<DiscountingSwapEngine>(market->discountCurve("USD"));
251 qlSwap->setPricingEngine(dscEngine);
252 BOOST_TEST_MESSAGE("Leg 1 NPV: ORE = "
253 << QuantLib::ext::static_pointer_cast<QuantLib::Swap>(eqSwap->instrument()->qlInstrument())->legNPV(0)
254 << " QL = " << qlSwap->legNPV(0));
255 BOOST_TEST_MESSAGE("Leg 2 NPV: ORE = "
256 << QuantLib::ext::static_pointer_cast<QuantLib::Swap>(eqSwap->instrument()->qlInstrument())->legNPV(1)
257 << " QL = " << qlSwap->legNPV(1));
258 BOOST_CHECK_CLOSE(eqSwap->instrument()->NPV(), qlSwap->NPV(), 1E-8);
259}

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( testEquitySwapNotionalReset  )

Definition at line 261 of file equityswap.cpp.

261 {
262
263 BOOST_TEST_MESSAGE("Testing Equity Swap Notional Reset...");
264
265 // build market
266 QuantLib::ext::shared_ptr<TestMarket> market = QuantLib::ext::make_shared<TestMarket>();
267 Date today = market->asofDate();
268 // Move on 4 months so we during next period, check we can get a notional
269 Settings::instance().evaluationDate() = today + Period(4, Months);
270
271 CommonVars vars;
272 QuantLib::ext::shared_ptr<ore::data::Swap> eqSwap = vars.makeEquitySwap(EquityReturnType::Total, true);
273
274 // engine data and factory
275 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
276 engineData->model("Swap") = "DiscountedCashflows";
277 engineData->engine("Swap") = "DiscountingSwapEngine";
278 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
279
280 // build swaps and portfolio
281 QuantLib::ext::shared_ptr<Portfolio> portfolio(new Portfolio());
282 eqSwap->id() = "EQ_Swap";
283
284 portfolio->add(eqSwap);
285 portfolio->build(engineFactory);
286
287 QuantLib::ext::shared_ptr<QuantLib::Swap> qlSwap = vars.qlEquitySwap(EquityReturnType::Total, true);
288
289 BOOST_TEST_MESSAGE("Initial notional = " << eqSwap->notional());
290
291 // Add equity fixing after portfolio build, this allows us to test notional without fixing
292 market->equityCurve("SP5")->addFixing(Date(18, October, 2016), 2100);
293
294 auto dscEngine = QuantLib::ext::make_shared<DiscountingSwapEngine>(market->discountCurve("USD"));
295 qlSwap->setPricingEngine(dscEngine);
296 BOOST_TEST_MESSAGE("Leg 1 NPV: ORE = "
297 << QuantLib::ext::static_pointer_cast<QuantLib::Swap>(eqSwap->instrument()->qlInstrument())->legNPV(0)
298 << " QL = " << qlSwap->legNPV(0));
299 BOOST_TEST_MESSAGE("Leg 2 NPV: ORE = "
300 << QuantLib::ext::static_pointer_cast<QuantLib::Swap>(eqSwap->instrument()->qlInstrument())->legNPV(1)
301 << " QL = " << qlSwap->legNPV(1));
302 BOOST_CHECK_CLOSE(eqSwap->instrument()->NPV(), qlSwap->NPV(), 1E-8);
303}