Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to YoY inflation index returning the last fixing date #2076

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading