19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
28#include <oret/toplevelfixture.hpp>
29#include <ql/termstructures/volatility/swaption/swaptionconstantvol.hpp>
30#include <ql/termstructures/yield/flatforward.hpp>
31#include <ql/time/calendars/target.hpp>
32#include <ql/time/daycounters/actualactual.hpp>
35using namespace boost::unit_test_framework;
44 asof_ = Date(2, January, 2017);
52 Handle<IborIndex> h(
parseIborIndex(
"EUR-EURIBOR-6M", flatRateYts(0.03)));
57 Handle<YieldTermStructure> flatRateYts(Real forward) {
58 QuantLib::ext::shared_ptr<YieldTermStructure> yts(
new FlatForward(0, NullCalendar(), forward, ActualActual(ActualActual::ISDA)));
59 return Handle<YieldTermStructure>(yts);
61 Handle<QuantLib::SwaptionVolatilityStructure>
62 flatSwaptionVol(Volatility forward, VolatilityType type = ShiftedLognormal, Real shift = 0.0) {
63 QuantLib::ext::shared_ptr<QuantLib::SwaptionVolatilityStructure> svs(
64 new QuantLib::ConstantSwaptionVolatility(Settings::instance().evaluationDate(), NullCalendar(),
65 ModifiedFollowing, forward, ActualActual(ActualActual::ISDA), type, shift));
66 return Handle<QuantLib::SwaptionVolatilityStructure>(svs);
71BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
73BOOST_AUTO_TEST_SUITE(EuropeanSwaptionTests)
77 BOOST_TEST_MESSAGE(
"Testing Swaption Price...");
79 Date today(3, Dec, 2018);
80 Settings::instance().evaluationDate() = today;
83 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
84 Settings::instance().evaluationDate() = market->asofDate();
89 Date qlStartDate =
calendar.adjust(today + 5 * Years);
90 Date qlEndDate =
calendar.adjust(qlStartDate + 10 * Years);
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));
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));
104 vector<LegData> legs;
105 legs.push_back(fixedLeg);
106 legs.push_back(floatingLeg);
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",
"",
118 Real expectedNpvCash = 565.19;
119 Real premiumNpv = premium * market->discountCurve(
"EUR")->discount(
calendar.adjust(qlStartDate));
120 Real expectedNpvPremium = expectedNpvCash - premiumNpv;
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);
130 swaptionCash.
build(engineFactory);
131 swaptionPhysical.
build(engineFactory);
132 swaptionPremium.
build(engineFactory);
134 Real npvCash = swaptionCash.
instrument()->NPV();
135 Real npvPhysical = swaptionPhysical.
instrument()->NPV();
136 Real npvPremium = swaptionPremium.
instrument()->NPV();
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);
143 BOOST_CHECK_SMALL(npvCash - expectedNpvCash, 0.01);
144 BOOST_CHECK_SMALL(npvPremium - expectedNpvPremium, 0.01);
147BOOST_AUTO_TEST_SUITE_END()
149BOOST_AUTO_TEST_SUITE_END()
Engine builder for Swaps.
Serializable object holding generic trade data, reporting dimensions.
Serializable object holding leg data.
static const string defaultConfiguration
Default configuration label.
map< tuple< string, YieldCurveType, string >, Handle< YieldTermStructure > > yieldCurves_
map< pair< string, string >, Handle< IborIndex > > iborIndices_
map< pair< string, string >, Handle< QuantLib::SwaptionVolatilityStructure > > swaptionCurves_
Serializable object holding option data.
Serializable object holding premium data.
Serializable schedule data.
Serializable object holding schedule Rules data.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
const string & npvCurrency() const
A class to hold pricing engine parameters.
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
Map text representations to QuantLib/QuantExt types.
An implementation of the Market class that stores the required objects in maps.
std::string to_string(const LocationInfo &l)
Swaption data model and serialization.
BOOST_AUTO_TEST_CASE(testEuropeanSwaptionPrice)
string conversion utilities