114 {
115
116 BOOST_TEST_MESSAGE("Testing Zero Coupon Swap Price...");
117
118
119 Date today(28, August, 2018);
120 Settings::instance().evaluationDate() = today;
121 QuantLib::ext::shared_ptr<TestMarket> market = QuantLib::ext::make_shared<TestMarket>();
122 Date marketDate = market->asofDate();
123 BOOST_CHECK_EQUAL(today, marketDate);
124 Settings::instance().evaluationDate() = marketDate;
125
126
127 Handle<YieldTermStructure> dts = market->discountCurve("GBP");
128 QL_REQUIRE(!dts.empty(), "GBP discount curve not found");
129 BOOST_CHECK_CLOSE(market->discountCurve("GBP")->discount(today + 1 * Years), 0.9914, 0.0001);
130
131
132 Handle<IborIndex> iis = market->iborIndex("GBP-LIBOR-6M");
133 QL_REQUIRE(!iis.empty(), "GBP LIBOR 6M ibor Index not found");
134 BOOST_TEST_MESSAGE(
135 "CPISwap: Projected Libor fixing: " << market->iborIndex("GBP-LIBOR-6M")->forecastFixing(today + 1 * Years));
136
137
139
140
141 Size years = 5;
142 Date startDate = today;
143 Date endDate = today + years * Years;
144
145
146 std::ostringstream oss;
147 oss << io::iso_date(startDate);
148 string start(oss.str());
149 oss.str("");
150 oss.clear();
151 oss << io::iso_date(endDate);
152 string end(oss.str());
153
154
155 vector<Real> notional(1, 1000000);
156 string paymentConvention = "MF";
157 Real rate = 0.02;
158 vector<Real> rates;
159 rates.push_back(rate);
160
161
162 string conv = "MF";
163 string rule = "Zero";
166 BOOST_CHECK_EQUAL(schedule.dates().size(), 2);
167
168
169 bool isPayerLibor = true;
170 string indexLibor = "GBP-LIBOR-6M";
171 LegData leg(QuantLib::ext::make_shared<ZeroCouponFixedLegData>(rates), isPayerLibor,
"GBP", scheduleData,
"Year", notional,
172 vector<string>(), paymentConvention);
173
174
175 vector<LegData> legData;
176 legData.push_back(leg);
177 QuantLib::ext::shared_ptr<Trade> swap(
new ore::data::Swap(env, legData));
178
179
180 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
181 engineData->model("Swap") = "DiscountedCashflows";
182 engineData->engine("Swap") = "DiscountingSwapEngine";
183 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
184
185
186 QuantLib::ext::shared_ptr<Portfolio> portfolio(
new Portfolio());
187 swap->id() = "Swap";
188
189 portfolio->add(swap);
190 portfolio->build(engineFactory);
191
194 Real df = market->discountCurve("GBP")->discount(fixedPayDate);
195 Real expectedNPV = -1 * notional.back() * (
pow(1.0 + rate, years) - 1.0) * df;
196 BOOST_CHECK_CLOSE(swap->instrument()->NPV(), expectedNPV, 1E-8);
197}
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.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
RandomVariable pow(RandomVariable x, const RandomVariable &y)
Schedule makeSchedule(const ScheduleDates &data)