Skip to content

Commit

Permalink
Add method to YoY inflation index returning the last fixing date (#2076)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Sep 23, 2024
2 parents cf9406d + 145d235 commit bbecf53
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ql/indexes/inflationindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ namespace QuantLib {
}
}

Date YoYInflationIndex::lastFixingDate() const {
if (ratio()) {
return underlyingIndex_->lastFixingDate();
} else {
const auto& fixings = timeSeries();
QL_REQUIRE(!fixings.empty(), "no fixings stored for " << name());
// attribute fixing to first day of the underlying period
return inflationPeriod(fixings.lastDate(), frequency_).first;
}
}

bool YoYInflationIndex::needsForecast(const Date& fixingDate) const {
Date today = Settings::instance().evaluationDate();

Expand Down
1 change: 1 addition & 0 deletions ql/indexes/inflationindex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ namespace QuantLib {

//! \name Other methods
//@{
Date lastFixingDate() const;
bool interpolated() const;
bool ratio() const;
ext::shared_ptr<ZeroInflationIndex> underlyingIndex() const;
Expand Down
14 changes: 14 additions & 0 deletions test-suite/inflation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ BOOST_AUTO_TEST_CASE(testQuotedYYIndexFutureFixing) {
quoted_flat.addFixing({1,January,2024}, 100.1);
quoted_flat.addFixing({1,February,2024}, 100.2);

BOOST_CHECK_EQUAL(quoted_flat.lastFixingDate(), Date(1,February,2024));
BOOST_CHECK_EQUAL(quoted_linear.lastFixingDate(), Date(1,February,2024));

// mid-January fixing: ok for both flat and interpolated
BOOST_CHECK_NO_THROW(quoted_flat.fixing({15,January,2024}));
BOOST_CHECK_NO_THROW(quoted_linear.fixing({15,January,2024}));
Expand All @@ -883,6 +886,10 @@ BOOST_AUTO_TEST_CASE(testQuotedYYIndexFutureFixing) {

// both ok after March is published:
quoted_flat.addFixing({1,March,2024}, 100.3);

BOOST_CHECK_EQUAL(quoted_flat.lastFixingDate(), Date(1,March,2024));
BOOST_CHECK_EQUAL(quoted_linear.lastFixingDate(), Date(1,March,2024));

BOOST_CHECK_NO_THROW(quoted_flat.fixing({15,February,2024}));
BOOST_CHECK_NO_THROW(quoted_linear.fixing({15,February,2024}));

Expand Down Expand Up @@ -1034,6 +1041,9 @@ BOOST_AUTO_TEST_CASE(testRatioYYIndexFutureFixing) {
euhicp->addFixing({1,January,2024}, 100.1);
euhicp->addFixing({1,February,2024}, 100.2);

BOOST_CHECK_EQUAL(ratio_flat.lastFixingDate(), Date(1,February,2024));
BOOST_CHECK_EQUAL(ratio_linear.lastFixingDate(), Date(1,February,2024));

// mid-January fixing: ok for both flat and interpolated
BOOST_CHECK_NO_THROW(ratio_flat.fixing({15,January,2024}));
BOOST_CHECK_NO_THROW(ratio_linear.fixing({15,January,2024}));
Expand All @@ -1049,6 +1059,10 @@ BOOST_AUTO_TEST_CASE(testRatioYYIndexFutureFixing) {

// both ok after March is published:
euhicp->addFixing({1,March,2024}, 100.3);

BOOST_CHECK_EQUAL(ratio_flat.lastFixingDate(), Date(1,March,2024));
BOOST_CHECK_EQUAL(ratio_linear.lastFixingDate(), Date(1,March,2024));

BOOST_CHECK_NO_THROW(ratio_flat.fixing({15,February,2024}));
BOOST_CHECK_NO_THROW(ratio_linear.fixing({15,February,2024}));

Expand Down

0 comments on commit bbecf53

Please sign in to comment.