Stepwise Regression

PortfolioOptimisers.PValueType
struct PValue{T1} <: AbstractStepwiseRegressionCriterion
    threshold::T1
end

Stepwise regression criterion based on p-value thresholding.

PValue is used as a criterion for stepwise regression algorithms, where variables are included or excluded from the model based on their statistical significance (p-value). The threshold field specifies the maximum p-value for a variable to be considered significant and included in the model.

Fields

  • threshold::Real: The p-value threshold for variable inclusion (default: 0.05).

Related

source
PortfolioOptimisers.ForwardType
struct Forward <: AbstractStepwiseRegressionAlgorithm end

Stepwise regression algorithm: forward selection.

Forward specifies the forward selection strategy for stepwise regression. In forward selection, variables are added to the model one at a time based on a criterion (such as p-value or information criterion), starting from an empty model and including the variable that most improves the model at each step. The process continues until no further improvement is possible or a stopping criterion is met.

Related

source
PortfolioOptimisers.BackwardType
struct Backward <: AbstractStepwiseRegressionAlgorithm end

Stepwise regression algorithm: backward elimination.

Backward specifies the backward elimination strategy for stepwise regression. In backward elimination, all candidate variables are initially included in the model, and variables are removed one at a time based on a criterion (such as p-value or information criterion). At each step, the variable whose removal most improves the model (or least degrades it) is excluded, until no further improvement is possible or a stopping criterion is met.

Related

source
PortfolioOptimisers.StepwiseRegressionType
struct StepwiseRegression{T1, T2, T3} <: AbstractRegressionEstimator
    crit::T1
    alg::T2
    target::T3
end

Estimator for stepwise regression-based moment estimation.

StepwiseRegression is a flexible estimator type for performing stepwise regression, supporting both forward selection and backward elimination strategies. It allows users to specify the criterion for variable selection (such as p-value, AIC, BIC, or R²), the stepwise algorithm, and the regression target (e.g., linear or generalised linear models).

Fields

  • crit::AbstractStepwiseRegressionCriterion: Criterion for variable selection.
  • alg::AbstractStepwiseRegressionAlgorithm: Stepwise algorithm.
  • target::AbstractRegressionTarget: Regression target type.

Constructor

StepwiseRegression(; crit::AbstractStepwiseRegressionCriterion = PValue(),
                    alg::AbstractStepwiseRegressionAlgorithm = Forward(),
                    target::AbstractRegressionTarget = LinearModel())

Related

source
PortfolioOptimisers.add_best_asset_after_failure_pval!Function
add_best_asset_after_failure_pval!(target::AbstractRegressionTarget,
                                  included::AbstractVector,
                                  F::AbstractMatrix,
                                  x::AbstractVector)

Helper for stepwise regression: add the "best" asset by p-value if no variables are included.

This function is used in stepwise regression routines when no variables meet the p-value threshold for inclusion. It scans all excluded variables, fits a regression for each, and selects the variable with the lowest p-value (even if above the threshold). The index of this variable is pushed to included, ensuring the model always includes at least one variable.

Arguments

  • target::AbstractRegressionTarget: Regression target type (e.g., LinearModel()).
  • included::AbstractVector: Indices of currently included variables (modified in-place).
  • F::AbstractMatrix: Factor matrix (features × observations).
  • x::AbstractVector: Response vector.

Returns

  • nothing: Modifies included in-place.

Details

If included is not empty, the function does nothing. Otherwise, it evaluates each excluded variable by fitting a regression and extracting its p-value, then adds the variable with the lowest p-value to included. A warning is issued if no variable meets the threshold.

Related

source
PortfolioOptimisers.get_forward_reg_incl_excl!Function
get_forward_reg_incl_excl!(::AbstractMinValStepwiseRegressionCriterion,
                           value::AbstractVector,
                           excluded::AbstractVector,
                           included::AbstractVector,
                           threshold::Real)

Helper for forward stepwise regression with minimum-value criteria (e.g., p-value, AIC).

This function updates the included and excluded variable sets in forward stepwise regression when the selection criterion is minimized (such as p-value or AIC). It finds the variable among excluded with the lowest value, and if this value is less than the current threshold, moves it from excluded to included and updates the threshold.

Arguments

  • ::AbstractMinValStepwiseRegressionCriterion: Stepwise regression criterion type where lower values are better.
  • value::AbstractVector: Vector of criterion values for each variable.
  • excluded::AbstractVector: Indices of currently excluded variables (modified in-place).
  • included::AbstractVector: Indices of currently included variables (modified in-place).
  • threshold::Real: Current threshold value for inclusion.

Returns

  • threshold::Real: Updated threshold value after inclusion (if any).

Details

  • Finds the variable in excluded with the minimum value in value.
  • If this value is less than threshold, moves the variable from excluded to included and updates threshold.
  • If no variable meets the criterion, the sets remain unchanged and the threshold is not updated.

Related

source
get_forward_reg_incl_excl!(::AbstractMaxValStepwiseRegressionCriteria,
                           value::AbstractVector,
                           excluded::AbstractVector,
                           included::AbstractVector,
                           threshold::Real)

Helper for forward stepwise regression with maximum-value criteria (e.g., R²).

This function updates the included and excluded variable sets in forward stepwise regression when the selection criterion is maximized (such as R²). It finds the variable among excluded with the highest value, and if this value is greater than the current threshold, moves it from excluded to included and updates the threshold.

Arguments

  • ::AbstractMaxValStepwiseRegressionCriteria: Stepwise regression criterion type where higher values are better.
  • value::AbstractVector: Vector of criterion values for each variable.
  • excluded::AbstractVector: Indices of currently excluded variables (modified in-place).
  • included::AbstractVector: Indices of currently included variables (modified in-place).
  • threshold::Real: Current threshold value for inclusion.

Returns

  • threshold::Real: Updated threshold value after inclusion (if any).

Details

  • Finds the variable in excluded with the maximum value in value.
  • If this value is greater than threshold, moves the variable from excluded to included and updates threshold.
  • If no variable meets the criterion, the sets remain unchanged and the threshold is not updated.

Related

source