QuantLib
: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
ql
math
bspline.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) 2007 Allen Kuo
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 bspline.hpp
21
\brief B-spline basis functions
22
*/
23
24
#ifndef quantlib_bspline_hpp
25
#define quantlib_bspline_hpp
26
27
#include <
ql/types.hpp
>
28
#include <vector>
29
30
namespace
QuantLib
{
31
32
//! B-spline basis functions
33
/*! Follows treatment and notation from:
34
35
Weisstein, Eric W. "B-Spline." From MathWorld--A Wolfram Web
36
Resource. <http://mathworld.wolfram.com/B-Spline.html>
37
38
\f$ (p+1) \f$-th order B-spline (or p degree polynomial) basis
39
functions \f$ N_{i,p}(x), i = 0,1,2 \ldots n \f$, with \f$ n+1 \f$
40
control points, or equivalently, an associated knot vector
41
of size \f$ p+n+2 \f$ defined at the increasingly sorted points
42
\f$ (x_0, x_1 \ldots x_{n+p+1}) \f$. A linear B-spline has
43
\f$ p=1 \f$, quadratic B-spline has \f$ p=2 \f$, a cubic
44
B-spline has \f$ p=3 \f$, etc.
45
46
The B-spline basis functions are defined recursively
47
as follows:
48
49
\f[
50
\begin{array}{rcl}
51
N_{i,0}(x) &=& 1 \textrm{\ if\ } x_{i} \leq x < x_{i+1} \\
52
&=& 0 \textrm{\ otherwise} \\
53
N_{i,p}(x) &=& N_{i,p-1}(x) \frac{(x - x_{i})}{ (x_{i+p-1} - x_{i})} +
54
N_{i+1,p-1}(x) \frac{(x_{i+p} - x)}{(x_{i+p} - x_{i+1})}
55
\end{array}
56
\f]
57
*/
58
class
BSpline
{
59
public
:
60
BSpline
(
Natural
p,
61
Natural
n
,
62
const
std::vector<Real>& knots);
63
64
Real
operator()
(
Natural
i,
Real
x)
const
;
65
66
private
:
67
// recursive definition of N, the B-spline basis function
68
Real
N
(
Natural
i,
Natural
p,
Real
x)
const
;
69
// e.g. p_=2 is a quadratic B-spline, p_=3 is a cubic B-Spline, etc.
70
Natural
p_
;
71
// n_ + 1 = "control points" = max number of basis functions
72
Natural
n_
;
73
std::vector<Real>
knots_
;
74
};
75
76
}
77
78
79
#endif
n
Size n
Definition:
andreasenhugevolatilityinterpl.cpp:47
QuantLib::BSpline
B-spline basis functions.
Definition:
bspline.hpp:58
QuantLib::BSpline::p_
Natural p_
Definition:
bspline.hpp:70
QuantLib::BSpline::N
Real N(Natural i, Natural p, Real x) const
Definition:
bspline.cpp:49
QuantLib::BSpline::knots_
std::vector< Real > knots_
Definition:
bspline.hpp:73
QuantLib::BSpline::operator()
Real operator()(Natural i, Real x) const
Definition:
bspline.cpp:43
QuantLib::BSpline::n_
Natural n_
Definition:
bspline.hpp:72
QuantLib::Real
QL_REAL Real
real number
Definition:
types.hpp:50
QuantLib::Natural
unsigned QL_INTEGER Natural
positive integer
Definition:
types.hpp:43
QuantLib
Definition:
any.hpp:35
types.hpp
Custom types.
Generated by
Doxygen
1.9.5