Mean test draws
Draw algorithms
PortfolioOptimisers.ObservationDraws — Type
struct ObservationDraws <: AbstractBootstrapDrawsDraws one multiplier for each finite entry of the series, and computes the statistic of each draw from the product.
It reads every kernel at its exact weights. Every kernel reads the multipliers in the same order, one per finite entry and draw by draw, so two kernels answer their p-values from the same draws of one generator. Under BartlettKernel a draw reads sums of windows, so its cost is linear in the length of the series. Under any other kernel a block of draws is one product with the matrix of the weights, so the cost of a draw is quadratic in the length. It is the default of every kernel except QuadraticSpectralKernel.
Constructors
ObservationDraws() -> ObservationDrawsExamples
julia> WildBootstrapMeanTest().algObservationDraws()Related
PortfolioOptimisers.QuadratureSumDraws — Type
struct QuadratureSumDraws{__T_tol, __T_nodes, __T_form} <: AbstractBootstrapDrawsDraws the statistic of each draw from a few Gaussian sums, through quadrature features of the QuadraticSpectralKernel.
The quadratic spectral kernel is the cosine transform of a weight on a bounded band, so a Gauss-Legendre rule of $2N$ nodes on the band writes the matrix of its weights as $\mathbf{\Phi} \mathbf{\Phi}^{\intercal}$, with $2N$ features per entry. The statistic of a draw reads the multipliers only through the sum of the product and its sums against the centred features. These $2N + 1$ sums are jointly Gaussian, with the covariance $\mathbf{H}^{\intercal} \mathbf{H}$, so the test draws them directly. A draw then costs $O(N^{2})$, whatever the length of the series.
The observed statistic reads the weighted sum of the observed series by the rule form. The default FeatureLongRunForm reads it through the same features, so the whole test costs $O(P K)$ once and $O(K^{2})$ per draw, with $K = 2N$. ExactLongRunForm reads the exact sum over every lag, at $O(P^{2})$.
The largest angle that the test reads, $c$, sets the number of nodes. Under FiniteEntrySpan, $c < 6 \pi / (5 b)$, so the count depends on the bandwidth fraction b and not on the length of the series. The count is the smallest $N$ whose bound on the error of the quadrature, at every lag, is at most tol. The bound is that of Gauss quadrature for a function analytic in the Bernstein ellipse $E_{\rho}$, minimised over $\rho$. Measured at a tolerance of 1e-14, it agrees with the smallest sufficient count to one node: 9 nodes at b = 0.4, 19 at b = 0.1 and 114 at b = 0.01. A fixed count is wrong at a small b: 32 nodes give an error of 0.57 at b = 0.02.
Mathematical definition
\[\begin{align} k(x) &\approx \sum_{l = 1}^{N} a_{l}^{2} \cos\left( \frac{6 \pi}{5} x u_{l} \right)\,, \quad a_{l} = \sqrt{\frac{3}{2} w_{l} \left( 1 - u_{l}^{2} \right)}\,, \\ \boldsymbol{\phi}_{i} &= \left( a_{l} \cos(\theta_{i} u_{l}),\, a_{l} \sin(\theta_{i} u_{l}) \right)_{l = 1}^{N}\,, \quad \theta_{i} = \frac{6 \pi (i - 1)}{5 B}\,, \\ \boldsymbol{h}_{i} &= d_{i} \left( 1,\, \boldsymbol{\phi}_{i} - \bar{\boldsymbol{\phi}} \right)\,, \quad \mathbf{H}^{\intercal} \mathbf{H} = \mathbf{R}^{\intercal} \mathbf{R}\,, \\ \boldsymbol{v} &= \mathbf{R}^{\intercal} \boldsymbol{z}\,, \quad \boldsymbol{z} \sim \mathcal{N}(\boldsymbol{0}, \mathbf{I})\,, \quad \bar{u}^{*} = \frac{v_{1}}{n}\,, \quad Q^{*} = \sum_{k \geq 2} v_{k}^{2}\,, \\ \epsilon_{N} &\leq \min_{\rho > 1} \frac{16}{5} \left( 1 + \alpha_{\rho}^{2} \right) \cosh\left( c \beta_{\rho} \right) \frac{\rho^{-4N}}{\rho^{2} - 1}\,, \quad c = \frac{6 \pi (P - 1)}{5 B}\,. \end{align}\]
Where:
- $u_{l}$, $w_{l}$: The positive nodes and their weights of the Gauss-Legendre rule of $2N$ nodes on $[-1, 1]$, from the eigenvalues of its Jacobi matrix.
- $a_{l}$: The amplitude of node $l$.
- $\boldsymbol{\phi}_{i}$: The features of entry $i$ of the span, and $\bar{\boldsymbol{\phi}}$ their mean over the finite entries.
- $B$: The bandwidth, in entries.
- $d_{i}$: Entry $i$ of the centred series. A missing entry has no row.
- $\mathbf{R}$: A square-root factor of $\mathbf{H}^{\intercal} \mathbf{H}$, from its eigenvalues above round-off and their eigenvectors.
- $\bar{u}^{*}$, $Q^{*}$: The mean and the weighted sum of the centred product of a draw, which
studentised_meanreads. - $\epsilon_{N}$: The largest error of the quadrature over the lags of the span.
- $\alpha_{\rho} = (\rho + \rho^{-1}) / 2$, $\beta_{\rho} = (\rho - \rho^{-1}) / 2$: The semi-axes of $E_{\rho}$.
- $P$: The length of the span, from the first finite entry to the last.
Fields
tol: Bound on the error of the quadrature at every lag that the test reads, in(0, 1), ornothingfor the machine epsilon of the kernel weights. The weight at lag zero is one, so the bound is relative to the largest weight.
nodes: Number of positive nodes of the rule, ornothingto derive it fromtol. A count overrides the derivation, and a count below the derived one gives a kernel with an error abovetol.
form: Rule that computes the weighted sum of the observed series, anAbstractLongRunForm.
Constructors
QuadratureSumDraws(; tol::Option{<:Real} = nothing, nodes::Option{<:Integer} = nothing, form::AbstractLongRunForm = FeatureLongRunForm(),) -> QuadratureSumDrawsKeywords correspond to the struct's fields.
Validation
0 < tol < 1, when given. Raises aDomainError.nodes > 0, when given. Raises aDomainError.- A
WildBootstrapMeanTestwhose kernel is not theQuadraticSpectralKernelrefuses it. Raises aConflictingArgumentError.
Examples
julia> WildBootstrapMeanTest(; kernel = QuadraticSpectralKernel()).algQuadratureSumDraws tol ┼ nothing nodes ┼ nothing form ┴ FeatureLongRunForm()julia> PortfolioOptimisers.quadrature_node_count(6 * pi / (5 * 0.1), 1e-14)19Related
AbstractBootstrapDrawsObservationDrawsEigenSumDrawsAbstractLongRunFormQuadraticSpectralKernelWildBootstrapMeanTest
References
PortfolioOptimisers.EigenSumDraws — Type
struct EigenSumDraws <: AbstractBootstrapDrawsDraws the statistic of each draw from a few Gaussian sums, through an eigen factor of the matrix of the kernel weights.
The algorithm factors the symmetric matrix $\mathbf{W}$ of the weights of every pair once, as $\mathbf{W} = \mathbf{\Phi}_{+} \mathbf{\Phi}_{+}^{\intercal} - \mathbf{\Phi}_{-} \mathbf{\Phi}_{-}^{\intercal}$, from its eigenvalues above round-off in absolute value. It then draws the Gaussian sums of QuadratureSumDraws with these columns as the features, and subtracts the squares of the sums that read $\mathbf{\Phi}_{-}$. The factor is exact, so it reads every kernel, one that a user writes included, and a kernel whose weights are not positive semidefinite. The factorisation costs $O(P^{3})$ once, and a draw costs $O(r^{2})$, with $r$ the rank of the factor. An eigenvalue at most $P \epsilon \max_{k} |\lambda_{k}|$ in absolute value is round-off of zero, and the factor drops it.
Constructors
EigenSumDraws() -> EigenSumDrawsExamples
julia> WildBootstrapMeanTest(; alg = EigenSumDraws()).algEigenSumDraws()Related
PortfolioOptimisers.wild_bootstrap_statistics — Function
wild_bootstrap_statistics(kernel::AbstractLongRunKernel, alg::AbstractBootstrapDraws,
M::Integer, d::VecNum, f::AbstractVector{Bool}, n::Integer,
nd::Integer, B::Real, buf::VecNum,
rng::Random.AbstractRNG) -> Tuple
wild_bootstrap_statistics(kernel::QuadraticSpectralKernel, alg::QuadratureSumDraws,
M::Integer, d::VecNum, f::AbstractVector{Bool}, n::Integer,
nd::Integer, B::Real, buf::VecNum,
rng::Random.AbstractRNG) -> TupleReturn the weighted sum of the observed series and the absolute t-statistics of M wild bootstrap draws of it.
The generic method reads the exact sum by long_run_quadratic_form, and the draws by draw_statistics. The quadrature method computes the features of quadrature_kernel_features once, reads the sum by observed_long_run_form under alg.form, and the draws by sum_draw_statistics. A sum that is not positive gives no statistic, so neither method draws for it.
Arguments
kernel: The kernel.alg: The draw algorithm.M: The number of draws.d: The centred series, with a zero at each missing observation. It is not changed.f: Whether each entry ofdis a finite observation.n: The number of finite entries.nd: The divisor of the long-run variance,n - ddof.B: The bandwidth, in entries.buf: Work buffer of lengthlength(d) + 1.rng: The generator.
Returns
Q::Real: The weighted sum of the observed series.ats::Vector{<:Real}: TheMabsolute t-statistics, empty whenQis not positive. A statistic that is not finite isInf.
Related
PortfolioOptimisers.assert_bootstrap_draws — Function
assert_bootstrap_draws(kernel::AbstractLongRunKernel, alg::AbstractBootstrapDraws)Refuse a kernel that a draw algorithm cannot read.
Arguments
kernel: The kernel.alg: The draw algorithm.
Validation
QuadratureSumDrawsreads theQuadraticSpectralKernelalone. Raises aConflictingArgumentErrorfor any other kernel.
Returns
nothing.
Related
Observed long-run forms
PortfolioOptimisers.AbstractLongRunForm — Type
abstract type AbstractLongRunForm <: AbstractAlgorithmAbstract supertype for the rules that compute the weighted sum of the observed series under QuadratureSumDraws.
The observed t-statistic reads $Q = \boldsymbol{d}^{\intercal} \mathbf{W} \boldsymbol{d}$, the sum of the products of every pair of entries of the centred series weighted by the kernel. The quadratic spectral kernel weights every lag, so the exact sum costs $O(P^{2})$: 1.2 s at 50,000 entries. Through the features of the draws, $\mathbf{W} \approx \mathbf{\Phi} \mathbf{\Phi}^{\intercal}$, the sum is $\lVert \mathbf{\Phi}^{\intercal} \boldsymbol{d} \rVert^{2}$ and costs $O(P K)$: 0.8 ms at 50,000 entries.
Interfaces
In order to implement a new rule that works seamlessly with the library, subtype AbstractLongRunForm and implement the following method:
Form method
observed_long_run_form(form::AbstractLongRunForm, kernel::AbstractLongRunKernel, d::VecNum, B::Real, buf::VecNum, Phi::MatNum) -> Real: The weighted sum $Q$ of the observed series.
Arguments
form: Concrete subtype instance.kernel: The kernel of the test.d: The centred series, with a zero at each missing observation.B: The bandwidth, in entries.buf: Work buffer of lengthlength(d) + 1.Phi: The quadrature features of every entry of the span, fromquadrature_kernel_features.
Returns
Q::Real: The weighted sum.
Related
PortfolioOptimisers.ExactLongRunForm — Type
struct ExactLongRunForm <: AbstractLongRunFormComputes the weighted sum of the observed series at the exact kernel weights, by long_run_quadratic_form.
It sums every lag of the series, so under the quadratic spectral kernel its cost is quadratic in the length of the series. The observed statistic then reads the exact weights, and the draws read the weights of the quadrature to its tolerance.
Constructors
ExactLongRunForm() -> ExactLongRunFormExamples
julia> QuadratureSumDraws(; form = ExactLongRunForm()).formExactLongRunForm()Related
PortfolioOptimisers.FeatureLongRunForm — Type
struct FeatureLongRunForm <: AbstractLongRunFormComputes the weighted sum of the observed series through the quadrature features of the draws, as $\lVert \mathbf{\Phi}^{\intercal} \boldsymbol{d} \rVert^{2}$.
Its cost is linear in the length of the series, and the observed statistic reads the same kernel as the draws. It differs from the exact sum by the error of the quadrature: 1.3e-14 relative at 50,000 entries at the default tolerance. It is the default of QuadratureSumDraws.
Constructors
FeatureLongRunForm() -> FeatureLongRunFormExamples
julia> QuadratureSumDraws().formFeatureLongRunForm()Related
PortfolioOptimisers.observed_long_run_form — Function
observed_long_run_form(form::ExactLongRunForm, kernel::AbstractLongRunKernel,
d::VecNum, B::Real, buf::VecNum, Phi::MatNum) -> Real
observed_long_run_form(form::FeatureLongRunForm, kernel::AbstractLongRunKernel,
d::VecNum, B::Real, buf::VecNum, Phi::MatNum) -> RealReturn the weighted sum of the observed series under a rule of AbstractLongRunForm.
Arguments
form: The rule.kernel: The kernel.d: The centred series, with a zero at each missing observation.B: The bandwidth, in entries.buf: Work buffer of lengthlength(d) + 1.Phi: The quadrature features of every entry of the span.
Returns
Q::Real:long_run_quadratic_formunderExactLongRunForm, and $\lVert \mathbf{\Phi}^{\intercal} \boldsymbol{d} \rVert^{2}$ underFeatureLongRunForm. A missing entry is zero ind, so its row ofPhiadds nothing.
Related
References
- [16]
- G. H. Golub and J. H. Welsch. Calculation of Gauss Quadrature Rules. Mathematics of Computation 23, 221–230 (1969).
- [17]
- L. N. Trefethen. Approximation Theory and Approximation Practice, Extended Edition (SIAM, Philadelphia, 2019).