20#include <ql/models/shortrate/onefactormodels/coxingersollross.hpp>
21#include <ql/methods/lattices/trinomialtree.hpp>
22#include <ql/math/distributions/chisquaredistribution.hpp>
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;
109 Real ncps = 2.0*rho*rho*
x0()*std::exp(h*t)/(rho+psi+b);
110 Real ncpt = 2.0*rho*rho*
x0()*std::exp(h*t)/(rho+psi);
115 Real z = std::log(
A(t,s)/strike)/b;
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>(
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.
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates