Regression

PortfolioOptimisers.AbstractRegressionResultType
abstract type AbstractRegressionResult <: AbstractResult end

Abstract supertype for all regression result types in PortfolioOptimisers.jl.

All concrete types representing the output of regression-based moment estimation should subtype AbstractRegressionResult. This enables a consistent interface for handling regression results, such as fitted parameters, rr, and intercepts, throughout the package.

Related

source
PortfolioOptimisers.AbstractRegressionAlgorithmType
abstract type AbstractRegressionAlgorithm <: AbstractAlgorithm end

Abstract supertype for all regression algorithm types in PortfolioOptimisers.jl.

All concrete types implementing specific regression algorithms should subtype AbstractRegressionAlgorithm. This enables flexible extension and dispatch of regression routines for moment estimation.

These types are used to specify the algorithm when constructing a regression estimator.

Related

source
PortfolioOptimisers.AbstractStepwiseRegressionAlgorithmType
abstract type AbstractStepwiseRegressionAlgorithm <: AbstractRegressionAlgorithm end

Abstract supertype for all stepwise regression algorithm types in PortfolioOptimisers.jl.

All concrete types implementing stepwise regression algorithms should subtype AbstractStepwiseRegressionAlgorithm. This enables modular extension and dispatch for stepwise regression routines, commonly used for variable selection and model refinement in regression-based moment estimation.

Related

source
PortfolioOptimisers.AbstractStepwiseRegressionCriterionType
abstract type AbstractStepwiseRegressionCriterion <: AbstractRegressionAlgorithm end

Abstract supertype for all stepwise regression criterion types in PortfolioOptimisers.jl.

All concrete types representing criteria for stepwise regression algorithms should subtype AbstractStepwiseRegressionCriterion. These criteria are used to evaluate model quality and guide variable selection during stepwise regression, such as AIC, BIC, or R².

Related

source
PortfolioOptimisers.AbstractRegressionTargetType
abstract type AbstractRegressionTarget <: AbstractRegressionAlgorithm end

Abstract supertype for all regression target types in PortfolioOptimisers.jl.

All concrete types representing regression targets (such as linear or generalised linear models) should subtype AbstractRegressionTarget. This enables flexible specification and dispatch of regression targets when constructing regression estimators.

Related

source
PortfolioOptimisers.LinearModelType
struct LinearModel{T1} <: AbstractRegressionTarget
    kwargs::T1
end

Regression target type for standard linear models in PortfolioOptimisers.jl.

LinearModel is used to specify a standard linear regression target (i.e., ordinary least squares) when constructing regression estimators. It encapsulates keyword arguments for configuring the underlying linear model fitting routine, enabling flexible extension and dispatch within the regression estimation framework.

Fields

  • kwargs::NamedTuple: Keyword arguments to be passed to the linear model fitting routine (e.g., options for the solver or regularisation).

Constructor

LinearModel(; kwargs::NamedTuple = (;))

Construct a LinearModel regression target with optional keyword arguments for model fitting.

Related

source
StatsAPI.fitMethod
StatsAPI.fit(target::LinearModel, X::AbstractMatrix, y::AbstractVector)

Fit a standard linear regression model using a LinearModel regression target.

This method dispatches to StatsAPI.fit with the GLM.LinearModel type, passing the design matrix X, response vector y, and any keyword arguments stored in target.kwargs. It enables flexible configuration of the underlying linear model fitting routine within the PortfolioOptimisers.jl regression estimation framework.

Arguments

  • target::LinearModel: A LinearModel regression target specifying model options.
  • X::AbstractMatrix: The design matrix (observations × features).
  • y::AbstractVector: The response vector.

Returns

  • GLM.LinearModel: A fitted linear model object from the GLM.jl package.

Related

source
PortfolioOptimisers.GeneralisedLinearModelType
struct GeneralisedLinearModel{T1, T2} <: AbstractRegressionTarget
    args::T1
    kwargs::T2
end

Regression target type for generalised linear models (GLMs) in PortfolioOptimisers.jl.

GeneralisedLinearModel is used to specify a generalised linear regression target (e.g., logistic, Poisson, etc.) when constructing regression estimators. It encapsulates positional and keyword arguments for configuring the underlying GLM fitting routine, enabling flexible extension and dispatch within the regression estimation framework.

Fields

  • args::Tuple: Positional arguments to be passed to the GLM fitting routine (e.g., distribution and link).
  • kwargs::NamedTuple: Keyword arguments for the GLM fitting routine (e.g., solver options, regularisation).

Constructor

GeneralisedLinearModel(; args::Tuple = (Normal(),), kwargs::NamedTuple = (;))

Construct a GeneralisedLinearModel regression target with optional arguments for model fitting.

Related

source
StatsAPI.fitMethod
StatsAPI.fit(target::GeneralisedLinearModel, X::AbstractMatrix, y::AbstractVector)

Fit a generalised linear regression model using a GeneralisedLinearModel regression target.

This method dispatches to StatsAPI.fit with the GLM.GeneralizedLinearModel type, passing the design matrix X, response vector y, any positional arguments in target.args, and any keyword arguments in target.kwargs. This enables flexible configuration of the underlying GLM fitting routine within the PortfolioOptimisers.jl regression estimation framework.

Arguments

  • target::GeneralisedLinearModel: A GeneralisedLinearModel regression target specifying model options.
  • X::AbstractMatrix: The design matrix (observations × features).
  • y::AbstractVector: The response vector.

Returns

  • GLM.GeneralizedLinearModel: A fitted generalised linear model object from the GLM.jl package.

Related

source
PortfolioOptimisers.AbstractMinValStepwiseRegressionCriterionType
abstract type AbstractMinValStepwiseRegressionCriterion <: AbstractStepwiseRegressionCriterion end

Abstract supertype for all stepwise regression criteria where lower values indicate better model fit in PortfolioOptimisers.jl.

All concrete types implementing minimisation-based stepwise regression criteria (such as AIC, AICC, or BIC) should subtype AbstractMinValStepwiseRegressionCriterion. These criteria are used to guide variable selection in stepwise regression algorithms by minimising the criterion value.

Related

source
PortfolioOptimisers.AbstractMaxValStepwiseRegressionCriteriaType
abstract type AbstractMaxValStepwiseRegressionCriteria <: AbstractStepwiseRegressionCriterion end

Abstract supertype for all stepwise regression criteria where higher values indicate better model fit in PortfolioOptimisers.jl.

All concrete types implementing maximisation-based stepwise regression criteria (such as R² or Adjusted R²) should subtype AbstractMaxValStepwiseRegressionCriteria. These criteria are used to guide variable selection in stepwise regression algorithms by maximising the criterion value.

Related

source
PortfolioOptimisers.RSquaredType
struct RSquared <: AbstractMaxValStepwiseRegressionCriteria end

Coefficient of determination (R²) for stepwise regression in PortfolioOptimisers.jl.

RSquared is a maximisation-based criterion used to evaluate model quality in stepwise regression algorithms. Higher values indicate better model fit, representing the proportion of variance explained by the model.

Related

source
PortfolioOptimisers.AdjustedRSquaredType
struct AdjustedRSquared <: AbstractMaxValStepwiseRegressionCriteria end

Adjusted coefficient of determination (Adjusted R²) for stepwise regression in PortfolioOptimisers.jl.

AdjustedRSquared is a maximisation-based criterion that adjusts R² for the number of predictors in the model, providing a more accurate measure of model quality when comparing models with different numbers of predictors.

Related

source
PortfolioOptimisers.regression_criterion_funcFunction
regression_criterion_func(::AbstractStepwiseRegressionCriterion)

Return the function used to compute the value of a stepwise regression criterion.

This utility dispatches on the concrete criterion subtype of AbstractStepwiseRegressionCriterion, returning the corresponding function from GLM.jl. Used internally by stepwise regression algorithms to evaluate model quality.

Arguments

  • criterion: A stepwise regression criterion type (e.g., AIC(), BIC(), RSquared()).

Returns

  • f::Function: The function that computes the criterion value for a fitted model.

Related

source
PortfolioOptimisers.RegressionType
struct Regression{T1, T2, T3} <: AbstractRegressionResult
    M::T1
    L::T2
    b::T3
end

Container type for regression results in PortfolioOptimisers.jl.

Regression stores the results of a regression-based moment estimation, including the main coefficient matrix, an optional auxiliary matrix, and the intercept vector. This type is used as the standard output for regression estimators, enabling consistent downstream processing and analysis.

Fields

  • M::AbstractMatrix: Main coefficient matrix (e.g., regression weights or loadings).
  • L::Union{Nothing, AbstractMatrix}: Optional auxiliary matrix for recovering lost dimensions in dimensionality reduction regressions.
  • b::AbstractVector: Optional intercept vector.

Constructor

Regression(; M::AbstractMatrix, L::Union{Nothing, <:AbstractMatrix} = nothing,
             b::Union{Nothing, <:AbstractVector} = nothing)

Construct a Regression result object with the specified coefficient matrix, optional auxiliary matrix, and intercept vector.

Related

source
PortfolioOptimisers.regressionFunction
regression(re::Regression, args...)

Return the regression result object unchanged.

This method is a pass-through for Regression result objects, allowing generic code to call regression on a result and receive the same object. It enables a unified interface for both estimator and result types.

Arguments

  • re::Regression: A regression result object.
  • args...: Additional arguments (ignored).

Returns

  • The input re, unchanged.

Related

source
regression(re::AbstractRegressionEstimator, rd::ReturnsResult)

Compute or extract a regression result from an estimator or result and a ReturnsResult.

This method dispatches to regression(re, rd.X, rd.F), allowing both regression estimators and regression result objects to be used interchangeably in generic workflows. If re is an estimator, it computes the regression result using the data in rd. If re is already a result, it is returned unchanged.

Arguments

  • re::AbstractRegressionEstimator: A regression estimator or result object.
  • rd::ReturnsResult: A returns result object containing data matrices X and F.

Returns

  • Regression: The computed or extracted regression result.

Related

source
regression(re::StepwiseRegression{<:PValue, <:Forward}, x::AbstractVector, F::AbstractMatrix)

Perform forward stepwise regression using a p-value criterion.

This method implements forward selection for stepwise regression, where variables (columns of F) are added to the model one at a time based on their statistical significance (p-value), starting from an empty model. At each step, the variable with the lowest p-value (and all p-values below the specified threshold) is added. The process continues until no remaining variable meets the p-value threshold. If no variable meets the threshold at any step, the variable with the lowest p-value is included to ensure at least one variable is selected.

Arguments

  • re::StepwiseRegression{<:PValue, <:Forward}: Stepwise regression estimator with a PValue criterion and Forward algorithm.
  • x::AbstractVector: Response vector.
  • F::AbstractMatrix: Feature matrix (observations × variables).

Returns

  • included::Vector{Int}: Indices of variables selected by the forward stepwise regression.

Details

  • At each iteration, the method fits a regression model for each excluded variable, computes p-values, and adds the variable with the lowest p-value if it is below the threshold.
  • If no variable meets the threshold, the variable with the lowest p-value is included (see add_best_asset_after_failure_pval!).
  • The process stops when no further variables can be added under the criterion.

Related

source
PortfolioOptimisers.regression_viewFunction
regression_view(re::Regression, i::AbstractVector)

Return a view of a Regression result object, selecting only the rows indexed by i.

This function constructs a new Regression result, where the coefficient matrix M, optional auxiliary matrix L, and intercept vector b are restricted to the rows specified by the index vector i. This is useful for extracting or operating on a subset of regression results, such as for a subset of assets or features.

Arguments

  • re::Regression: A regression result object.
  • i::AbstractVector: Indices of the rows to select.

Returns

  • Regression: A new regression result object with fields restricted to the selected rows.

Examples

julia> re = Regression(; M = [1 2; 3 4; 5 6], L = [10 20; 30 40; 50 60], b = [7, 8, 9])
Regression
  M | 3×2 Matrix{Int64}
  L | 3×2 Matrix{Int64}
  b | Vector{Int64}: [7, 8, 9]

julia> PortfolioOptimisers.regression_view(re, [1, 3])
Regression
  M | 2×2 SubArray{Int64, 2, Matrix{Int64}, Tuple{Vector{Int64}, Base.Slice{Base.OneTo{Int64}}}, false}
  L | 2×2 SubArray{Int64, 2, Matrix{Int64}, Tuple{Vector{Int64}, Base.Slice{Base.OneTo{Int64}}}, false}
  b | SubArray{Int64, 1, Vector{Int64}, Tuple{Vector{Int64}}, false}: [7, 9]

Related

source
regression_view(re::Union{Nothing, <:AbstractRegressionEstimator}, args...)

No-op fallback for regression_view when the input is nothing or an AbstractRegressionEstimator.

This method returns the input re unchanged. It is used internally to allow generic code to call regression_view without needing to check for nothing or estimator types, ensuring graceful handling of missing or non-result regression objects.

Arguments

  • re::Union{Nothing, <:AbstractRegressionEstimator}: Either nothing or a regression estimator type.
  • args...: Additional arguments (ignored).

Returns

  • The input re, unchanged.

Related

source