26 class CoxIngersollRoss::VolatilityConstraint :
public Constraint {
28 class Impl final :
public Constraint::Impl {
32 bool test(
const Array&
params)
const override {
40 new VolatilityConstraint::Impl(
k,
theta))) {}
45 bool withFellerConstraint)
47 theta_(arguments_[0]),
k_(arguments_[1]),
48 sigma_(arguments_[2]), r0_(arguments_[3]) {
51 if (withFellerConstraint)
58 ext::shared_ptr<OneFactorModel::ShortRateDynamics>
60 return ext::shared_ptr<ShortRateDynamics>(
66 Real h = std::sqrt(
k()*
k() + 2.0*sigma2);
67 Real numerator = 2.0*h*std::exp(0.5*(
k()+h)*(
T-
t));
68 Real denominator = 2.0*h + (
k()+h)*(std::exp((
T-
t)*h) - 1.0);
69 Real value = std::log(numerator/denominator)*
71 return std::exp(
value);
76 Real temp = std::exp((
T-
t)*h) - 1.0;
77 Real numerator = 2.0*temp;
78 Real denominator = 2.0*h + (
k()+h)*temp;
87 QL_REQUIRE(strike>0.0,
"strike must be positive");
94 return std::max<Real>(discountS - strike, 0.0);
96 return std::max<Real>(strike - discountS, 0.0);
97 default:
QL_FAIL(
"unsupported option type");
102 Real h = std::sqrt(
k()*
k() + 2.0*sigma2);
105 Real rho = 2.0*h/(sigma2*(std::exp(h*
t) - 1.0));
106 Real psi = (
k() + h)/sigma2;
116 Real call = discountS*chis(2.0*z*(
rho+psi+
b)) -
117 strike*discountT*chit(2.0*z*(
rho+psi));
122 return call - discountS + strike*discountT;
125 ext::shared_ptr<Lattice>
127 ext::shared_ptr<TrinomialTree> trinomial(
129 return ext::shared_ptr<Lattice>(
Chi-square (central and non-central) distributions.
Array params() const
Returns array of arguments on which calibration is done.
Real value(const Array ¶ms, const std::vector< ext::shared_ptr< CalibrationHelper > > &)
Standard constant parameter .
Constraint(ext::shared_ptr< Impl > impl=ext::shared_ptr< Impl >())
Dynamics of the short-rate under the Cox-Ingersoll-Ross model
Real B(Time t, Time T) const override
Real discountBondOption(Option::Type type, Real strike, Time maturity, Time bondMaturity) const override
ext::shared_ptr< Lattice > tree(const TimeGrid &grid) const override
Return by default a trinomial recombining tree.
CoxIngersollRoss(Rate r0=0.05, Real theta=0.1, Real k=0.1, Real sigma=0.1, bool withFellerConstraint=true)
ext::shared_ptr< ShortRateDynamics > dynamics() const override
returns the short-rate dynamics
Real A(Time t, Time T) const override
Single-factor affine base class.
Real discountBond(Time now, Time maturity, Array factors) const override
Recombining trinomial tree discretizing the state variable.
Constraint imposing positivity to all arguments
Recombining trinomial tree class.
Cox-Ingersoll-Ross model.
#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)
ext::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates