Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
swaption.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/builders/swaption.hpp>
#include <ored/portfolio/enginedata.hpp>
#include <ored/portfolio/swaption.hpp>
#include <ored/utilities/indexparser.hpp>
#include <ored/utilities/to_string.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/termstructures/volatility/swaption/swaptionconstantvol.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/daycounters/actualactual.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testEuropeanSwaptionPrice)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testEuropeanSwaptionPrice  )

Definition at line 75 of file swaption.cpp.

75 {
76
77 BOOST_TEST_MESSAGE("Testing Swaption Price...");
78
79 Date today(3, Dec, 2018);
80 Settings::instance().evaluationDate() = today;
81
82 // build market
83 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
84 Settings::instance().evaluationDate() = market->asofDate();
85
86 // build Swaptions - expiry 5Y, term 10Y
87
88 Calendar calendar = TARGET();
89 Date qlStartDate = calendar.adjust(today + 5 * Years);
90 Date qlEndDate = calendar.adjust(qlStartDate + 10 * Years);
91 string startDate = ore::data::to_string(qlStartDate);
92 string endDate = ore::data::to_string(qlEndDate);
93
94 // schedules
95 ScheduleData floatSchedule(ScheduleRules(startDate, endDate, "6M", "TARGET", "MF", "MF", "Forward"));
96 ScheduleData fixedSchedule(ScheduleRules(startDate, endDate, "1Y", "TARGET", "MF", "MF", "Forward"));
97 // fixed leg
98 LegData fixedLeg(QuantLib::ext::make_shared<FixedLegData>(std::vector<Real>(1, 0.03)), true, "EUR", fixedSchedule, "30/360",
99 std::vector<Real>(1, 10000.0));
100 // float leg
101 LegData floatingLeg(QuantLib::ext::make_shared<FloatingLegData>("EUR-EURIBOR-6M", 2, false, std::vector<Real>(1, 0.0)),
102 false, "EUR", floatSchedule, "A360", std::vector<Real>(1, 10000.0));
103 // leg vector
104 vector<LegData> legs;
105 legs.push_back(fixedLeg);
106 legs.push_back(floatingLeg);
107
108 Envelope env("CP1");
109 OptionData optionData("Long", "Call", "European", true, vector<string>(1, startDate), "Cash");
110 OptionData optionDataPhysical("Long", "Call", "European", true, vector<string>(1, startDate), "Physical");
111 Real premium = 700.0;
112 OptionData optionDataPremium("Long", "Call", "European", true, vector<string>(1, startDate), "Cash", "",
113 PremiumData(premium, "EUR", qlStartDate));
114 ore::data::Swaption swaptionCash(env, optionData, legs);
115 ore::data::Swaption swaptionPhysical(env, optionDataPhysical, legs);
116 ore::data::Swaption swaptionPremium(env, optionDataPremium, legs);
117
118 Real expectedNpvCash = 565.19;
119 Real premiumNpv = premium * market->discountCurve("EUR")->discount(calendar.adjust(qlStartDate));
120 Real expectedNpvPremium = expectedNpvCash - premiumNpv;
121
122 // Build and price
123 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
124 engineData->model("EuropeanSwaption") = "BlackBachelier";
125 engineData->engine("EuropeanSwaption") = "BlackBachelierSwaptionEngine";
126 engineData->model("Swap") = "DiscountedCashflows";
127 engineData->engine("Swap") = "DiscountingSwapEngine";
128 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
129
130 swaptionCash.build(engineFactory);
131 swaptionPhysical.build(engineFactory);
132 swaptionPremium.build(engineFactory);
133
134 Real npvCash = swaptionCash.instrument()->NPV();
135 Real npvPhysical = swaptionPhysical.instrument()->NPV();
136 Real npvPremium = swaptionPremium.instrument()->NPV();
137
138 BOOST_TEST_MESSAGE("Swaption, NPV Currency " << swaptionCash.npvCurrency());
139 BOOST_TEST_MESSAGE("NPV Cash = " << npvCash);
140 BOOST_TEST_MESSAGE("NPV Physical = " << npvPhysical);
141 BOOST_TEST_MESSAGE("NPV Cash with premium = " << npvPremium);
142
143 BOOST_CHECK_SMALL(npvCash - expectedNpvCash, 0.01);
144 BOOST_CHECK_SMALL(npvPremium - expectedNpvPremium, 0.01);
145}
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable object holding leg data.
Definition: legdata.hpp:844
Serializable object holding option data.
Definition: optiondata.hpp:42
Serializable object holding premium data.
Definition: premiumdata.hpp:37
Serializable schedule data.
Definition: schedule.hpp:202
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
Serializable Swaption.
Definition: swaption.hpp:39
Calendar calendar
Definition: utilities.cpp:441
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function: