25#ifndef quantlib_generalized_hull_white_hpp
26#define quantlib_generalized_hull_white_hpp
56 ext::shared_ptr<InterpolationParameter::Impl> impl =
57 ext::dynamic_pointer_cast<InterpolationParameter::Impl>(
impl_);
78 const std::vector<Date>& speedstructure,
79 const std::vector<Date>& volstructure,
80 const std::vector<Real>&
speed,
81 const std::vector<Real>&
vol,
83 const ext::function<
Real(
Real)>& fInverse = {});
85 template <
class SpeedInterpolationTraits,
class VolInterpolationTraits>
88 const std::vector<Date>& speedstructure,
89 const std::vector<Date>& volstructure,
90 const std::vector<Real>&
speed,
91 const std::vector<Real>&
vol,
92 const SpeedInterpolationTraits &speedtraits,
93 const VolInterpolationTraits &voltraits,
95 const ext::function<
Real(
Real)>& fInverse = {}) :
96 OneFactorAffineModel(2), TermStructureConsistentModel(yieldtermStructure),
101 initialize(yieldtermStructure,speedstructure,volstructure,
102 speed,
vol,speedtraits,voltraits,
f,fInverse);
105 ext::shared_ptr<ShortRateDynamics>
dynamics()
const override {
106 QL_FAIL(
"no defined process for generalized Hull-White model, "
110 ext::shared_ptr<Lattice>
tree(
const TimeGrid& grid)
const override;
119 ext::shared_ptr<ShortRateDynamics>
HWdynamics()
const;
125 Time bondMaturity)
const override;
143 class FittingParameter;
166 template <
class SpeedInterpolationTraits,
class VolInterpolationTraits>
168 const std::vector<Date>& speedstructure,
169 const std::vector<Date>& volstructure,
170 const std::vector<Real>&
speed,
171 const std::vector<Real>&
vol,
172 const SpeedInterpolationTraits &speedtraits,
173 const VolInterpolationTraits &voltraits,
175 const ext::function<
Real(
Real)>& fInverse)
178 "mean reversion inputs inconsistent");
180 "volatility inputs inconsistent");
186 DayCounter dc = yieldtermStructure->dayCounter();
187 Date ref = yieldtermStructure->referenceDate();
188 for (
auto i : speedstructure)
190 for (
auto i : volstructure)
233 :
public GeneralizedHullWhite::ShortRateDynamics {
284 return (forwardRate + 0.5*temp*temp);
299 inline ext::shared_ptr<OneFactorModel::ShortRateDynamics>
301 return ext::shared_ptr<ShortRateDynamics>(
306 template <
class I1,
class I2>
307 class LinearFlatInterpolationImpl;
315 template <
class I1,
class I2>
318 impl_ = ext::shared_ptr<Interpolation::Impl>(
new
329 template <
class I1,
class I2>
331 const I2& yBegin)
const {
339 template <
class I1,
class I2>
354 + dx*(this->
yBegin_[i-1] +0.5*dx*
s_[i-1]);
358 if (x <= this->
xMin())
360 if (x >= this->
xMax())
1-D array used in linear algebra.
const_iterator begin() const
std::vector< Parameter > arguments_
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Short-rate dynamics in the generalized Hull-White model.
ext::function< Real(Real)> _f_
ext::function< Real(Real)> _fInverse_
Dynamics(Parameter fitting, Real a, Real sigma)
Real shortRate(Time t, Real x) const override
Dynamics(Parameter fitting, const ext::function< Real(Time)> &alpha, const ext::function< Real(Time)> &sigma, ext::function< Real(Real)> f, ext::function< Real(Real)> fInverse)
Real variable(Time t, Rate r) const override
Real value(const Array &, Time t) const override
Handle< YieldTermStructure > termStructure_
Impl(Handle< YieldTermStructure > termStructure, Real a, Real sigma)
Analytical term-structure fitting parameter .
FittingParameter(const Handle< YieldTermStructure > &termStructure, Real a, Real sigma)
Generalized Hull-White model class.
Real V(Time t, Time T) const
ext::function< Real(Time)> speed() const
std::vector< Time > speedperiods_
ext::shared_ptr< ShortRateDynamics > dynamics() const override
returns the short-rate dynamics
ext::function< Real(Real)> fInverse_
Real B(Time t, Time T) const override
std::vector< Time > volperiods_
std::vector< bool > fixedReversion() const
vector to pass to 'calibrate' to fit only volatility
Real discountBondOption(Option::Type type, Real strike, Time maturity, Time bondMaturity) const override
Only valid under Hull-White model.
void generateArguments() override
std::vector< Date > volstructure_
GeneralizedHullWhite(const Handle< YieldTermStructure > &yieldtermStructure, const std::vector< Date > &speedstructure, const std::vector< Date > &volstructure, const std::vector< Real > &speed, const std::vector< Real > &vol, const SpeedInterpolationTraits &speedtraits, const VolInterpolationTraits &voltraits, const ext::function< Real(Real)> &f={}, const ext::function< Real(Real)> &fInverse={})
std::vector< Date > speedstructure_
ext::function< Real(Time)> vol() const
ext::function< Real(Real)> f_
ext::shared_ptr< ShortRateDynamics > HWdynamics() const
ext::shared_ptr< Lattice > tree(const TimeGrid &grid) const override
Real A(Time t, Time T) const override
static Real identity(Real x)
void initialize(const Handle< YieldTermStructure > &yieldtermStructure, const std::vector< Date > &speedstructure, const std::vector< Date > &volstructure, const std::vector< Real > &speed, const std::vector< Real > &vol, const SpeedInterpolationTraits &speedtraits, const VolInterpolationTraits &voltraits, const ext::function< Real(Real)> &f, const ext::function< Real(Real)> &fInverse)
Piecewise linear Ornstein-Uhlenbeck process class.
Shared handle to an observable.
basic template implementation
Real xMax() const override
Size locate(Real x) const
templateImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const int requiredPoints=2)
bool isInRange(Real x) const override
Real xMin() const override
base class for 1-D interpolations.
ext::shared_ptr< Impl > impl_
Real value(const Array &, Time t) const override
void reset(const Interpolation &interp)
Interpolation interpolator_
Parameter that holds an interpolation object.
InterpolationParameter(Size count, const Constraint &constraint=NoConstraint())
void reset(const Interpolation &interp)
Linear-interpolation with flat-extrapolation factory and traits
static const Size requiredPoints
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
Linear interpolation between discrete points with flat extapolation
LinearFlatInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Single-factor affine base class.
Base class describing the short-rate dynamics.
Ornstein-Uhlenbeck process class.
Base class for model parameter implementation.
Base class for model arguments.
const Constraint & constraint() const
void setParam(Size i, Real x)
const Array & params() const
ext::shared_ptr< Impl > impl_
Constraint imposing positivity to all arguments
1-dimensional stochastic process
Term-structure consistent model class.
const Handle< YieldTermStructure > & termStructure() const
Deterministic time-dependent parameter used for yield-curve fitting.
Real value(Real x) const override
Real secondDerivative(Real) const override
Real derivative(Real x) const override
std::vector< Real > primitiveConst_
Real primitive(Real x) const override
LinearFlatInterpolationImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Ornstein-Uhlenbeck process with piecewise linear coefficients.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
base class for 1-D interpolations
Abstract one-factor interest rate model class.
Ornstein-Uhlenbeck process.
ext::shared_ptr< YieldTermStructure > r
Real operator()(Real x) const