Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inflationtraits.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/termstructures/inflation/inflationtraits.hpp
20 \brief interpolated correlation term structure
21*/
22
23#pragma once
24
25#include <ql/termstructures/bootstraphelper.hpp>
26#include <ql/termstructures/inflation/interpolatedyoyinflationcurve.hpp>
27#include <ql/termstructures/inflation/interpolatedzeroinflationcurve.hpp>
28
29namespace QuantExt {
30
31namespace detail {
32const QuantLib::Rate avgInflation = 0.02;
33const QuantLib::Rate maxInflation = 0.5;
34} // namespace detail
35
36//! Bootstrap traits to use for PiecewiseZeroInflationCurve
38public:
40 public:
41 virtual ~BootstrapFirstDateInitializer() = default;
42 virtual QuantLib::Date initialDate() const = 0;
43 };
44
45 typedef QuantLib::BootstrapHelper<QuantLib::ZeroInflationTermStructure> helper;
46
47 // start of curve data
48 static QuantLib::Date initialDate(const BootstrapFirstDateInitializer* t) { return t->initialDate(); }
49 // value at reference date
50 static QuantLib::Rate initialValue(const QuantLib::ZeroInflationTermStructure* t) { return t->baseRate(); }
51
52 // guesses
53 template <class C>
54 static QuantLib::Rate guess(QuantLib::Size i, const C* c, bool validData,
55 QuantLib::Size) // firstAliveHelper
56 {
57 if (validData) // previous iteration value
58 return c->data()[i];
59
60 if (i == 1) // first pillar
62
63 // could/should extrapolate
65 }
66
67 // constraints
68 template <class C>
69 static QuantLib::Rate minValueAfter(QuantLib::Size i, const C* c, bool validData,
70 QuantLib::Size) // firstAliveHelper
71 {
72 if (validData) {
73 QuantLib::Rate r = *(std::min_element(c->data().begin(), c->data().end()));
74 return r < 0.0 ? r * 2.0 : r / 2.0;
75 }
77 }
78 template <class C>
79 static QuantLib::Rate maxValueAfter(QuantLib::Size i, const C* c, bool validData,
80 QuantLib::Size) // firstAliveHelper
81 {
82 if (validData) {
83 QuantLib::Rate r = *(std::max_element(c->data().begin(), c->data().end()));
84 return r < 0.0 ? r / 2.0 : r * 2.0;
85 }
86 // no constraints.
87 // We choose as max a value very unlikely to be exceeded.
89 }
90
91 // update with new guess
92 static void updateGuess(std::vector<QuantLib::Rate>& data, QuantLib::Rate level, QuantLib::Size i) {
93 data[i] = level;
94 }
95 // upper bound for convergence loop
96 // calibration is trivial, should be immediate
97 static QuantLib::Size maxIterations() { return 5; }
98};
99} // namespace QuantExt
Bootstrap traits to use for PiecewiseZeroInflationCurve.
static QuantLib::Rate initialValue(const QuantLib::ZeroInflationTermStructure *t)
QuantLib::BootstrapHelper< QuantLib::ZeroInflationTermStructure > helper
static QuantLib::Rate minValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
static QuantLib::Size maxIterations()
static QuantLib::Rate maxValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
static QuantLib::Rate guess(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
static void updateGuess(std::vector< QuantLib::Rate > &data, QuantLib::Rate level, QuantLib::Size i)
static QuantLib::Date initialDate(const BootstrapFirstDateInitializer *t)
const QuantLib::Rate avgInflation
const QuantLib::Rate maxInflation