@@ -137,44 +137,68 @@ Rate calculateExtrapolatedForward(Time t, Time fsp, Rate llfr, Rate ufr, Real al
137137 return ufr + (llfr - ufr) * beta;
138138}
139139
140-
141- BOOST_AUTO_TEST_CASE (testDutchCentralBankRates) {
142- BOOST_TEST_MESSAGE (" Testing DNB replication of UFR zero annually compounded rates..." );
143-
140+ void checkDutchBankRates (const std::vector<Datum> expectedRates,
141+ const ext::optional<Integer>& rounding = ext::nullopt ,
142+ Compounding compounding = Compounded,
143+ Frequency frequency = Annual,
144+ Real tolerance = 1.0e-4 ) {
144145 CommonVars vars;
145146
146147 ext::shared_ptr<Quote> llfr = calculateLLFR (vars.ftkCurveHandle , vars.fsp );
147148
148- ext::shared_ptr<YieldTermStructure> ufrTs (
149- new UltimateForwardTermStructure (vars.ftkCurveHandle , Handle<Quote>(llfr),
150- Handle<Quote>(vars.ufrRate ), vars.fsp , vars.alpha ));
151-
152- // Official annually compounded zero rates published
153- // by the Dutch Central Bank: https://statistiek.dnb.nl/
154- Datum expectedZeroes[] = {{10 , Years, 0.00477 }, {20 , Years, 0.01004 }, {30 , Years, 0.01223 },
155- {40 , Years, 0.01433 }, {50 , Years, 0.01589 }, {60 , Years, 0.01702 },
156- {70 , Years, 0.01785 }, {80 , Years, 0.01849 }, {90 , Years, 0.01899 },
157- {100 , Years, 0.01939 }};
149+ ext::shared_ptr<YieldTermStructure> ufrTs (new UltimateForwardTermStructure (
150+ vars.ftkCurveHandle , Handle<Quote>(llfr), Handle<Quote>(vars.ufrRate ), vars.fsp , vars.alpha ,
151+ rounding, compounding, frequency));
158152
159- Real tolerance = 1.0e-4 ;
160- Size nRates = std::size (expectedZeroes);
153+ Size nRates = std::size (expectedRates);
161154
162155 for (Size i = 0 ; i < nRates; ++i) {
163- Period p = expectedZeroes [i].n * expectedZeroes [i].units ;
156+ Period p = expectedRates [i].n * expectedRates [i].units ;
164157 Date maturity = vars.settlement + p;
165158
166- Rate actual = ufrTs->zeroRate (maturity, vars.dayCount , Compounded, Annual ).rate ();
167- Rate expected = expectedZeroes [i].rate ;
159+ Rate actual = ufrTs->zeroRate (maturity, vars.dayCount , compounding, frequency ).rate ();
160+ Rate expected = expectedRates [i].rate ;
168161
169162 if (std::fabs (actual - expected) > tolerance)
170163 BOOST_ERROR (" unable to reproduce zero yield rate from the UFR curve\n "
171- << std::setprecision (5 )
172- << " calculated: " << actual << " \n "
164+ << std::setprecision (5 ) << " calculated: " << actual << " \n "
173165 << " expected: " << expected << " \n "
174166 << " tenor: " << p << " \n " );
175167 }
176168}
177169
170+ BOOST_AUTO_TEST_CASE (testDutchCentralBankRates) {
171+ BOOST_TEST_MESSAGE (" Testing DNB replication of UFR zero annually compounded rates..." );
172+
173+ std::vector<Datum> expectedRates{
174+ {10 , Years, 0.00477 }, {20 , Years, 0.01004 }, {30 , Years, 0.01223 }, {40 , Years, 0.01433 },
175+ {50 , Years, 0.01589 }, {60 , Years, 0.01702 }, {70 , Years, 0.01785 }, {80 , Years, 0.01849 },
176+ {90 , Years, 0.01899 }, {100 , Years, 0.01939 }};
177+ checkDutchBankRates (expectedRates);
178+ }
179+
180+ BOOST_AUTO_TEST_CASE (testDutchCentralBankRatesWithRounding) {
181+ BOOST_TEST_MESSAGE (
182+ " Testing DNB replication of UFR zero annually compounded rates with rounding..." );
183+ std::vector<Datum> expectedRates{{10 , Years, 0.005 }, {20 , Years, 0.01 }, {30 , Years, 0.012 },
184+ {40 , Years, 0.014 }, {50 , Years, 0.016 }, {60 , Years, 0.017 },
185+ {70 , Years, 0.018 }, {80 , Years, 0.018 }, {90 , Years, 0.019 },
186+ {100 , Years, 0.019 }};
187+
188+ checkDutchBankRates (expectedRates, 3 , Compounded, Annual, 1 .e -12 );
189+ }
190+
191+ BOOST_AUTO_TEST_CASE (testDutchCentralBankRatesWithRoundingAndContinuousCompounding) {
192+ BOOST_TEST_MESSAGE (
193+ " Testing DNB replication of UFR zero continuously compounded rates with rounding..." );
194+ std::vector<Datum> expectedRates{
195+ {10 , Years, 0.00477 }, {20 , Years, 0.01002 }, {30 , Years, 0.01211 }, {40 , Years, 0.01417 },
196+ {50 , Years, 0.01571 }, {60 , Years, 0.01683 }, {70 , Years, 0.01766 }, {80 , Years, 0.01829 },
197+ {90 , Years, 0.01878 }, {100 , Years, 0.01917 }};
198+
199+ checkDutchBankRates (expectedRates, 5 , Continuous, NoFrequency, 1 .e -12 );
200+ }
201+
178202BOOST_AUTO_TEST_CASE (testExtrapolatedForward) {
179203 BOOST_TEST_MESSAGE (" Testing continuous forward rates in extrapolation region..." );
180204
0 commit comments