Regime Adjusted Exponential Weighted Covariance (b): private API
Functions
PortfolioOptimisers.gap_fill_value — Method
gap_fill_value(ce::RegimeAdjustedExpWeightedCovariance) -> Float64Answer NaN, so a gapped sample reaches the recursion with its gaps intact.
The recursion updates only the sub-block of the assets that are valid at each observation, and the regime weight is taken from that sub-block alone, so a fill would both decay a frozen block and move the regime it is weighted by. The consumer therefore hands the sample as it stands, together with the active mask that explains the gap.
Arguments
ce: Covariance estimator.
Returns
fv::Float64:NaN.
Related
Base.copy — Method
copy(
x::RegimeAdjustedCovarianceState
) -> Union{RegimeAdjustedCovarianceState{Nothing}, RegimeAdjustedCovarianceState{__T_ret_buffer} where __T_ret_buffer<:DataStructures.CircularBuffer}
Copies a RegimeAdjustedCovarianceState, so the copy shares no array with the original.
The copy method of the AbstractPartialFitState interface, which partial_fit calls before it folds. Every array field is copied, and the two scalar fields pass through. The circular buffer of recent centred returns is rebuilt at the same capacity, and each observation it holds is copied into it, so a fold on the copy pushes into a buffer of its own. The two fields of the separate correlation recursion pass through as nothing where they are nothing.
Arguments
x: The cache to copy.
Returns
state::RegimeAdjustedCovarianceState: A fresh cache, equal tox, whose arrays are fresh.
Related
PortfolioOptimisers.variance_series — Method
variance_series(
ce::RegimeAdjustedExpWeightedCovariance,
X::MatNum;
dims::Int = 1,
estimation_mask::Option{<:AbstractMatrix{<:Bool}} = nothing,
active_mask::Option{<:AbstractMatrix{<:Bool}} = nothing,
kwargs...
) -> Matrix{<:Number}Compute the point-in-time regime-adjusted exponentially weighted variance series.
Row t holds the diagonal of what cov returns for the first t observations of X, so no row reads an observation after its own. The update is a recursion over one observation, so this method overrides the expanding-window fallback with a single forward pass: it reads the cache after each observation instead of refitting.
The fallback cannot answer this estimator. It slices X once per row and passes every keyword unsliced, so a mask of the whole window meets a window of t observations and the size check refuses the call.
Arguments
ce: Regime-adjusted exponentially weighted covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which to perform the computation.estimation_mask: Optional boolean matrix with the same size asX. When provided, only assets whereestimation_mask[i, :](or[:, i]) istruecontribute to the regime state update for observationi.active_mask: Optional boolean matrix with the same size asX. When provided, assets that become inactive have their covariance and observation count reset.kwargs: Additional keyword arguments (ignored).
Validation
dims in (1, 2).- If
estimation_maskis notnothing,size(X) == size(estimation_mask). - If
active_maskis notnothing,size(X) == size(active_mask).
Returns
val::Matrix{<:Number}: Variance series, shaped as(T, N)ifdims == 1or(N, T)ifdims == 2. An asset with fewer thance.min_obsobservations at rowtisNaNthere.
Related
PortfolioOptimisers.variance_series — Method
variance_series(
ce::RegimeAdjustedExpWeightedCovariance,
X::MatNum,
pnl::Option{<:AssetPanel};
dims::Int = 1,
kwargs...
) -> Matrix{<:Number}Compute the point-in-time regime-adjusted exponentially weighted variance series from a window of an Asset Panel.
This is the diagonal of the covariance of the same call, read after each observation, and it reads the panel's two masks through the same override.
Arguments
ce: Regime-adjusted exponentially weighted covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.pnl: OptionalAssetPanel, whose active mask the Coverage Universe of the fit is derived from.nothingmakes the rule finiteness alone.dims: Dimension along which to perform the computation.kwargs: Additional keyword arguments (ignored).
Returns
val::Matrix{<:Number}: Variance series on the full asset universe, shaped as(T, N)ifdims == 1or(N, T)ifdims == 2.
Related
RegimeAdjustedExpWeightedCovariancevariance_series(ce::RegimeAdjustedExpWeightedCovariance, X::MatNum; dims::Int = 1, estimation_mask::Option{<:AbstractMatrix{<:Bool}} = nothing, active_mask::Option{<:AbstractMatrix{<:Bool}} = nothing, kwargs...)variance_series(ce::AbstractCovarianceEstimator, X::MatNum, pnl::Option{<:AssetPanel}; dims::Int = 1, kwargs...)