Dimension reduction regression: private API

PortfolioOptimisers.DimensionReductionTarget — Type
abstract type DimensionReductionTarget <: AbstractRegressionAlgorithm

Abstract supertype for all dimension reduction target types.

A subtype sets the method that reduces the factors of a DimensionReductionRegression, for example PCA or PPCA. A target must answer StatsAPI.fit(tgt, X) with a model that StatsAPI.predict and dimension_reduction_map both accept. The generic method of dimension_reduction_map reads MultivariateStats.projection. That matrix is correct for a model whose predict applies the transpose of that projection.

Related

source
PortfolioOptimisers.ReducedBasisFit — Type
struct ReducedBasisFit{__T_beta, __T_edof} <: AbstractResult

Holds the fit of one asset in the reduced basis of a DimensionReductionRegression, with its coefficients mapped back to the original factors.

This type is an implementation detail and is not intended for direct use. _regression(::DimensionReductionRegression, ::VecNum, ::VecNum, ::VecNum, ::MatNum, ::MatNum) makes it, and regression(::DimensionReductionRegression, ::MatNum, ::MatNum) collects one for each asset into a Regression.

Fields

  • beta: beta: Regression coefficients in the original factor space, with the intercept as the first element.
  • edof: edof: Residual count of the fit in the reduced space, the number of rows of the projected design less its number of columns under an unpenalised target.

Related

source
PortfolioOptimisers._regression — Method
_regression(re::DimensionReductionRegression, y::VecNum, mu::VecNum,
           sigma::VecNum, x1::MatNum, Vp::MatNum) -> ReducedBasisFit

Fits one asset in the reduced basis and maps its coefficients back to the original factors.

The method discards the intercept of the reduced space and builds a new one from the mean of the response. So a fit and its recovery agree only while mu is the mean under the weights that the fit used. When the weights match, the two paths predict the same values, with or without weights. When the standardisation uses an unweighted mean and the fit uses weights, the predictions of the two paths are different.

Mathematical definition

\[\begin{align} \hat{y} &= \hat{\beta}_{0,\mathrm{pc}} + \mathbf{X}_1 \hat{\boldsymbol{\beta}}_{\mathrm{pc}}\,, \\ \hat{\boldsymbol{\beta}} &= \mathbf{V}_p \hat{\boldsymbol{\beta}}_{\mathrm{pc}} \oslash \boldsymbol{\sigma}\,, \\ \hat{\beta}_0 &= \bar{y} - \hat{\boldsymbol{\beta}}^{\intercal} \boldsymbol{\mu}\,. \end{align}\]

Where:

  • $\hat{y}$: Fitted response.
  • $\hat{\beta}_{0,\mathrm{pc}}$: Intercept of the fit in the reduced space, which this method discards.
  • $\hat{\boldsymbol{\beta}}_{\mathrm{pc}}$: Regression coefficients in the reduced space.
  • $\hat{\boldsymbol{\beta}}$: Regression coefficients in the original factor space.
  • $\hat{\beta}_0$: Intercept in the original factor space.
  • $\mathbf{X}_1$: Projected factor matrix in the reduced space, with its leading column of ones.
  • $\mathbf{V}_p$: Projection matrix of the dimension reduction model.
  • $\boldsymbol{\sigma}$: Factor standard deviations.
  • $\boldsymbol{\mu}$: Factor means.
  • $\bar{y}$: Mean of the response.
  • $\oslash$: Element-wise division.

Algorithm

  1. Read the weights of re.retgt with regression_target_weights, and call them w. Take the mean of y, weighted by w when it is not nothing, and call it mean_y.
  2. Fit re.retgt to x1 and y, with the leading column of ones named to it by factory(re.retgt, InterceptColumn(1)), and drop the leading coefficient. Call the rest beta_pc.
  3. Map beta_pc through Vp and divide by sigma. Call the result beta, the coefficients in the original factor space.
  4. Subtract the mu-weighted sum of beta from mean_y, and call the result beta0.
  5. Prepend beta0 to beta.
  6. Read the residual count of the fit of step 2 with residual_count, and call it edof.

Arguments

  • re: Dimension reduction regression.
  • y: Response vector observations × 1.
  • mu: Mean vector of the original factors. It must be the mean that standardised them. That is why prep_dim_red_reg returns it.
  • sigma: Standard deviation vector of the original factors. It must be the scale that standardised them, for the same reason.
  • x1: Projected factor matrix with an intercept column, from prep_dim_red_reg.
  • Vp: Projection matrix of the fitted dimension reduction model.

Returns

  • fit::ReducedBasisFit: The coefficients beta in the original factor space, with the intercept first, and the residual count edof of the fit in the reduced space.

Related

References

  • [73] B. D. Fekedulegn, J. J. Colbert, R. R. Hicks, Jr. and M. E. Schuckers. Coping with multicollinearity: an example on application of principal components regression in dendroecology. Research Paper NE-RP-721 (U.S. Department of Agriculture, Forest Service, Northeastern Research Station, 2002). Pages 7 and 21-22, Equations 20-23 and 34-36.
source
PortfolioOptimisers.prep_dim_red_reg — Function
prep_dim_red_reg(re::DimensionReductionRegression{<:Any, <:Any, <:Any, <:Any, Nothing},
                 X::MatNum)
prep_dim_red_reg(re::DimensionReductionRegression{<:Any, <:Any, <:Any, <:Any, <:MatNum},
                 X::MatNum)

Standardises the factors, fits the dimension reduction model, and projects the factors into the reduced basis.

It returns the two statistics of the standardisation with the projection, because the caller must undo that same scale. Equations 11 and 12 of [73] hold only when the standardisation and the recovery use the same statistics.

When re.proj holds the components, the method makes no reduction. It centres the factors at their mean and multiplies them by re.proj. It returns re.proj as the projection and a scale of ones, so the caller recovers the coefficients with the same formula. A constant shift of the components changes only the intercept of the fit in the reduced basis, and _regression discards that intercept. So the components need no centre of their own.

Algorithm

The method that Julia selects is the algorithm.

  1. Read the expected returns estimator from re.ve.me, and call it me. Use SimpleExpectedReturns() when it is nothing.
  2. Take the mean of each column of X under me, and call it mu.
  3. re.proj is nothing:
    1. Take the standard deviation of each column of X under re.ve, and call it sigma. Raise every entry to at least eps(eltype(sigma)), so that a constant factor does not cause a division by zero.
    2. Centre X with demean_returns at mu, divide each column by its entry of sigma, and transpose. Call the result X_std.
    3. Fit re.drtgt to X_std, and call the fit model.
    4. Project X_std through model and transpose. Call the result Xp, the factors in the reduced basis.
    5. Read the matrix of the projection of model with dimension_reduction_map, and call it Vp.
  4. re.proj is a matrix:
    1. Centre X with demean_returns at mu, and multiply it by re.proj. Call the result Xp.
    2. Take Vp = re.proj, and a vector of ones as sigma.
  5. Prepend a column of ones to Xp, and call the result x1.

Arguments

  • re: Dimension reduction regression estimator. Its ve gives the standard deviation, and its ve.me gives the mean. When ve.me is nothing, the method uses SimpleExpectedReturns().
  • X: Factor matrix observations × factors, which the method reduces.

Validation

  • If re.proj is a matrix, size(re.proj, 1) == size(X, 2). The method raises a DimensionMismatch otherwise.

Returns

  • x1::MatNum: Projected factor matrix observations × components, with an intercept column prepended.
  • Vp::MatNum: Projection matrix factors × components. Its transpose maps one standardised observation to its components.
  • mu::VecNum: Factor means that centre X.
  • sigma::VecNum: Factor standard deviations that scale X, or ones when re.proj holds the components.

Related

References

  • [73] B. D. Fekedulegn, J. J. Colbert, R. R. Hicks, Jr. and M. E. Schuckers. Coping with multicollinearity: an example on application of principal components regression in dendroecology. Research Paper NE-RP-721 (U.S. Department of Agriculture, Forest Service, Northeastern Research Station, 2002). Pages 4-5 and 21, Equations 8, 13-17 and 34.
source
PortfolioOptimisers.dimension_reduction_map — Function
dimension_reduction_map(model)
dimension_reduction_map(model::MultivariateStats.PPCA)

Returns the matrix whose transpose maps one centred, standardised observation of the factors to its components, as StatsAPI.predict of model maps it.

prep_dim_red_reg regresses each asset on the components that StatsAPI.predict gives, and _regression maps the coefficients back to the factors through this matrix. The recovery is exact only when this matrix is the one that the prediction applies.

Mathematical definition

The prediction of a probabilistic PCA is the posterior mean of its latent components, Equation 9 of [74]:

\[\begin{align} \mathbb{E}[\mathbf{z} \mid \mathbf{x}] &= \mathbf{M}^{-1} \mathbf{W}^{\intercal} (\mathbf{x} - \boldsymbol{\mu}_{\mathrm{pp}})\,, \\ \mathbf{M} &= \mathbf{W}^{\intercal} \mathbf{W} + \sigma^2 \mathbf{I}\,. \end{align}\]

Where:

  • $\mathbf{z}$: Latent components of one observation.
  • $\mathbf{x}$: One standardised observation of the factors.
  • $\mathbf{W}$: Weights of the model, factors × components.
  • $\sigma^2$: Noise variance of the model.
  • $\boldsymbol{\mu}_{\mathrm{pp}}$: Mean of the model.
  • $\mathbf{M}$: The $q \times q$ matrix that Statistics.cov of the model gives, with $q$ the number of components.
  • $\mathbf{I}$: Identity matrix.

So the matrix is $\mathbf{W} \mathbf{M}^{-1}$, which differs from MultivariateStats.projection, the left singular vectors of $\mathbf{W}$.

Algorithm

The method that Julia selects is the algorithm.

  1. Any model: return MultivariateStats.projection(model). For a PCA this is the matrix that the prediction applies.
  2. A probabilistic PCA: return $\mathbf{W} \mathbf{M}^{-1}$, computed as model.W / Statistics.cov(model).

Arguments

Returns

  • Vp::MatNum: Matrix factors × components.

Related

References

  • [74] M. E. Tipping and C. M. Bishop. Probabilistic principal component analysis. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 61, 611–622 (1999). Section 3.4, Equation 9.
source
PortfolioOptimisers.pin_regression_choice — Function
pin_regression_choice(re::DimensionReductionRegression{<:Any, <:Any, <:Any,
                                                       <:PinnedChoice, Nothing},
                      X::MatNum, F::MatNum, w::Option{<:ObsWeights} = nothing)

Writes the components of the first fit into proj of a dimension reduction regression under a PinnedChoice.

The online step of a prior calls it after the fold, over the rows of the buffer of the prior. The reduction reads F alone, so the components that it writes are the components that the fit over the same rows uses. A prior that refits the regression under observation weights, as OpinionPoolingPrior refits pe2, gives those weights as w, and the reduction reads them as that fit does.

The method writes the components in the units of the original factors. That is the matrix of the projection, with each row divided by the scale that standardised its factor. A later fit centres the factors at their mean over its own rows and multiplies them by proj. So the components keep the weights of the first fit, and the intercept of each asset is still its mean less the part that the factors explain. A regression whose proj is a matrix, and a regression under BatchChoice, get the generic method, which returns re unchanged.

Algorithm

  1. Return re when F holds fewer than two rows. The regression refuses one row, so no fit happens yet.
  2. Reduce F with prep_dim_red_reg, and keep Vp and sigma. When w is not nothing, the reduction is the reduction of factory(re, w).
  3. Return re rebuilt with proj = Vp ./ sigma.

Arguments

  • re: Dimension reduction regression under a PinnedChoice, whose proj is nothing.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • F: Data matrix observations × factors if the dims keyword does not exist or dims = 1, factors × observations when dims = 2.
  • w: The observation weights under which the batch fit makes the choice that the method pins, or nothing when that fit is unweighted.

Validation

Returns

  • re::DimensionReductionRegression: The regression with the components of the first fit in proj.

Related

source
PortfolioOptimisers.reader_frames — Method
reader_frames(re::Union{StepwiseRegression, DimensionReductionRegression},
              path::AbstractString, refit::Bool)

Returns the frames that a regression reader adds to the group of the optimiser that holds it.

A regression reader at x_src = nothing takes the loadings of the Prior Result when it holds them, and then it reads the frame of the prior. It fits on the raw returns rd.X only when the Prior Result holds none. So it counts as a raw reader only when refit is true. refits_regression finds refit from the prior estimator of the optimiser. A regression reader is outermost when it is in a constraint space or in a factor risk optimiser. A regression inside a prior keeps x_src = nothing, and the prior counts for it.

Arguments

  • re: Regression reader of the returns.
  • path: The path of the value from the head, for example "pe", "cle" or "r[2].pe". A warning names a reader by its path.
  • refit: true when a regression reader at x_src = nothing in the group fits its regression on the raw returns data. refits_regression finds the value.

Returns

  • fr::ReturnsFrames: The frames of re, from source_frames with raw = refit.

Related

source

References

[73]
B. D. Fekedulegn, J. J. Colbert, R. R. Hicks Jr. and M. E. Schuckers. Coping with multicollinearity: an example on application of principal components regression in dendroecology. Technical Report NE-RP-721 (U.S. Department of Agriculture, Forest Service, Northeastern Research Station, 2002).
[74]
M. E. Tipping and C. M. Bishop. Probabilistic principal component analysis. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 61, 611–622 (1999).