19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
28#include <oret/toplevelfixture.hpp>
29#include <ql/cashflows/iborcoupon.hpp>
30#include <ql/indexes/inflation/ukrpi.hpp>
31#include <ql/termstructures/yield/discountcurve.hpp>
32#include <ql/time/calendars/unitedkingdom.hpp>
33#include <ql/time/daycounters/actual365fixed.hpp>
34#include <ql/time/daycounters/actualactual.hpp>
38using namespace boost::unit_test_framework;
51 asof_ = Date(28, August, 2018);
54 vector<Date> datesGBP = {
asof_,
85 vector<DiscountFactor> dfsGBP = {1, 0.9955, 0.9953, 0.9947, 0.9941, 0.9933, 0.9924, 0.9914,
86 0.9908, 0.9901, 0.9895, 0.9888, 0.9881, 0.9874, 0.9868, 0.9862,
87 0.9855, 0.9849, 0.9842, 0.9836, 0.9743, 0.9634, 0.9510, 0.9361,
88 0.9192, 0.9011, 0.8822, 0.8637, 0.7792, 0.7079};
92 intDiscCurve(datesGBP, dfsGBP, ActualActual(ActualActual::ISDA), UnitedKingdom());
95 Handle<IborIndex> hGBP = Handle<IborIndex>(
96 parseIborIndex(
"GBP-LIBOR-6M", intDiscCurve(datesGBP, dfsGBP, ActualActual(ActualActual::ISDA), UnitedKingdom())));
101 Handle<YieldTermStructure> intDiscCurve(vector<Date> dates, vector<DiscountFactor> dfs, DayCounter dc,
103 QuantLib::ext::shared_ptr<YieldTermStructure> idc(
104 new QuantLib::InterpolatedDiscountCurve<LogLinear>(dates, dfs, dc, cal));
105 return Handle<YieldTermStructure>(idc);
110BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
112BOOST_AUTO_TEST_SUITE(ZeroCouponSwapTests)
116 BOOST_TEST_MESSAGE(
"Testing Zero Coupon Swap Price...");
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;
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);
132 Handle<IborIndex> iis = market->iborIndex(
"GBP-LIBOR-6M");
133 QL_REQUIRE(!iis.empty(),
"GBP LIBOR 6M ibor Index not found");
135 "CPISwap: Projected Libor fixing: " << market->iborIndex(
"GBP-LIBOR-6M")->forecastFixing(today + 1 * Years));
142 Date startDate = today;
143 Date endDate = today + years * Years;
146 std::ostringstream oss;
147 oss << io::iso_date(startDate);
148 string start(oss.str());
151 oss << io::iso_date(endDate);
152 string end(oss.str());
155 vector<Real> notional(1, 1000000);
156 string paymentConvention =
"MF";
159 rates.push_back(rate);
163 string rule =
"Zero";
166 BOOST_CHECK_EQUAL(schedule.dates().size(), 2);
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);
175 vector<LegData> legData;
176 legData.push_back(leg);
177 QuantLib::ext::shared_ptr<Trade> swap(
new ore::data::Swap(env, legData));
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);
186 QuantLib::ext::shared_ptr<Portfolio> portfolio(
new Portfolio());
189 portfolio->add(swap);
190 portfolio->build(engineFactory);
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);
199BOOST_AUTO_TEST_SUITE_END()
201BOOST_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_
Serializable schedule data.
Serializable object holding schedule Rules data.
Serializable Swap, Single and Cross Currency.
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.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
An implementation of the Market class that stores the required objects in maps.
RandomVariable pow(RandomVariable x, const RandomVariable &y)
Schedule makeSchedule(const ScheduleDates &data)
Swap trade data model and serialization.
BOOST_AUTO_TEST_CASE(testZeroCouponSwapPrice)