quad
Defining various quadrature routines.
Based on the quadrature routines found in the CompEcon toolbox by Miranda and Fackler.
References
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwbeta(n, a=1.0, b=1.0)[source]
Computes nodes and weights for beta distribution
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float), optional(default=1.0)
A length-d
- barray_like(float), optional(default=1.0)
A d x d array representing the variance-covariance matrix of the multivariate normal distribution.
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwbeta
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwcheb(n, a=1, b=1)[source]
Computes multivariate Guass-Checbychev quadrature nodes and weights.
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwcheb
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwequi(n, a, b, kind='N', equidist_pp=None, random_state=None)[source]
Generates equidistributed sequences with property that averages value of integrable function evaluated over the sequence converges to the integral as n goes to infinity.
- Parameters:
- nint
Number of sequence points
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- kindstring, optional(default=”N”)
One of the following:
N - Neiderreiter (default)
W - Weyl
H - Haber
R - pseudo Random
- equidist_pparray_like, optional(default=None)
TODO: I don’t know what this does
- random_stateint or np.random.RandomState/Generator, optional
Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used. Relevant only when setting kind=’R’.
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwequi
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwgamma(n, a=1.0, b=1.0, tol=3e-14)[source]
Computes nodes and weights for gamma distribution
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)optional(default=ones(d))
Shape parameter of the gamma distribution parameter. Must be positive
- bscalar or array_like(float)optional(default=ones(d))
Scale parameter of the gamma distribution parameter. Must be positive
- tolscalar or array_like(float)optional(default=ones(d) * 3e-14)
Tolerance parameter for newton iterations for each node
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwgamma
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwlege(n, a, b)[source]
Computes multivariate Guass-Legendre quadrature nodes and weights.
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwlege
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwlogn(n, mu=None, sig2=None)[source]
Computes nodes and weights for multivariate lognormal distribution
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- muscalar or array_like(float), optional(default=zeros(d))
The means of each dimension of the random variable. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- sig2array_like(float), optional(default=eye(d))
A d x d array representing the variance-covariance matrix of the multivariate normal distribution.
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwlogn
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwnorm(n, mu=None, sig2=None, usesqrtm=False)[source]
Computes nodes and weights for multivariate normal distribution
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- muscalar or array_like(float), optional(default=zeros(d))
The means of each dimension of the random variable. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- sig2array_like(float), optional(default=eye(d))
A d x d array representing the variance-covariance matrix of the multivariate normal distribution.
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwnorm
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwsimp(n, a, b)[source]
Computes multivariate Simpson quadrature nodes and weights.
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwsimp
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwtrap(n, a, b)[source]
Computes multivariate trapezoid rule quadrature nodes and weights.
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwtrap
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.qnwunif(n, a, b)[source]
Computes quadrature nodes and weights for multivariate uniform distribution
- Parameters:
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- Returns:
- nodesnp.ndarray(dtype=float)
Quadrature nodes
- weightsnp.ndarray(dtype=float)
Weights for quadrature nodes
Notes
Based of original function
qnwunif
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.
- quantecon.quad.quadrect(f, n, a, b, kind='lege', random_state=None, *args, **kwargs)[source]
Integrate the d-dimensional function f on a rectangle with lower and upper bound for dimension i defined by a[i] and b[i], respectively; using n[i] points.
- Parameters:
- ffunction
The function to integrate over. This should be a function that accepts as its first argument a matrix representing points along each dimension (each dimension is a column). Other arguments that need to be passed to the function are caught by *args and **kwargs
- nint or array_like(float)
A length-d iterable of the number of nodes in each dimension
- ascalar or array_like(float)
A length-d iterable of lower endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- bscalar or array_like(float)
A length-d iterable of upper endpoints. If a scalar is given, that constant is repeated d times, where d is the number of dimensions
- kindstring, optional(default=’lege’)
Specifies which type of integration to perform. Valid values are:
lege - Gauss-Legendre cheb - Gauss-Chebyshev trap - trapezoid rule simp - Simpson rule N - Neiderreiter equidistributed sequence W - Weyl equidistributed sequence H - Haber equidistributed sequence R - Monte Carlo
- random_stateint or np.random.RandomState/Generator, optional
Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used. Relevant only when setting kind=’R’.
- *args, **kwargs
Other arguments passed to the function f
- Returns:
- outscalar (float)
The value of the integral on the region [a, b]
Notes
Based of original function
quadrect
in CompEcon toolbox by Miranda and FacklerReferences
Miranda, Mario J, and Paul L Fackler. Applied Computational Economics and Finance, MIT Press, 2002.