Bootstrap Uncertainty Sets: private API
PortfolioOptimisers.bootstrap_generator — Function
bootstrap_generator(ue::ARCHUncertaintySet, X::MatNum; kwargs...)Refits the mean and the covariance on every block bootstrap resample of X, in one pass over one index stream.
The function fits both statistics on the same resample. So a caller that needs both axes gets them from ue.n_sim index vectors, and not from two runs of ue.n_sim index vectors each.
Algorithm
- Read the observation count
TfromX. Allocatemusandsigmas. - Resolve the generator with
resolve_rngto getrng. Ifue.seedis set,rngis a private reseeded copy. The stream then starts at the same place on every call, andue.rngdoes not advance. Ifue.seedisnothing,rngisue.rng, and the stream continues from the end of the previous call. - For each of the
ue.n_simsimulations, draw one index vector withbootstrap_indices. Take those rows ofXto get the resampleXi. - Fit
ue.meonXito get one column ofmus. - Fit
ue.ceonXito get one slice ofsigmas. Steps 4 and 5 read the sameXi, so the two statistics of one simulation come from one resample. - Return
musandsigmas. This function does not readue.pe.
Arguments
ue: ARCH uncertainty set estimator.X: Data matrix that the function resamples, with one row per observation.kwargs...: More keyword arguments, which the function gives toue.meandue.ce.
Returns
mus::Matrix{<:Number}: Bootstrap expected returns, with one column per simulation. Its size issize(X, 2) × ue.n_sim.sigmas::Array{<:Number, 3}: Bootstrap covariance matrices, with one slice per simulation. Its size issize(X, 2) × size(X, 2) × ue.n_sim.
Related
PortfolioOptimisers.mu_bootstrap_generator — Function
mu_bootstrap_generator(ue::ARCHUncertaintySet, X::MatNum; kwargs...)Refits the mean on every block bootstrap resample of X, and fits no covariance.
The function draws its index vectors as bootstrap_generator does, one vector per simulation. If ue.seed is set, the stream starts at the same place on every call, so this function sees the same resamples as the other two generators. If ue.seed is nothing, the three generators read different parts of one shared stream.
Algorithm
- Read the observation count
TfromX. Allocatemus. - Resolve the generator with
resolve_rngto getrng. Ifue.seedis set,rngis a private reseeded copy. The stream then starts at the same place on every call, andue.rngdoes not advance. Ifue.seedisnothing,rngisue.rng, and the stream continues from the end of the previous call. - For each of the
ue.n_simsimulations, draw one index vector withbootstrap_indices. Take those rows ofXto get the resampleXi. - Fit
ue.meonXito get one column ofmus. - Return
mus. This function reads neitherue.cenorue.pe.
Arguments
ue: ARCH uncertainty set estimator.X: Data matrix that the function resamples, with one row per observation.kwargs...: More keyword arguments, which the function gives toue.me.
Returns
mus::Matrix{<:Number}: Bootstrap expected returns, with one column per simulation. Its size issize(X, 2) × ue.n_sim.
Related
PortfolioOptimisers.sigma_bootstrap_generator — Function
sigma_bootstrap_generator(ue::ARCHUncertaintySet, X::MatNum; kwargs...)Refits the covariance on every block bootstrap resample of X, and fits no mean.
The function draws its index vectors as bootstrap_generator does, one vector per simulation. If ue.seed is set, the stream starts at the same place on every call, so this function sees the same resamples as the other two generators. If ue.seed is nothing, the three generators read different parts of one shared stream.
Algorithm
- Read the observation count
TfromX. Allocatesigmas. - Resolve the generator with
resolve_rngto getrng. Ifue.seedis set,rngis a private reseeded copy. The stream then starts at the same place on every call, andue.rngdoes not advance. Ifue.seedisnothing,rngisue.rng, and the stream continues from the end of the previous call. - For each of the
ue.n_simsimulations, draw one index vector withbootstrap_indices. Take those rows ofXto get the resampleXi. - Fit
ue.ceonXito get one slice ofsigmas. On the ellipsoidal route, this is the first of the two fits ofue.ce. - Return
sigmas. This function reads neitherue.menorue.pe.
Arguments
ue: ARCH uncertainty set estimator.X: Data matrix that the function resamples, with one row per observation.kwargs...: More keyword arguments, which the function gives toue.ce.
Returns
sigmas::Array{<:Number, 3}: Bootstrap covariance matrices, with one slice per simulation. Its size issize(X, 2) × size(X, 2) × ue.n_sim.
Related
PortfolioOptimisers.bootstrap_ellipsoidal_set — Function
bootstrap_ellipsoidal_set(
ue::ARCHUncertaintySet,
X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
cov::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
class::AbstractUncertaintySetClass,
val::AbstractArray{<:Union{Number, AbstractJuMPScalar}}
) -> EllipsoidalUncertaintySet{var"#s185", var"#s1851", var"#s1852", <:AbstractArray{var"#s166", N}} where {var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s185"<:AbstractMatrix{var"#s166"}, var"#s1851"<:Number, var"#s1852"<:AbstractUncertaintySetClass, var"#s166"<:Union{Number, AbstractJuMPScalar}, N}
Builds the EllipsoidalUncertaintySet of a bootstrap estimator from the bootstrap deviations and their sample covariance.
The shape is the sample covariance of the $M$ rows of X, so its rank is at most $M - 1$. If $M - 1$ is less than the dimension of the set, the repaired shape is flat in the other directions. A chi-squared radius at the full dimension is then too large for the set. So the degrees of freedom are the dimension of the set, capped at $M - 1$. This is the rank that norm_ball_deviation_set measures on the same sample, so the two routes of one bootstrap set give one radius.
Algorithm
- Calculate
df = ucs_dimension(class, ue.alg.diagonal, size(X, 2), size(X, 1)). This is the dimension of the set, capped at the number of rows ofXminus one. - Build the set with
ellipsoidal_setonue.alg,ue.q,X,cov,class,valanddf.
Arguments
ue: Bootstrap uncertainty set estimator. It gives the set algorithm and the significance level.X: Bootstrap deviations, with one row per resample.cov: Sample covariance ofX. It becomes the shape matrix.class: Axis tag of the set.val: Centre of the set. It is the fitted expected returns on the mean axis, and the fitted covariance on the covariance axis.
Returns
ucs::EllipsoidalUncertaintySet: The set.
Related