24#ifndef quantext_irlgm1f_parametrization_hpp
25#define quantext_irlgm1f_parametrization_hpp
29#include <ql/experimental/math/piecewiseintegral.hpp>
30#include <ql/handle.hpp>
31#include <ql/math/integrals/integral.hpp>
32#include <ql/termstructures/yieldtermstructure.hpp>
43 const std::string&
name = std::string());
45 virtual Real
zeta(
const Time t)
const = 0;
47 virtual Real
H(
const Time t)
const = 0;
48 virtual Real
alpha(
const Time t)
const;
49 virtual Real
kappa(
const Time t)
const;
50 virtual Real
Hprime(
const Time t)
const;
51 virtual Real
Hprime2(
const Time t)
const;
56 Real
zetan(
const Size n,
const Time t,
const QuantLib::ext::shared_ptr<Integrator>& integrator);
69 void update()
const override;
83 const std::string& name)
84 :
Parametrization(currency, name.empty() ? currency.code() : name), shift_(0.0), scaling_(1.0),
85 termStructure_(termStructure) {}
90 return std::sqrt((zeta(tr(t)) - zeta(tl(t))) / h_) / scaling_;
94 return scaling_ * (H(tr(t)) - H(tl(t))) / h_;
98 return scaling_ * (H(tr2(t)) - 2.0 * H(tm2(t)) + H(tl2(t))) / (h2_ * h2_);
102 return Hprime(t) * alpha(t);
115 const QuantLib::ext::shared_ptr<Integrator>& integrator) {
116 auto z = zetan_cached_.find(std::make_pair(n, t));
117 if (z == zetan_cached_.end()) {
118 std::vector<Real> times;
119 for (Size i = 0; i < numberOfParameters(); ++i)
120 times.insert(times.end(), parameterTimes(i).begin(), parameterTimes(i).end());
121 PiecewiseIntegral pwint(integrator, times,
true);
122 Real v = pwint([
this, n](Real s) {
return std::pow(this->alpha(s), 2) * std::pow(this->H(s), n); }, 0.0, t);
123 zetan_cached_[std::make_pair(n, t)] = v;
132 zetan_cached_.clear();
virtual Real Hprime(const Time t) const
Lgm1fParametrization(const Currency ¤cy, const Handle< TS > &termStructure, const std::string &name=std::string())
const Handle< TS > termStructure_
virtual Real H(const Time t) const =0
void update() const override
Size numberOfParameters() const override
virtual Real kappa(const Time t) const
const Handle< TS > termStructure() const
virtual Real hullWhiteSigma(const Time t) const
Real zetan(const Size n, const Time t, const QuantLib::ext::shared_ptr< Integrator > &integrator)
virtual Real alpha(const Time t) const
virtual Real Hprime2(const Time t) const
std::map< std::pair< Size, Real >, Real > zetan_cached_
virtual Real zeta(const Time t) const =0
const std::string & name() const
virtual const Currency & currency() const
virtual void update() const
Lgm1fParametrization< YieldTermStructure > IrLgm1fParametrization
base class for model parametrizations