88 {
89
90 BOOST_TEST_MESSAGE("Testing duration adjusted cms coupon historical rates...");
91
92 Date today(25, January, 2021);
93 Settings::instance().evaluationDate() = today;
94
95 Date startDate = Date(25, June, 2020);
96 Date endDate = Date(25, June, 2021);
97 Date payDate = Date(27, June, 2021);
98 Size fixingDays = 2;
99
100 Handle<YieldTermStructure> discountCurve(
101 QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.01, Actual365Fixed()));
102 Handle<YieldTermStructure> forwardCurve(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.02, Actual365Fixed()));
103
104 auto index = QuantLib::ext::make_shared<EuriborSwapIsdaFixA>(10 * Years, forwardCurve, discountCurve);
105
106 Date
fixingDate = index->fixingCalendar().advance(startDate, -(fixingDays * Days), Preceding);
107 Real fixingValue = 0.01;
108 index->addFixing(fixingDate, fixingValue);
109
110
111 auto pricer =
112 QuantLib::ext::make_shared<DurationAdjustedCmsCouponTsrPricer>(Handle<SwaptionVolatilityStructure>(), nullptr);
113
117
118 cpn0.setPricer(pricer);
119 cpn1.setPricer(pricer);
120 cpn10.setPricer(pricer);
121
122 BOOST_TEST_MESSAGE("duration = 0 : rate = " << cpn0.rate());
123 BOOST_TEST_MESSAGE("duration = 1 : rate = " << cpn1.rate());
124 BOOST_TEST_MESSAGE("duration = 10 : rate = " << cpn10.rate());
125
126 BOOST_TEST_MESSAGE("duration = 0 : indexFixing = " << cpn0.indexFixing());
127 BOOST_TEST_MESSAGE("duration = 1 : indexFixing = " << cpn1.indexFixing());
128 BOOST_TEST_MESSAGE("duration = 10 : indexFixing = " << cpn10.indexFixing());
129
130 auto durationAdjustment = [](const Real S, const Size i) {
131 if (i == 0)
132 return 1.0;
133 Real tmp = 0.0;
134 for (Size j = 0; j < i; ++j)
135 tmp += 1.0 / std::pow(1.0 + S, j + 1);
136 return tmp;
137 };
138
139 Real tol = 1.0E-6;
140
141 BOOST_CHECK_CLOSE(cpn0.rate(), fixingValue * durationAdjustment(fixingValue, 0), tol);
142 BOOST_CHECK_CLOSE(cpn1.rate(), fixingValue * durationAdjustment(fixingValue, 1), tol);
143 BOOST_CHECK_CLOSE(cpn10.rate(), fixingValue * durationAdjustment(fixingValue, 10), tol);
144
145 BOOST_CHECK_CLOSE(cpn0.indexFixing(), fixingValue * durationAdjustment(fixingValue, 0), tol);
146 BOOST_CHECK_CLOSE(cpn1.indexFixing(), fixingValue * durationAdjustment(fixingValue, 1), tol);
147 BOOST_CHECK_CLOSE(cpn10.indexFixing(), fixingValue * durationAdjustment(fixingValue, 10), tol);
148}
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)