Dimensional Reduction Regression
PortfolioOptimisers.PCA — Type
struct PCA{__T_kwargs} <: DimensionReductionTargetReplaces the factors with the principal components of their standardised covariance.
The kwargs field is forwarded to MultivariateStats.fit(MultivariateStats.PCA, X; kwargs...), and it is the only place the retained width is set: pratio caps the share of variance the retained components must explain and maxoutdim caps their number. The default kwargs = (;) takes that library's own defaults, which on a factor matrix of full rank retain every component and reduce nothing: on five factors of full rank PCA() retained five components, while PCA(; kwargs = (; pratio = 0.8)) retained four and PCA(; kwargs = (; maxoutdim = 2)) retained two.
Fields
kwargs: Keyword arguments passed tofit(MultivariateStats.PCA, X; kwargs...)
Constructors
PCA(; kwargs::NamedTuple = (;)) -> PCAKeywords correspond to the struct's fields.
Examples
julia> PCA()PCA kwargs ┴ @NamedTuple{}: NamedTuple()Related
References
- [35] K. Pearson. On lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science 2, 559–572 (1901).
- [36] H. Hotelling. Analysis of a complex of statistical variables into principal components. Journal of Educational Psychology 24, 417–441 (1933).
PortfolioOptimisers.PPCA — Type
struct PPCA{__T_kwargs} <: DimensionReductionTargetReplaces the factors with the latent components of a Gaussian latent-variable model.
The model is the maximum-likelihood factor analyser with an isotropic noise variance; its latent directions span the same subspace as the principal components of PCA, and they coincide with them in the zero-noise limit. The kwargs field is forwarded to MultivariateStats.fit(MultivariateStats.PPCA, X; kwargs...). Its default width is one fewer than PCA's, because that library caps a latent-variable model at one less than the number of input dimensions: on five factors of full rank PCA() retained five components and PPCA() retained four. maxoutdim lowers that width and must not raise it to the factor count: at the full width the third-party fit succeeds and MultivariateStats.projection then raises an ArgumentError out of its singular value decomposition, so the failure would surface inside prep_dim_red_reg rather than at construction. StatsAPI.fit(::PPCA, ::MatNum) checks the cap before it calls that library, and raises a DomainError naming maxoutdim instead. The constructor cannot hold the check, because it never sees the factor matrix.
Fields
kwargs: Keyword arguments passed tofit(MultivariateStats.PPCA, X; kwargs...)
Constructors
PPCA(; kwargs::NamedTuple = (;)) -> PPCAKeywords correspond to the struct's fields.
Examples
julia> PPCA()PPCA kwargs ┴ @NamedTuple{}: NamedTuple()Related
References
- [37] 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).
PortfolioOptimisers.DimensionReductionRegression — Type
struct DimensionReductionRegression{__T_ve, __T_drtgt, __T_retgt} <: AbstractTimeSeriesRegressionEstimatorEstimates a loadings matrix by regressing each asset on the leading components of the factors.
drtgt reduces the standardised factors to a smaller orthogonal basis, retgt fits each asset in that basis, and the coefficients are then mapped back to the original factors. ve supplies the mean and the standard deviation that mapping divides by; the expected returns estimator it reads is ve.me, and a nothing there falls back to SimpleExpectedReturns(). Unlike StepwiseRegression, every asset keeps every factor. The standardisation and the recovery read the same statistics: prep_dim_red_reg computes them from ve, and _regression recovers the coefficients with the pair it returned, so a weighted ve — the one factory builds from the incoming observation weights — is honoured end to end, as Equations 4.13, 4.15 and 4.20 of [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). require.
Fields
ve: Variance estimator.
drtgt: Dimension reduction target.
retgt: Regression model target.
Constructors
DimensionReductionRegression(; ve::AbstractVarianceEstimator = SimpleVariance(), drtgt::DimensionReductionTarget = PCA(), retgt::AbstractRegressionTarget = LinearModel()) -> DimensionReductionRegressionKeywords correspond to the struct's fields.
Validation
- If
retgt.kwargscarries aweightsentry, it must be anObsWeightsand, when it is a vector,!isempty(retgt.kwargs.weights).
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
ve: Recursively updated viafactory.drtgt: Recursively updated viafactory.retgt: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
ve: Recursively viewed viaport_opt_view.
Examples
julia> DimensionReductionRegression()DimensionReductionRegression ve ┼ SimpleVariance │ me ┼ SimpleExpectedReturns │ │ w ┴ nothing │ w ┼ nothing │ corrected ┴ Bool: true drtgt ┼ PCA │ kwargs ┴ @NamedTuple{}: NamedTuple() retgt ┼ LinearModel │ kwargs ┴ @NamedTuple{}: NamedTuple()Related
AbstractTimeSeriesRegressionEstimatorAbstractVarianceEstimatorDimensionReductionTargetAbstractRegressionTargetStepwiseRegressionRegressionfactoryport_opt_view
References
- [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 4.3.1, Equations 4.12-4.20.
- [38] 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).
StatsAPI.fit — Method
StatsAPI.fit(drtgt::PCA, X::MatNum)Fit a Principal Component Analysis (PCA) model to the data matrix X using the configuration in drtgt.
This method applies PCA as a dimension reduction technique for regression-based moment estimation.
Algorithm
- Read
drtgt.kwargs, which carries the retained width throughpratioandmaxoutdim. - Call
MultivariateStats.fitonMultivariateStats.PCAwithXand those keyword arguments, giving the fitted model.
Arguments
drtgt: APCAdimension reduction target, specifying keyword arguments for PCA.X: Data matrixfactors × observations, standardised by the caller.
Returns
model::PCA: A fitted PCA model object fromMultivariateStats.jl.
Related
StatsAPI.fit — Method
StatsAPI.fit(drtgt::PPCA, X::MatNum)Fit a Probabilistic Principal Component Analysis (PPCA) model to the data matrix X using the configuration in drtgt.
This method applies PPCA as a dimension reduction technique for regression-based moment estimation.
Algorithm
- Read
drtgt.kwargs, which carries the retained width throughmaxoutdim. - If
maxoutdimis present, check it against the number of factors,size(X, 1). - Call
MultivariateStats.fitonMultivariateStats.PPCAwithXand those keyword arguments, giving the fitted model.
Arguments
drtgt: APPCAdimension reduction target, specifying keyword arguments for PPCA.X: Data matrixfactors × observations, standardised by the caller.
Validation
- If
drtgt.kwargscarries amaxoutdimentry,0 < drtgt.kwargs.maxoutdim < size(X, 1)must hold.MultivariateStatscaps a probabilistic PCA at one latent dimension fewer than the number of factors, and its own fit accepts the full width and returns a model whose weights areNaN. Without this check the failure reaches the caller as anArgumentErrorfrom LAPACK, raised byMultivariateStats.projectioninsideprep_dim_red_reg, which names neither the cause nor the keyword.
Returns
model::PPCA: A fitted PPCA model object fromMultivariateStats.jl.
Related
PortfolioOptimisers.regression — Method
regression(re::DimensionReductionRegression, X::MatNum, F::MatNum)Reduces the factors once and regresses every asset on the same reduced basis.
The reduction is fitted on F alone, so it does not depend on the assets and one asset's response cannot move another's loadings.
Algorithm
- Allocate
rr, a denseassets × (factors + 1)buffer of zeros. - Reduce
Fwithprep_dim_red_reg, givingf1,Vp,muandsigma. - For each asset
i, fit that column ofXin the reduced basis and map the coefficients back, and write the result into rowiofrr. - Take the first column of
rrasband its remaining columns asM. - Undo the rescaling and the projection of
Min turn, givingL, the coefficients in the reduced basis. - Build a
Regressionfromb,MandL.
Arguments
re: Dimension reduction regression estimator that supplies the variance estimator, the dimension reduction target and the regression target.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.F: Data matrixobservations × factorsif thedimskeyword does not exist ordims = 1,factors × observationswhendims = 2.
Returns
reg::Regression: Regression result carrying:b: Intercept of each asset, a view of the first column ofrr.M: Coefficient of each asset and factor in the original factor space, a view of the remaining columns ofrr. Every asset keeps every factor, soMcarries no structural zero.L: Coefficient of each asset and retained component, $(\mathbf{M} \odot \boldsymbol{\sigma}^{\intercal}) \mathbf{V}_p^{+\intercal}$. It reproduces the reduced-space coefficients the fits of step 3 produced, checked at2.2e-16against them on a 200×5 sample, andsize(L, 2)is the number of retained components, which is the width risk is decomposed in.
Related
References
- [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 4.3.1, Equations 4.12-4.22.
- [38] 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).
PortfolioOptimisers.factory — Method
factory(drtgt::DimensionReductionTarget, args...; kwargs...) -> DimensionReductionTargetNo-op factory for DimensionReductionTarget subtypes. Returns the target unchanged.
Dimension reduction targets (such as PCA and PPCA) do not depend on observation weights, so this method returns drtgt unchanged. This allows generic code to call factory on dimension reduction targets without special-casing. The weights reach the reduction through DimensionReductionRegression's ve instead, which standardises the factors before the target ever sees them.
Arguments
drtgt: Dimension reduction target.args...: Additional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
drtgt: The input dimension reduction target, unchanged.
Related
References
- [5]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [35]
- K. Pearson. On lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science 2, 559–572 (1901).
- [36]
- H. Hotelling. Analysis of a complex of statistical variables into principal components. Journal of Educational Psychology 24, 417–441 (1933).
- [37]
- 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).
- [38]
- 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).