Stepwise Regression
PortfolioOptimisers.PValue — Type
struct PValue{__T_t} <: AbstractStepwiseRegressionCriterionSelects factors by the statistical significance of their coefficients.
A candidate model is admissible when every one of its coefficient p-values is at or below t, the intercept excluded. This is the only criterion that reads the fitted coefficients rather than one model-wide score, so it is not a MinMaxValStepwiseRegressionCriterion and it takes its own stepwise methods. Under either algorithm the selection never returns an empty factor set: when no factor clears t, add_best_factor_after_pval_failure! adds the single best one and warns.
Fields
t: Threshold value.
Constructors
PValue(; t::Number = 0.05) -> PValueKeywords correspond to the struct's fields.
Validation
0 < t < 1.
Examples
julia> PValue()PValue t ┴ Float64: 0.05Related
References
- [33] M. A. Efroymson. Multiple regression analysis. In: Mathematical Methods for Digital Computers, edited by A. Ralston and H. S. Wilf (John Wiley & Sons, 1960); pp. 191–203.
PortfolioOptimisers.ForwardSelection — Type
struct ForwardSelection <: AbstractStepwiseRegressionAlgorithmGrows the factor set from empty, adding the factor that most improves the criterion.
At each step the algorithm fits one model per excluded factor, keeps the best of them, and stops when no addition improves on the score of the set it already holds. Under a MinMaxValStepwiseRegressionCriterion the starting score is regression_threshold, the worst value that criterion can take, so the first addition always happens; under PValue the step instead admits a candidate whose p-values all clear t. The selection is therefore never empty under either criterion, which is the one behaviour that separates this tag from BackwardElimination. The steps are stated on the two methods that run them, _regression(::StepwiseRegression{<:PValue, <:ForwardSelection}, ::VecNum, ::MatNum) and _regression(::StepwiseRegression{<:MinMaxValStepwiseRegressionCriterion, <:ForwardSelection}, ::VecNum, ::MatNum).
Related
References
- [33] M. A. Efroymson. Multiple regression analysis. In: Mathematical Methods for Digital Computers, edited by A. Ralston and H. S. Wilf (John Wiley & Sons, 1960); pp. 191–203.
PortfolioOptimisers.BackwardElimination — Type
struct BackwardElimination <: AbstractStepwiseRegressionAlgorithmShrinks the factor set from full, removing the factor whose removal most improves the criterion.
At each step the algorithm fits one model per included factor, each with that factor dropped, and removes the factor whose reduced model scores best. It stops when no removal improves on the score of the set it already holds. The starting score is the score of the full model, not regression_threshold; under PValue the step instead drops the factor with the largest p-value while any exceeds t. Under a MinMaxValStepwiseRegressionCriterion the selection can therefore empty, because a criterion that rewards every removal removes every factor; the asset then gets an intercept-only model, and its row of the loadings matrix is all zeros. regression warns when that happens, naming the asset, so an unexplained asset is never silent. The steps are stated on the two methods that run them, _regression(::StepwiseRegression{<:PValue, <:BackwardElimination}, ::VecNum, ::MatNum) and _regression(::StepwiseRegression{<:MinMaxValStepwiseRegressionCriterion, <:BackwardElimination}, ::VecNum, ::MatNum).
Related
References
- [33] M. A. Efroymson. Multiple regression analysis. In: Mathematical Methods for Digital Computers, edited by A. Ralston and H. S. Wilf (John Wiley & Sons, 1960); pp. 191–203.
PortfolioOptimisers.StepwiseRegression — Type
struct StepwiseRegression{__T_crit, __T_alg, __T_tgt} <: AbstractTimeSeriesRegressionEstimatorEstimates a loadings matrix by selecting a factor subset per asset, one factor at a time.
crit scores a candidate model, alg sets the direction the factor set moves in, and tgt fits it. Each asset gets its own subset, so a factor a given asset never selected carries an exact zero in that row of the loadings matrix.
Fields
crit: Factor selection criterion. APValue, or aValof one symbol ofSTEPWISE_REGRESSION_CRITERIA.
alg: Regression algorithm.
tgt: Regression model target.
Constructors
StepwiseRegression(; crit::Union{Symbol, MinMaxValStepwiseRegressionCriterion, AbstractStepwiseRegressionCriterion} = PValue(), alg::AbstractStepwiseRegressionAlgorithm = ForwardSelection(), tgt::AbstractRegressionTarget = LinearModel()) -> StepwiseRegressionKeywords correspond to the struct's fields.
Validation
- If
critis aSymbol,crit in STEPWISE_REGRESSION_CRITERIA. The constructor storesVal(crit). - If
critisVal(:adjr2),tgtis aGeneralisedLinearModelandtgt.variantis set,tgt.variant in ADJUSTED_PSEUDO_R2_VARIANTS. - If
tgt.kwargscarries aweightsentry, it must be anObsWeightsand, when it is a vector,!isempty(tgt.kwargs.weights).
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
tgt: Recursively updated viafactory.
Examples
julia> StepwiseRegression()StepwiseRegression crit ┼ PValue │ t ┴ Float64: 0.05 alg ┼ ForwardSelection() tgt ┼ LinearModel │ kwargs ┴ @NamedTuple{}: NamedTuple()Related
AbstractStepwiseRegressionCriterionAbstractStepwiseRegressionAlgorithmAbstractRegressionTargetRegressionDimensionReductionRegressionfactory
References
PortfolioOptimisers.regression — Method
regression(re::StepwiseRegression, X::MatNum, F::MatNum)Runs one stepwise search per asset and assembles the loadings matrix from the fits.
Each asset takes its own search, so the searches see one another only through the buffer they write into.
Algorithm
- Allocate
rr, a denseassets × (factors + 1)buffer of zeros. A factor an asset never selected keeps its zero. - For each asset
i, do steps 3 to 5. - Run the stepwise search of
reon columniofX, givingincluded. - Fit
re.tgtto an intercept column and the columnsincludedofF, and read its coefficients, givingparams. Warn, naming the asset, and fit the intercept column alone whenincludedis empty. - Write
params[1]intorr[i, 1], and the remaining coefficients into the columns ofrrthatincludednames, in the orderincludedholds them. - Build a
Regressionfrom the first column ofrrand its remaining columns.
Arguments
re: Stepwise regression estimator that supplies the criterion, the algorithm 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, a view of the remaining columns ofrr. An unselected factor is an exact zero. A whole row is zero when the search selected no factor for that asset, which onlyBackwardEliminationunder aMinMaxValStepwiseRegressionCriterioncan do, and which the loop warns about.L: Left unset. The regression runs in the original factor basis, soreg.Lreads back asreg.Mthrough the result'sswap(L, M)property rule, andsize(reg.L, 2)is the number of columns ofF.
Related
References
- [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 4.1, Equations 4.2-4.3.
References
- [5]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [33]
- M. A. Efroymson. Multiple regression analysis. In: Mathematical Methods for Digital Computers, edited by A. Ralston and H. S. Wilf (John Wiley & Sons, 1960); pp. 191–203.
- [34]
- R. R. Hocking. The analysis and selection of variables in linear regression. Biometrics 32, 1–49 (1976).