Portfolio report

PortfolioOptimisers.portfolio_report — Function
portfolio_report(preds::AbstractVector{<:AbstractPredictionResult};
                 names::Option{<:AbstractVector{<:AbstractString}} = nothing,
                 title::AbstractString = "Portfolio report",
                 groups::Option{<:AbstractVector} = nothing,
                 meta::Option{<:AbstractVector} = nothing,
                 allocs::Option{<:AbstractVector} = nothing,
                 sets::Union{Nothing, UniverseSets, AbstractVector} = nothing,
                 taxonomy::AbstractVector{<:AbstractString} = String[],
                 overview_figures = (), entry_figures = (),
                 weight_threshold::Real = 1e-6, kwargs...) -> Report
portfolio_report(pred::AbstractPredictionResult; name::AbstractString = "Portfolio",
                 group::Option{<:AbstractString} = nothing,
                 meta::Option{<:AbstractVector{<:Pair}} = nothing, alloc = nothing,
                 kwargs...) -> Report

Build a Portfolio Report that compares prediction results: one entry for each prediction, and an overview table of their statistics.

Each element of preds is one candidate, and one entry of the report. A candidate can be a single fold, a PredictionResult, a walk-forward path, a MultiPeriodPredictionResult, or a population of paths, a PopulationPredictionResult. The builder does not split a candidate: the paths of a population and the members of a prediction whose optimiser gives many portfolios are rows inside its entry. The second method builds the report of one prediction.

The overview

The overview holds the table of DataFrames.DataFrame(ps::PerformanceSummaryResult) of performance_summary(preds; names, kwargs...), with one row for each candidate, path and member. Every keyword of performance_summary other than names, such as measures, rf, ppy and benchmark, passes through kwargs. The report computes no figure of its own, so each statistic has one source. With groups, a group column comes first. A click on a row of the table in the HTML file shows the entry of its candidate. overview_figures adds one figure for each of its pairs, from the vector of predictions and their names.

The sections of an entry

  1. Statistics. A candidate with one row of the overview gives a table of two columns, the figure and its value. A candidate with many rows gives its rows as a sortable table. A population also gives the distribution of each figure over its paths: the count of finite values, the minimum, the 25 % quantile, the median, the 75 % quantile and the maximum. The distribution describes the columns of the summary, and it adds no statistic.
  2. Weights. One table for each member, from prediction_weights. A single fold gives one column of weights. A path gives one column for each fold, and a population one column for each path, after a mean column. The rows are sorted by the absolute value of the first column of weights. A row whose largest absolute weight is less than weight_threshold is not shown, and the caption gives the count of such rows.
  3. Exposure, when the entry has a UniverseSets and taxonomy names at least one taxonomy column: the sums of the weights of each group, as # The Exposure section states.
  4. Allocation, when the entry has a finite allocation result: the shares, the cost and the realised weight of each asset, with the cash that is left and the fees in the caption. A finite allocation is the allocation of one portfolio. For a path, it is the allocation of the target of the last fold, the portfolio to hold now.
  5. Figures, when entry_figures gives one: one figure for each of its pairs, from the prediction.

The Exposure section

A taxonomy column is a key of sets.dict, such as "nx_sector", that holds one group label for each asset of sets.dict[sets.xkey], in that order. asset_sets_matrix reads the same column. Each name of taxonomy gives one subsection, and each member of the prediction gives one table in it. The section reads the rows of prediction_weights, and it maps an asset to its label by name, so a fold that holds a part of the universe is correct. An asset that the universe does not name, or whose label is missing, counts in the group (none), so the groups of a row sum to its weights. The section computes no statistic other than the sums.

  • One row of weights, a single fold: one row for each group, with the columns long, the sum of the positive weights, short, the sum of the negative weights, and net, their sum. The rows are sorted by the absolute value of net, and the caption gives the gross exposure. With a finite allocation, the columns alloc_long, alloc_short and alloc_net sum the realised weights of the allocation in the same way.
  • Many rows of weights, a path or a population: one row for each fold of the path or each path of the population, with the column portfolio that holds the label of the row, one column of net exposure for each group, and the column gross. A group whose label is portfolio or gross takes the column name of its label with the first suffix _k, from _1 up, that no other column name holds. With a finite allocation of a path, the last row allocation sums the realised weights of the allocation.

The allocation is the allocation of the first member, as in the Allocation section. A NaN weight gives a NaN sum for its group, on both sides.

Figures

overview_figures and entry_figures are collections of pairs caption => f. An overview figure is f(preds, names), so a legend can name the predictions, and an entry figure is f(pred). Each gives a figure, or nothing, which adds no figure. A figure is any object that ReportFigure takes. The function takes the prediction as it is, so it can dispatch on its type. Both collections are empty by default, so a report with no plotting package is complete. With the plotting extension loaded, default_report_figures gives the default figures. A function that throws stops the build with its own error, and the builder does not hide the failure.

Arguments

  • preds: The predictions, one for each candidate.
  • pred: One prediction.
  • names: One name for each prediction, or nothing for "Portfolio 1", "Portfolio 2", …. The names must be unique.
  • name: The name of the prediction of the second method.
  • title: The title of the report.
  • groups, group: The group of each prediction, an AbstractString or nothing, or nothing for no groups. A group is a label of the caller.
  • meta: The labels of each entry, each a vector of pairs label => value or nothing, or nothing for none. The second method takes the labels of its one entry.
  • allocs, alloc: The finite allocation result of each prediction, a FiniteAllocationOptimisationResult or nothing, or nothing for none.
  • sets: The UniverseSets of every prediction, or the sets of each prediction, a UniverseSets or nothing, or nothing for no Exposure section.
  • taxonomy: The names of the taxonomy columns of sets, as stated in # The Exposure section. An empty vector gives no Exposure section.
  • overview_figures, entry_figures: The figures, as stated in # Figures.
  • weight_threshold: The least absolute weight that a row of a weights table shows.
  • kwargs...: The keywords of performance_summary.

Validation

  • preds is not empty. Otherwise the function raises an IsEmptyError.
  • names, groups, meta and allocs have the length of preds, and so does sets when it is a vector. Otherwise the function raises a DimensionMismatch that names the keyword.
  • Each name of taxonomy is a key of the sets of an entry that has sets. Otherwise the function raises a KeyError, through taxonomy_column.
  • A taxonomy column has the length of sets.dict[sets.xkey]. Otherwise the function raises a DimensionMismatch.
  • The names are unique. Otherwise the function raises an ArgumentError.
  • Each element of overview_figures and entry_figures is a pair whose first part is an AbstractString. Otherwise the function raises an ArgumentError.
  • weight_threshold is finite and not negative. Otherwise the function raises a DomainError.
  • The length of the shares of an allocation is the number of assets of the portfolio that it allocates. Otherwise the function raises a DimensionMismatch.
  • A population has no allocation, because it holds no single portfolio. Otherwise the function raises an ArgumentError.
  • The rules of performance_summary.

Returns

  • r::Report: The report.

Related

source