Prediction weights

prediction_weights gives the weights of a prediction on asset names, with one row for each portfolio that the prediction holds: one fold, each fold of a path, or each path of a population. portfolio_report writes its weights tables from these rows.

PortfolioOptimisers.prediction_weights — Function
prediction_weights(pred::PredictionResult, j::Integer = 1)
prediction_weights(pred::MultiPeriodPredictionResult, j::Integer = 1)
prediction_weights(ppred::PopulationPredictionResult, j::Integer = 1)

The weights of member j of a prediction, on asset names, with one row for each portfolio that the prediction holds.

A single fold holds one portfolio, its target. A path holds one portfolio for each fold, its target at the start of the fold. A population holds one portfolio for each path, the mean of the fold targets of the path. Every target comes from fold_target, on the names rd.nx of its fold, so the weights sit on the universe that performance_summary reads for n_eff and turnover. The folds of a path and the paths of a population can hold different assets, so weights_by_name puts the rows on the union of their names, with a zero where a row does not hold an asset. A fold that failed to solve holds NaN weights, so its row is NaN at every name, and so is the row of a path that holds such a fold. Under a Weight Drift, a failed fold that the fold loop handed the previous weights holds those weights, and its row is that book. A fold whose returns data carries no names takes the positions of its weights as names.

portfolio_report writes the weights table of an entry from this function. The composition plots of a path and of a population draw the same rows.

Algorithm

  1. For a single fold, read the target w of member j, and give one row with the label "weight".
  2. For a path, read the target of member j of each fold, and embed the targets on the union of the fold names. The label of a row is the first timestamp of its fold, or "fold k" when the fold carries no timestamps.
  3. For a population, read the rows of each path as in steps 1 and 2, and take their mean over the rows. Embed the means on the union of the path names. The label of a row is the key of its path, population_path_key.

Arguments

  • pred, ppred: The prediction result.
  • j: The index of the member.

Validation

  • A population holds at least one path. Otherwise the function raises an IsEmptyError.

Returns

  • names::Vector: The asset names of the columns.
  • W::MatNum: One row for each portfolio, one column for each name.
  • labels::Vector{String}: The label of each row.

Related

source