75 {
76
77 BOOST_TEST_MESSAGE("Testing Swaption Price...");
78
79 Date today(3, Dec, 2018);
80 Settings::instance().evaluationDate() = today;
81
82
83 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
84 Settings::instance().evaluationDate() = market->asofDate();
85
86
87
89 Date qlStartDate =
calendar.adjust(today + 5 * Years);
90 Date qlEndDate =
calendar.adjust(qlStartDate + 10 * Years);
93
94
97
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
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
104 vector<LegData> legs;
105 legs.push_back(fixedLeg);
106 legs.push_back(floatingLeg);
107
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",
"",
117
118 Real expectedNpvCash = 565.19;
119 Real premiumNpv = premium * market->discountCurve(
"EUR")->discount(
calendar.adjust(qlStartDate));
120 Real expectedNpvPremium = expectedNpvCash - premiumNpv;
121
122
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.
Serializable object holding leg data.
Serializable object holding option data.
Serializable object holding premium data.
Serializable schedule data.
Serializable object holding schedule Rules data.
std::string to_string(const LocationInfo &l)