31#include <boost/math/distributions/non_central_chi_squared.hpp>
37 const ext::shared_ptr<GeneralizedBlackScholesProcess>& bsProcess,
38 ext::shared_ptr<SquareRootProcess> sqrtProcess,
39 std::vector<Date> maturityDates,
43 : pMax_(pMax), pMin_(pMin), bsProcess_(bsProcess), sqrtProcess_(
std::move(sqrtProcess)),
44 maturityDates_(
std::move(maturityDates)), lagrangeOrder_(lagrangeOrder),
57 const Date&
d)
const {
69 return std::make_pair(df, ncp);
83 const boost::math::non_central_chi_squared_distribution<Real>
84 dist(p.first, p.second);
88 ? 0.0 : boost::math::quantile(dist,
pMin_));
108 const boost::math::non_central_chi_squared_distribution<Real>
109 dist(params.first, params.second);
112 for (
Size i=0,
n=
s.size(); i <
n; ++i) {
113 const Real q = boost::math::cdf(dist, x[i]);
133 model.maturityDates_.size(), model.lagrangeOrder_)),
135 model.maturityDates_.size(), model.lagrangeOrder_)) {
138 std::sort(maturityDates.begin(), maturityDates.end());
140 const ext::shared_ptr<GeneralizedBlackScholesProcess>&
143 for (
Size i=0,
n = maturityDates.size(); i <
n; ++i) {
144 const Date maturityDate = maturityDates[i];
149 std::copy(x.
begin(), x.
end(),
x_->row_begin(i));
150 std::copy(
y.begin(),
y.end(),
s_->row_begin(i));
152 const Time maturity = bsProcess->time(maturityDate);
155 std::make_pair(maturity,
156 ext::make_shared<LagrangeInterpolation>(
157 x_->row_begin(i),
x_->row_end(i),
163 const interpl_type::const_iterator ge = interpl.lower_bound(
t);
166 return (*ge->second)(x,
true);
169 QL_REQUIRE(ge != interpl.end() && ge != interpl.begin(),
170 "extrapolation to large or small t is not allowed");
172 const Time t1 = ge->first;
173 const Real y1 = (*ge->second)(x,
true);
175 interpl_type::const_iterator lt = ge;
176 std::advance(lt, -1);
178 const Time t0 = lt->first;
179 const Real y0 = (*lt->second)(x,
true);
181 return y0 + (y1 - y0)/(t1 - t0)*(
t - t0);
1-D array used in linear algebra.
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
Integral of a 1-dimensional function using the Gauss quadratures method.
virtual void calculate() const
Matrix used in linear algebra.
template class providing a null value for a given type.
Real operator()(Time t, Real x) const
const ext::shared_ptr< Matrix > x_
const ext::shared_ptr< Matrix > s_
MappingFunction(const SquareRootCLVModel &model)
const std::vector< Date > maturityDates_
const Size lagrangeOrder_
void performCalculations() const override
const ext::shared_ptr< GeneralizedBlackScholesProcess > bsProcess_
SquareRootCLVModel(const ext::shared_ptr< GeneralizedBlackScholesProcess > &bsProcess, ext::shared_ptr< SquareRootProcess > sqrtProcess, std::vector< Date > maturityDates, Size lagrangeOrder, Real pMax=Null< Real >(), Real pMin=Null< Real >())
const ext::shared_ptr< SquareRootProcess > sqrtProcess_
Real invCDF(const Date &d, Real q) const
Real cdf(const Date &d, Real x) const
ext::function< Real(Time, Real)> g_
const ext::shared_ptr< GBSMRNDCalculator > rndCalculator_
std::pair< Real, Real > nonCentralChiSquaredParams(const Date &d) const
Array collocationPointsX(const Date &d) const
Array collocationPointsY(const Date &d) const
ext::function< Real(Time, Real)> g() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
ext::function< Real(Real)> b
Integral of a 1-dimensional function using the Gauss quadratures.
risk neutral terminal density calculator for the Black-Scholes-Merton model with skew dependent volat...
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
ext::shared_ptr< YieldTermStructure > q
CLV model with a square root kernel process.