Regime switches: private API

Functions

PortfolioOptimisers.hac_outer_product! — Function
hac_outer_product!(
    cache::RegimeAdjustedCovarianceState,
    ce::RegimeAdjustedExpWeightedCovariance,
    X::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
    dvalid::AbstractVector{<:Bool}
) -> Any

Computes the outer product of one observation, with the Newey-West HAC correction where hac_lags is not nothing, and divides each product by its exact factor.

The correction adds each lagged cross-product and its transpose, weighted by the Bartlett kernel $w_j = 1 - j/(L+1)$, so the update reads the serial correlation of the returns. An entry of a lagged observation that is not finite is read as zero, which freezes that pair's contribution. Each product is then divided by hac_pair_factor, its mean in units of the covariance of the pair, which is one under PreCentred.

Arguments

  • cache::RegimeAdjustedCovarianceState: Online covariance computation cache (mutated).
  • ce::RegimeAdjustedExpWeightedCovariance: Covariance estimator configuration.
  • X::VecNum: The deviations of the current observation, zero where an asset gives none.
  • dvalid::AbstractVector{<:Bool}: Mask of the assets whose deviation exists.

Returns

  • XXt::MatNum: The HAC-adjusted outer product stored in cache.XXt.

Related

source
PortfolioOptimisers.hac_pair_factor — Function
hac_pair_factor(
    cache::RegimeAdjustedCovarianceState,
    ce::RegimeAdjustedExpWeightedCovariance,
    dvalid::AbstractVector{<:Bool}
) -> Any

Exact factor of each product of the regime covariance at the current observation, in units of the covariance of the pair.

The product is the outer product of the deviations, with the HAC products where hac_lags is set. Its mean, for returns that are independent in time, is the covariance of the pair times centring_pair_factor, plus centring_lag_factor once the buffer holds a lagged observation. Under PreCentred the factor is one.

Arguments

  • cache: Online covariance computation cache, before the observation folds into its counts and overlap.
  • ce: Covariance estimator configuration.
  • dvalid: Mask of the assets whose deviation exists at the observation.

Returns

  • F::Union{Number, MatNum}: The N × N matrix of the factors, or one.

Related

source
PortfolioOptimisers.has_separate_cor_decay — Function
has_separate_cor_decay(
    ce::RegimeAdjustedExpWeightedCovariance
) -> Any

States whether the estimator runs the variance and the correlation at separate decays.

A cor_decay of nothing states one decay for the whole matrix, and a cor_decay equal to decay states the same recursion in two places. Both take the single covariance recursion, so the cache allocates no correlation state.

Arguments

  • ce: Regime-adjusted exponentially weighted covariance estimator.

Returns

  • flag::Bool: true where cor_decay is not nothing and differs from decay.

Related

source
PortfolioOptimisers.regime_correlation_count — Function
regime_correlation_count(
    ce::RegimeAdjustedExpWeightedCovariance,
    n::Integer
) -> Any

Return the effective number of observations of the correlation of a regime-adjusted covariance over n rows.

The denoising step processes the correlation, so the count is the count of the correlation. Under a separate correlation decay, the correlation reads the pre-centred law at cor_decay, as the regime bias does. Otherwise it reads decay and the centring of the estimator. The count ignores the regime multiplier and the lags of a HAC adjustment, as variance_count does.

Arguments

  • ce: Regime-adjusted exponentially weighted covariance estimator.
  • n: Number of rows.

Returns

Related

source