26#include <boost/math/distributions/students_t.hpp>
31 const std::vector<Real>& factors)
32 : degreesFreedom_(degreesFreedom), factors_(factors), polyConvolved_(
std::vector<
Real>(1, 1.))
36 "Incompatible sizes in convolution.");
37 for (
int i : degreesFreedom) {
38 QL_REQUIRE(i % 2 != 0,
"Even degree of freedom not allowed");
39 QL_REQUIRE(i >= 0,
"Negative degree of freedom not allowed");
74 std::vector<Real> low(1,1.), high(1,1.);
75 high.push_back(std::sqrt(
static_cast<Real>(
nu)));
79 for(
Size k=1; k<
n; k++) {
80 std::vector<Real> recursionFactor(1,0.);
81 recursionFactor.push_back(0.);
82 recursionFactor.push_back(
nu/((2.*k+1.)*(2.*k-1.)));
83 std::vector<Real> lowUp =
86 for(
Size i=0; i<high.size(); i++)
95 const std::vector<Real>& v1,
96 const std::vector<Real>& v2)
const {
97 #if defined(QL_EXTRA_SAFETY_CHECKS)
99 "Incorrect vectors in polynomial.");
102 const std::vector<Real>& shorter = v1.size() < v2.size() ? v1 : v2;
103 const std::vector<Real>& longer = (v1 == shorter) ? v2 : v1;
105 Size newDegree = v1.size()+v2.size()-2;
106 std::vector<Real> resultB(newDegree+1, 0.);
107 for(
Size polyOrdr=0; polyOrdr<resultB.size(); polyOrdr++) {
108 for(
Size i=std::max<Integer>(0, polyOrdr-longer.size()+1);
109 i<=std::min(polyOrdr, shorter.size()-1); i++)
110 resultB[polyOrdr] += shorter[i]*longer[polyOrdr-i];
120 Real atan2xa = std::atan2(-x,
a_);
127 /std::pow(rootsqr,
static_cast<Real>(exponent));
129 return .5 + integral /
M_PI;
137 Real atan2xa = std::atan2(-x,
a_);
141 /std::pow(rootsqr,
static_cast<Real>(exponent+1) );
143 return integral /
M_PI;
149 const std::vector<Integer>& degreesFreedom,
150 const std::vector<Real>& factors,
152 : normSqr_(
std::inner_product(factors.begin(), factors.end(),
153 factors.begin(),
Real(0.))),
154 accuracy_(accuracy), distrib_(degreesFreedom, factors) { }
std::vector< Real > polyConvolved_
std::vector< std::vector< Real > > polynCharFnc_
const std::vector< Real > & factors() const
Factors in the linear combination.
Probability density(Real x) const
Returns the probability density of the resulting distribution.
Probability operator()(Real x) const
Returns the cumulative probability of the resulting distribution.
CumulativeBehrensFisher(const std::vector< Integer > °reesFreedom=std::vector< Integer >(), const std::vector< Real > &factors=std::vector< Real >())
std::vector< Real > factors_
std::vector< Real > convolveVectorPolynomials(const std::vector< Real > &v1, const std::vector< Real > &v2) const
std::vector< Integer > degreesFreedom_
std::vector< Real > polynCharactT(Natural n) const
Student t characteristic polynomials.
static Real get(Natural n)
Real operator()(Probability q) const
Returns the cumulative inverse value.
CumulativeBehrensFisher distrib_
InverseCumulativeBehrensFisher(const std::vector< Integer > °reesFreedom=std::vector< Integer >(), const std::vector< Real > &factors=std::vector< Real >(), Real accuracy=1.e-6)
static Real standard_value(Real x)
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Factorial numbers calculator.
unsigned QL_INTEGER Natural
positive integer
Real Probability
probability
std::size_t Size
size of a container
functionals and combinators not included in the STL
normal, cumulative and inverse cumulative distributions
ext::shared_ptr< YieldTermStructure > q