QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
studenttdistribution.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Roland Lichters
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file studenttdistribution.hpp
21 \brief Student's t-distribution
22*/
23
24#ifndef quantlib_student_t_distribution_hpp
25#define quantlib_student_t_distribution_hpp
26
27#include <ql/errors.hpp>
28#include <ql/types.hpp>
29#include <functional>
30
31namespace QuantLib {
32
33 //! Student t-distribution
34 /*! Probability density function for \f$ n \f$ degrees of freedom
35 (see mathworld.wolfram.com or wikipedia.org):
36 \f[
37 f(x) = \frac {\Gamma\left(\frac{n+1}{2}\right)} {\sqrt{n\pi}
38 \, \Gamma\left(\frac{n}{2}\right)}\:
39 \frac {1} {\left(1+\frac{x^2}{n}\right)^{(n+1)/2}}
40 \f]
41 */
43 public:
45 QL_REQUIRE(n > 0, "invalid parameter for t-distribution");
46 }
47 Real operator()(Real x) const;
48 private:
50 };
51
52 //! Cumulative Student t-distribution
53 /*! Cumulative distribution function for \f$ n \f$ degrees of freedom
54 (see mathworld.wolfram.com):
55 \f[
56 F(x) = \int_{-\infty}^x\,f(y)\,dy
57 = \frac{1}{2}\,
58 +\,\frac{1}{2}\,sgn(x)\,
59 \left[ I\left(1,\frac{n}{2},\frac{1}{2}\right)
60 - I\left(\frac{n}{n+y^2}, \frac{n}{2},\frac{1}{2}\right)\right]
61 \f]
62 where \f$ I(z; a, b) \f$ is the regularized incomplete beta function.
63 */
65 public:
67 QL_REQUIRE(n > 0, "invalid parameter for t-distribution");
68 }
69 Real operator()(Real x) const;
70 private:
72 };
73
74 //! Inverse cumulative Student t-distribution
75 /*! \todo Find/implement an efficient algorithm for evaluating the
76 cumulative Student t-distribution, replacing the Newton
77 iteration
78 */
80 public:
82 Real accuracy = 1e-6,
83 Size maxIterations = 50)
84 : d_(n), f_(n), accuracy_(accuracy),
85 maxIterations_(maxIterations) {}
86 Real operator()(Real x) const;
87 private:
92 };
93
94}
95
96#endif
Cumulative Student t-distribution.
Inverse cumulative Student t-distribution.
InverseCumulativeStudent(Integer n, Real accuracy=1e-6, Size maxIterations=50)
CumulativeStudentDistribution f_
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Custom types.