Regression
PortfolioOptimisers.LinearModel Type
struct LinearModel{T1} <: AbstractRegressionTarget
kwargs::T1
endRegression 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: Keyword arguments to be passed to the linear model fitting routine (e.g., options for the solver or regularisation).
Constructor
LinearModel(; kwargs::NamedTuple = (;))Keyword arguments correspond to the fields above.
Examples
julia> LinearModel()
LinearModel
kwargs ┴ @NamedTuple{}: NamedTuple()Related
sourceStatsAPI.fit Method
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: Regression target specifying model options.X: The design matrix (observations × features).y: The response vector.
Returns
GLM.LinearModel: A fitted linear model object from the GLM.jl package.
Related
sourcePortfolioOptimisers.GeneralisedLinearModel Type
struct GeneralisedLinearModel{T1, T2} <: AbstractRegressionTarget
args::T1
kwargs::T2
endRegression 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: Positional arguments to be passed to the GLM fitting routine (e.g., distribution and link).kwargs: Keyword arguments for the GLM fitting routine (e.g., solver options, regularisation).
Constructor
GeneralisedLinearModel(; args::Tuple = (Normal(),), kwargs::NamedTuple = (;))Keyword arguments correspond to the fields above.
Examples
julia> GeneralisedLinearModel()
GeneralisedLinearModel
args ┼ Tuple{Distributions.Normal{Float64}}: (Distributions.Normal{Float64}(μ=0.0, σ=1.0),)
kwargs ┴ @NamedTuple{}: NamedTuple()Related
sourceStatsAPI.fit Method
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: AGeneralisedLinearModelregression target specifying model options.X: The design matrix (observations × features).y: The response vector.
Returns
GLM.GeneralizedLinearModel: A fitted generalised linear model object from the GLM.jl package.
Related
sourcePortfolioOptimisers.AIC Type
struct AIC <: AbstractMinValStepwiseRegressionCriterion endAkaike Information Criterion (AIC) for stepwise regression in PortfolioOptimisers.jl.
AIC is a minimisation-based criterion used to evaluate model quality in stepwise regression algorithms. Lower values indicate better model fit, penalising model complexity to avoid overfitting.
Related
sourcePortfolioOptimisers.AICC Type
struct AICC <: AbstractMinValStepwiseRegressionCriterion endCorrected Akaike Information Criterion (AICC) for stepwise regression in PortfolioOptimisers.jl.
AICC is a minimisation-based criterion similar to AIC, but includes a correction for small sample sizes. Lower values indicate better model fit, balancing fit and complexity.
Related
sourcePortfolioOptimisers.BIC Type
struct BIC <: AbstractMinValStepwiseRegressionCriterion endBayesian Information Criterion (BIC) for stepwise regression in PortfolioOptimisers.jl.
BIC is a minimisation-based criterion used to evaluate model quality in stepwise regression algorithms. It penalises model complexity more strongly than AIC. Lower values indicate better model fit.
Related
sourcePortfolioOptimisers.RSquared Type
struct RSquared <: AbstractMaxValStepwiseRegressionCriteria endCoefficient 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
sourcePortfolioOptimisers.AdjustedRSquared Type
struct AdjustedRSquared <: AbstractMaxValStepwiseRegressionCriteria endAdjusted 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
sourcePortfolioOptimisers.Regression Type
struct Regression{T1, T2, T3} <: AbstractRegressionResult
M::T1
L::T2
b::T3
endContainer 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: Main coefficient matrix (e.g., regression weights or loadings).L: Optional auxiliary matrix for recovering lost dimensions in dimensionality reduction regressions.b: Optional intercept vector.
Constructor
Regression(; M::AbstractMatrix, L::Union{Nothing, <:AbstractMatrix} = nothing,
b::Union{Nothing, <:AbstractVector} = nothing)Keyword arguments correspond to the fields above.
Validation
!isempty(M).If provided,
!isempty(b), andlength(b) == size(M, 1).If provided,
!isempty(L), andsize(L, 1) == size(M, 1).
Examples
julia> Regression(; M = [1 2 3; 4 5 6], L = [1 2 3 4; 5 6 7 8], b = [1, 2])
Regression
M ┼ 2×3 Matrix{Int64}
L ┼ 2×4 Matrix{Int64}
b ┴ Vector{Int64}: [1, 2]Related
sourcePortfolioOptimisers.regression Method
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: A regression result object.args...: Additional arguments (ignored).
Returns
- The input
re, unchanged.
Related
sourcePortfolioOptimisers.regression Method
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: A regression estimator or result object.rd: A returns result object containing data matricesXandF.
Returns
Regression: The computed or extracted regression result.
Related
sourcePortfolioOptimisers.AbstractRegressionEstimator Type
abstract type AbstractRegressionEstimator <: AbstractEstimator endAbstract supertype for all regression estimator types in PortfolioOptimisers.jl.
All concrete types implementing regression estimation algorithms should subtype AbstractRegressionEstimator. This enables a consistent interface for regression-based moment estimation throughout the package.
Related
sourcePortfolioOptimisers.AbstractRegressionResult Type
abstract type AbstractRegressionResult <: AbstractResult endAbstract 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
sourcePortfolioOptimisers.AbstractRegressionAlgorithm Type
abstract type AbstractRegressionAlgorithm <: AbstractAlgorithm endAbstract 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
PortfolioOptimisers.AbstractStepwiseRegressionAlgorithm Type
abstract type AbstractStepwiseRegressionAlgorithm <: AbstractRegressionAlgorithm endAbstract 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
sourcePortfolioOptimisers.AbstractStepwiseRegressionCriterion Type
abstract type AbstractStepwiseRegressionCriterion <: AbstractRegressionAlgorithm endAbstract 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
sourcePortfolioOptimisers.AbstractRegressionTarget Type
abstract type AbstractRegressionTarget <: AbstractRegressionAlgorithm endAbstract 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
sourcePortfolioOptimisers.AbstractMinValStepwiseRegressionCriterion Type
abstract type AbstractMinValStepwiseRegressionCriterion <:
AbstractStepwiseRegressionCriterion endAbstract 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
sourcePortfolioOptimisers.AbstractMaxValStepwiseRegressionCriteria Type
abstract type AbstractMaxValStepwiseRegressionCriteria <:
AbstractStepwiseRegressionCriterion endAbstract 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
sourcePortfolioOptimisers.regression_view Function
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: A regression result object.i: 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
sourceregression_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: Eithernothingor a regression estimator type.args...: Additional arguments (ignored).
Returns
- The input
re, unchanged.
Related
sourcePortfolioOptimisers.regression_criterion_func Function
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