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...) -> ReportBuild 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
- 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.
- 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 ameancolumn. The rows are sorted by the absolute value of the first column of weights. A row whose largest absolute weight is less thanweight_thresholdis not shown, and the caption gives the count of such rows. - Exposure, when the entry has a
UniverseSetsandtaxonomynames at least one taxonomy column: the sums of the weights of each group, as# The Exposure sectionstates. - 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.
- Figures, when
entry_figuresgives 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, andnet, their sum. The rows are sorted by the absolute value ofnet, and the caption gives the gross exposure. With a finite allocation, the columnsalloc_long,alloc_shortandalloc_netsum 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
portfoliothat holds the label of the row, one column of net exposure for each group, and the columngross. A group whose label isportfolioorgrosstakes the column name of its label with the first suffix_k, from_1up, that no other column name holds. With a finite allocation of a path, the last rowallocationsums 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, ornothingfor"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, anAbstractStringornothing, ornothingfor no groups. A group is a label of the caller.meta: The labels of each entry, each a vector of pairslabel => valueornothing, ornothingfor none. The second method takes the labels of its one entry.allocs,alloc: The finite allocation result of each prediction, aFiniteAllocationOptimisationResultornothing, ornothingfor none.sets: TheUniverseSetsof every prediction, or the sets of each prediction, aUniverseSetsornothing, ornothingfor no Exposure section.taxonomy: The names of the taxonomy columns ofsets, 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 ofperformance_summary.
Validation
predsis not empty. Otherwise the function raises anIsEmptyError.names,groups,metaandallocshave the length ofpreds, and so doessetswhen it is a vector. Otherwise the function raises aDimensionMismatchthat names the keyword.- Each name of
taxonomyis a key of the sets of an entry that has sets. Otherwise the function raises aKeyError, throughtaxonomy_column. - A taxonomy column has the length of
sets.dict[sets.xkey]. Otherwise the function raises aDimensionMismatch. - The names are unique. Otherwise the function raises an
ArgumentError. - Each element of
overview_figuresandentry_figuresis a pair whose first part is anAbstractString. Otherwise the function raises anArgumentError. weight_thresholdis finite and not negative. Otherwise the function raises aDomainError.- 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