Combinatorial: private API

PortfolioOptimisers.test_set_indexMethod
test_set_index(ccv)

Generate all test set index combinations for combinatorial cross-validation.

Each element is one split's test set, given as the n_test_folds fold indices it holds. The elements are fold indices, not observation indices, and the splits come in the order Combinatorics.combinations enumerates them.

Arguments

Returns

  • Vector{Vector{Int}} of length n_splits.

Related

source
PortfolioOptimisers.binary_train_test_setsMethod
binary_train_test_sets(ccv)

Generate the binary train/test fold assignment matrix for combinatorial cross-validation.

The rows are folds and the columns are splits. An entry is true when that fold is a test fold of that split, and false when it is a training fold. The assignment is over folds, not over observations.

Arguments

Returns

  • BitMatrix of size (n_folds, n_splits).

Related

source
PortfolioOptimisers.get_path_idsMethod
get_path_ids(ccv)

Get path identifiers for each test fold of each split in combinatorial cross-validation.

This is the transpose of the view recombined_paths gives. The rows are the test folds of a split and the columns are splits. Entry (m, j) is the path that the m-th test block of split j belongs to, where the blocks of a split are counted in ascending observation order. This is the path_ids field of CombinatorialCrossValidationResult, and it is what pairs each block of test_idx[j] with its path.

Arguments

Returns

  • Matrix{Int} of size (n_test_folds, n_splits).

Related

source
PortfolioOptimisers.n_test_pathsFunction
n_test_paths(n_folds, n_test_folds)
n_test_paths(ccv::CombinatorialCrossValidation)

Compute the number of test paths in combinatorial cross-validation.

Returns the number of unique recombined test paths from n_folds folds choosing n_test_folds test folds. Also accepts a CombinatorialCrossValidation object directly.

The count is div(binomial(n_folds, n_test_folds) * n_test_folds, n_folds), which is the $\varphi(n,\, k)$ of CombinatorialCrossValidation. Each fold is a test fold in the same number of splits, so the test blocks recombine into exactly this many paths, and each path covers every observation once.

Arguments

  • n_folds: Total number of folds.
  • n_test_folds: Number of test folds per combination.
  • ccv: CombinatorialCrossValidation configuration, which supplies both counts.

Returns

  • Integer number of test paths.

Related

source
PortfolioOptimisers.average_train_sizeFunction
average_train_size(T, n_folds, n_test_folds)
average_train_size(ccv::CombinatorialCrossValidation, rd::Prices_RR)

Compute the average training set size for combinatorial cross-validation.

The count is T / n_folds * (n_folds - n_test_folds), taken before purging and embargoing, so the training set of a split with a non-zero purged_size or embargo_size is smaller than this.

Arguments

  • T: Total number of observations.
  • n_folds: Total number of folds.
  • n_test_folds: Number of test folds per combination.
  • ccv: CombinatorialCrossValidation configuration, which supplies n_folds and n_test_folds.
  • rd: Returns-level or price-level data, which supplies T through cv_nobs (Prices_RR).

Returns

  • Average number of training observations per split.

Related

source
PortfolioOptimisers.recombined_pathsFunction
recombined_paths(ccv)

Generate the recombined test paths for combinatorial cross-validation.

The rows are folds and the columns are paths. Entry (f, p) is the index of the split that supplies fold f to path p. Reading one column therefore names one split per fold, and those blocks together cover every observation exactly once.

Arguments

Returns

  • Matrix{Int} of size (n_folds, n_test_paths).

Related

source