Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inflationstartdate.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 Quaternion Risk Management Ltd
3
4 This file is part of ORE, a free-software/open-source library
5 for transparent pricing and risk analysis - http://opensourcerisk.org
6
7 ORE is free software: you can redistribute it and/or modify it
8 under the terms of the Modified BSD License. You should have received a
9 copy of the license along with this program.
10 The license is also available online at <http://opensourcerisk.org>
11
12 This program is distributed on the basis that it will form a useful
13 contribution to risk analytics and model standardisation, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
16*/
17
19
20namespace ore {
21namespace data {
22using std::make_pair;
23using QuantLib::Date;
24using QuantLib::Period;
25using QuantLib::Days;
26
27std::pair<QuantLib::Date, QuantLib::Period> getStartAndLag(const QuantLib::Date& asof,
28 const InflationSwapConvention& conv) {
29
31
32 // If no roll schedule, just return (as of, convention's obs lag).
33 if (conv.publicationRoll() == IPR::None) {
34 return make_pair(asof, Period());
35 }
36
37 // If there is a publication roll, call getStart to retrieve the date.
38 Date d = getInflationSwapStart(asof, conv);
39
40 // Date in inflation period related to the inflation index value.
41 Date dateInPeriod = d - Period(conv.index()->frequency());
42
43 // Find period between dateInPeriod and asof. This will be the inflation curve's obsLag.
44 QL_REQUIRE(dateInPeriod < asof, "InflationCurve: expected date in inflation period ("
45 << io::iso_date(dateInPeriod) << ") to be before the as of date ("
46 << io::iso_date(asof) << ").");
47 Period curveObsLag = (asof - dateInPeriod) * Days;
48
49 return make_pair(d, curveObsLag);
50}
51
52QuantLib::Date getInflationSwapStart(const QuantLib::Date& asof, const InflationSwapConvention& conv) {
53
55
56 // If no roll schedule, just return (as of, convention's obs lag).
57 if (conv.publicationRoll() == IPR::None) {
58 return asof;
59 }
60
61 // Get schedule and check not empty
62 const Schedule& ps = conv.publicationSchedule();
63 QL_REQUIRE(!ps.empty(), "InflationCurve: roll on publication is true for "
64 << conv.id() << " but the publication schedule is empty.");
65
66 // Check the schedule dates cover the as of date.
67 const vector<Date>& ds = ps.dates();
68 QL_REQUIRE(ds.front() < asof, "InflationCurve: first date in the publication schedule ("
69 << io::iso_date(ds.front()) << ") should be before the as of date ("
70 << io::iso_date(asof) << ").");
71 QL_REQUIRE(asof < ds.back(), "InflationCurve: last date in the publication schedule ("
72 << io::iso_date(ds.back()) << ") should be after the as of date ("
73 << io::iso_date(asof) << ").");
74
75 // Find d such that d_- < asof <= d. If necessary, move to the next publication schedule date. We
76 // know that there is another date because asof < ds.back() is checked above.
77 auto it = lower_bound(ds.begin(), ds.end(), asof);
78 Date d = *it;
79 if (asof == d && conv.publicationRoll() == IPR::OnPublicationDate) {
80 d = *next(it);
81 }
82
83 // Move d back availability lag and the 15th of that month is the helper's start date.
84 // Note: the 15th of the month is specific to AU CPI. We may need to generalise later.
85 d -= conv.index()->availabilityLag();
86
87 return Date(15, d.month(), d.year());
88}
89
90} // namespace data
91} // namespace ore
const string & id() const
Definition: conventions.hpp:91
PublicationRoll publicationRoll() const
QuantLib::ext::shared_ptr< ZeroInflationIndex > index() const
PublicationRoll
Rule for determining when inflation swaps roll to observing latest inflation index release.
const Schedule & publicationSchedule() const
@ data
Definition: log.hpp:77
QuantLib::Date getInflationSwapStart(const Date &asof, const InflationSwapConvention &convention)
std::pair< QuantLib::Date, QuantLib::Period > getStartAndLag(const QuantLib::Date &asof, const InflationSwapConvention &conv)
Serializable Credit Default Swap.
Definition: namespaces.docs:23