Skip to content
13

Base Cross Validation

PortfolioOptimisers.CrossValidationEstimator Type
julia
abstract type CrossValidationEstimator <: AbstractEstimator

Abstract supertype for all cross-validation estimators in PortfolioOptimisers.jl.

Related

source
PortfolioOptimisers.CrossValidationResult Type
julia
abstract type CrossValidationResult <: AbstractResult

Abstract supertype for all cross-validation result types in PortfolioOptimisers.jl.

Related

source
Base.split Method
julia
split(
    res::CrossValidationResult,
    args...
) -> CrossValidationResult

Identity split for CrossValidationResult. Returns the result unchanged, used as a no-op fallback when splitting is not applicable.

source
PortfolioOptimisers.CrossValidationAlgorithm Type
julia
abstract type CrossValidationAlgorithm <: AbstractAlgorithm

Abstract supertype for all cross-validation algorithm types.

source
PortfolioOptimisers.CVER Type
julia
const CVER = Union{<:CrossValidationEstimator, <:CrossValidationResult}

Union of all cross-validation estimators and result types.

source
PortfolioOptimisers.OptimisationCrossValidationEstimator Type
julia
abstract type OptimisationCrossValidationEstimator <: CrossValidationEstimator

Abstract supertype for cross-validation estimators used in portfolio optimisation. Subtypes implement different splitting strategies (sequential or non-sequential) for out-of-sample testing of optimisation pipelines.

Related

source
PortfolioOptimisers.SequentialCrossValidationEstimator Type
julia
abstract type SequentialCrossValidationEstimator <: OptimisationCrossValidationEstimator

Abstract supertype for sequential optimisation cross-validation estimators. Sequential schemes produce time-ordered, non-overlapping folds (e.g. walk-forward).

Related

source
PortfolioOptimisers.NonSequentialCrossValidationEstimator Type
julia
abstract type NonSequentialCrossValidationEstimator <: OptimisationCrossValidationEstimator

Abstract supertype for non-sequential optimisation cross-validation estimators. Non- sequential schemes may produce randomly sampled or combinatorial folds.

Related

source
PortfolioOptimisers.OptimisationCrossValidationResult Type
julia
abstract type OptimisationCrossValidationResult <: CrossValidationResult

Abstract supertype for all optimisation cross-validation result types.

Related

source
PortfolioOptimisers.SequentialCrossValidationResult Type
julia
abstract type SequentialCrossValidationResult <: OptimisationCrossValidationResult

Abstract supertype for sequential optimisation cross-validation results.

Related

source
PortfolioOptimisers.NonSequentialCrossValidationResult Type
julia
abstract type NonSequentialCrossValidationResult <: OptimisationCrossValidationResult

Abstract supertype for non-sequential optimisation cross-validation results.

Related

source
PortfolioOptimisers.OptCVER Type
julia
const OptCVER

Union of all optimisation cross-validation estimators and results.

source
PortfolioOptimisers.NonSeqCVER Type
julia
const NonSeqCVER

Union of all non-sequential cross-validation estimators and results.

source
PortfolioOptimisers.SeqCVER Type
julia
const SeqCVER

Union of all sequential cross-validation estimators and results.

source
PortfolioOptimisers.NonOptimisationCrossValidationEstimator Type
julia
abstract type NonOptimisationCrossValidationEstimator <: CrossValidationEstimator

Abstract supertype for cross-validation estimators used in non-optimisation contexts (e.g. resampling for hierarchical clustering or phylogeny methods).

Related

source
PortfolioOptimisers.NonOptimisationSequentialCrossValidationEstimator Type
julia
abstract type NonOptimisationSequentialCrossValidationEstimator <: NonOptimisationCrossValidationEstimator

Abstract supertype for sequential non-optimisation cross-validation estimators.

source
PortfolioOptimisers.NonOptimisationNonSequentialCrossValidationEstimator Type
julia
abstract type NonOptimisationNonSequentialCrossValidationEstimator <: NonOptimisationCrossValidationEstimator

Abstract supertype for non-sequential non-optimisation cross-validation estimators.

source
PortfolioOptimisers.NonOptimisationCrossValidationResult Type
julia
abstract type NonOptimisationCrossValidationResult <: CrossValidationResult

Abstract supertype for result types produced by non-optimisation cross-validation routines.

source
PortfolioOptimisers.NonOptimisationSequentialCrossValidationResult Type
julia
abstract type NonOptimisationSequentialCrossValidationResult <: NonOptimisationCrossValidationResult

Abstract supertype for sequential non-optimisation cross-validation result types.

source
PortfolioOptimisers.NonOptimisationNonSequentialCrossValidationResult Type
julia
abstract type NonOptimisationNonSequentialCrossValidationResult <: NonOptimisationCrossValidationResult

Abstract supertype for non-sequential non-optimisation cross-validation result types.

source
PortfolioOptimisers.AbstractPredictionResult Type
julia
abstract type AbstractPredictionResult <: AbstractResult

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

All concrete prediction result types from cross-validation should subtype AbstractPredictionResult.

Related

source
PortfolioOptimisers.PredictionReturnsResult Type
julia
struct PredictionReturnsResult{__T_nx, __T_X, __T_nf, __T_F, __T_nb, __T_B, __T_ts, __T_iv, __T_ivpa} <: AbstractReturnsResult

Stores the portfolio returns data associated with a cross-validation prediction. Packages asset returns, factor returns, benchmark returns, timestamps, and investment vehicle information for use in prediction result types.

Fields

  • nx: Asset name vector.

  • X: Data matrix observations × features if the dims keyword does not exist or dims = 1, features × observations when dims = 2.

  • nf: Factor name vector.

  • F: Data matrix observations × factors if the dims keyword does not exist or dims = 1, factors × observations when dims = 2.

  • nb: Benchmark name vector.

  • B: Benchmark returns.

  • ts: Timestamp vector.

  • iv: Investment vehicle returns.

  • ivpa: Investment vehicle per-asset allocation.

Constructors

julia
PredictionReturnsResult(;
    nx::Option{<:VecStr} = nothing,
    X::Option{<:VecNum_VecVecNum} = nothing,
    nf::Option{<:VecStr} = nothing,
    F::Option{<:MatNum} = nothing,
    nb::Option{<:VecStr} = nothing,
    B::Option{<:VecNum_VecVecNum} = nothing,
    ts::Option{<:VecDate} = nothing,
    iv::Option{<:VecNum_VecVecNum} = nothing,
    ivpa::Option{<:Num_VecNum} = nothing
) -> PredictionReturnsResult

Keywords correspond to the struct's fields.

Validation

  • nf and F must be consistent (both nothing, or F has length(nf) columns).

  • If X and F provided: row count of F matches length of each X vector.

  • If B and X provided: same type (VecNum/VecVecNum) and matching lengths.

  • If ts provided: !isempty(ts); at least one of X, F is not nothing; lengths of ts match X, F, and B where applicable.

  • If iv is a VecNum: ivpa is scalar or nothing; iv is non-empty, non-negative, and finite; length(iv) == length(X).

  • If iv is a VecVecNum: ivpa is VecNum or nothing; length(iv) == length(X) == length(ivpa); each sub-vector non-empty, non-negative, finite, and same length as corresponding X.

Related

source
PortfolioOptimisers.PredictionResult Type
julia
struct PredictionResult{__T_res, __T_rd} <: AbstractPredictionResult

Stores the result of a single cross-validation fold prediction. Pairs an optimisation result with the returns data from the test period.

Fields

  • res: Optimisation result from the training fold.

  • rd: The returns result to use.

Related

source
PortfolioOptimisers.VecPredRes Type
julia
const VecPredRes = AbstractVector{<:PredictionResult}

Alias for a vector of single-fold prediction results.

Represents a collection of PredictionResult objects from cross-validation folds.

Related

source
PortfolioOptimisers.PredRes_MultiPredRes Type
julia
const PredRes_MultiPredRes = Union{<:PredictionResult, <:MultiPeriodPredictionResult}

Alias for a single-fold or multi-period prediction result.

Matches either a PredictionResult or a MultiPeriodPredictionResult.

Related

source
PortfolioOptimisers.mapreduce_RetMtx Function
julia
mapreduce_RetMtx(rd, sym = :X)

Concatenate return matrices from a vector of PredictionReturnsResult objects.

Internal helper that vertically concatenates the field sym across all elements of rd. Handles both single-asset (vector) and multi-asset (vector of vectors) return data.

Arguments

Returns

  • Concatenated return matrix or vector of vectors.
source
PortfolioOptimisers.MultiPeriodPredictionResult Type
julia
struct MultiPeriodPredictionResult{__T_pred, __T_mrd, __T_id} <: AbstractPredictionResult

Stores predictions from multiple cross-validation folds as a single combined result. Concatenates the test-period returns from all folds into an aggregated PredictionReturnsResult.

Fields

  • pred: Collection of fold predictions.

  • mrd: Aggregated multi-period returns result.

  • id: Path or fold identifier.

Related

source
Base.getproperty Method
julia
getproperty(
    mpred::MultiPeriodPredictionResult,
    sym::Symbol
) -> Any

Access properties of MultiPeriodPredictionResult. Virtual properties :res and :rd broadcast over the inner pred vector, collecting per-fold results and relative drawdowns.

source
PortfolioOptimisers.VecMPredRes Type
julia
const VecMPredRes = AbstractVector{<:MultiPeriodPredictionResult}

Alias for a vector of multi-period prediction results.

Represents a collection of MultiPeriodPredictionResult objects.

Related

source
PortfolioOptimisers.PopulationPredictionResult Type
julia
struct PopulationPredictionResult{__T_pred} <: AbstractPredictionResult

Stores a collection of multi-period prediction results produced by a population-based cross-validation scheme (e.g. MultipleRandomised). Each element of pred represents one random asset-subset path.

Fields

  • pred: Collection of fold predictions.

Related

source
StatsAPI.predict Method
julia
predict(res::NonFiniteAllocationOptimisationResult, rd::ReturnsResult)
predict(res, rd, test_idx, cols = :)
predict(res, rd, test_idxs::VecVecInt, cols = :)

Apply an optimisation result res to returns data rd to produce a PredictionResult or a vector of prediction results.

When test_idx is provided, only the rows (observations) indexed by test_idx (and optionally columns cols) of rd are used for the prediction.

Arguments

  • res::NonFiniteAllocationOptimisationResult: Fitted optimisation result.

  • rd::ReturnsResult: Returns data for the prediction period.

  • test_idx: Observation index or vector of observation indices for the test fold.

  • cols: Column selector. Defaults to : (all assets).

Returns

Related

source
PortfolioOptimisers.fit_predict Function
julia
fit_predict(opt, rd::ReturnsResult)

Fit optimisation estimator opt on returns data rd and immediately produce a PredictionResult for the same data.

Arguments

  • opt: Optimisation estimator or result.

  • rd::ReturnsResult: Returns data.

Returns

Related

source
PortfolioOptimisers.sort_by_measure Function
julia
sort_by_measure(ppred::PopulationPredictionResult, r::AbstractBaseRiskMeasure; kwargs...)

Sort the successful paths in a PopulationPredictionResult by their expected risk under r. Paths where any fold returned a non-success retcode are excluded.

Arguments

  • ppred::PopulationPredictionResult: Population prediction to sort.

  • r::AbstractBaseRiskMeasure: Risk measure used for ranking.

Returns

  • Vector{MultiPeriodPredictionResult}: Sorted vector of successful path predictions.

Related

source
PortfolioOptimisers.quantile_by_measure Function
julia
quantile_by_measure(ppred::PopulationPredictionResult, r::AbstractBaseRiskMeasure, q::Real;
                    r_kwargs::NamedTuple = (;), q_kwargs::NamedTuple = (;))

Select the successful path in ppred whose expected risk under r is closest to the q-th quantile of the risk distribution across all successful paths.

Arguments

  • ppred::PopulationPredictionResult: Population prediction result.

  • r::AbstractBaseRiskMeasure: Risk measure for computing path risks.

  • q::Real: Quantile level in [0, 1].

  • r_kwargs::NamedTuple = (;): Keyword arguments forwarded to expected_risk.

  • q_kwargs::NamedTuple = (;): Keyword arguments forwarded to Statistics.quantile.

Returns

Related

source
PortfolioOptimisers.fit_and_predict Function
julia
fit_and_predict(opt, rd::ReturnsResult, cv::NonSeqCVER; cols, ex, id) -> MultiPeriodPredictionResult
fit_and_predict(opt, rd::ReturnsResult; train_idx, test_idx, cols) -> PredictionResult
fit_and_predict(res::NonFiniteAllocationOptimisationResult, rd::ReturnsResult; test_idx, cols) -> PredictionResult

Fit an optimisation estimator on training data and predict on test data using cross-validation.

The three-argument method (opt, rd, cv) performs full cross-validated prediction over all folds of cv. The two-argument methods operate on a single pre-defined train/test split or on a pre-existing result.

Arguments

  • opt: Optimisation estimator or an existing optimisation result.

  • rd::ReturnsResult: Full returns data.

  • cv::NonSeqCVER: Non-sequential cross-validation estimator (e.g. KFold or CombinatorialCrossValidation).

  • train_idx::VecInt: Training indices.

  • test_idx: Test indices (vector or vector of vectors).

  • cols: Column selector (default : for all assets).

Returns

Related

source
PortfolioOptimisers.reconstruct_rd Method
julia
reconstruct_rd(res::NonFiniteAllocationOptimisationResult, rd::ReturnsResult, X)

Reconstruct a PredictionReturnsResult from an optimisation result and returns data.

Computes benchmark, investment vehicle, and per-asset allocation data from the optimisation result weights and the original returns data.

Arguments

  • res::NonFiniteAllocationOptimisationResult: Fitted optimisation result.

  • rd::ReturnsResult: Original returns data.

  • X: Portfolio returns (vector or vector of vectors).

Returns

Related

source
PortfolioOptimisers.sort_predictions! Method
julia
sort_predictions!(res::Union{test_idx, CrossValidationResult}, pred::VecPredRes) -> VecPredRes

Sort prediction results to match the order of test indices.

Reorders predictions so that they align with the original time ordering of test_idx.

Arguments

  • res:

    • ::VecVecInt: Vector of test index vectors.

    • ::CrossValidationResult: Cross validation result object, uses the test indices stored in res.test_idx.

  • pred: Vector of prediction results.

Returns

  • Sorted predictions vector.

Related

source
PortfolioOptimisers.VecVecPredRes Type
julia
const VecVecPredRes = AbstractVector{<:VecPredRes}

Alias for a vector of vectors of prediction results.

Represents the outer collection of cross-validation paths, where each inner vector contains prediction results from a single path.

Related

source
PortfolioOptimisers.VecPredRes_MultiPredRes Type
julia
const VecPredRes_MultiPredRes = AbstractVector{<:PredRes_MultiPredRes}

Alias for a vector of single-fold or multi-period prediction results.

Represents a collection of PredRes_MultiPredRes elements.

Related

source