Portfolio report: private API

PortfolioOptimisers.assert_report_length — Function
assert_report_length(x::Option{<:UniverseSets}, n::Integer, name::Symbol)
assert_report_length(x::AbstractVector, n::Integer, name::Symbol)

Check that a keyword of portfolio_report gives one value for each prediction.

One UniverseSets is the sets of every prediction, so it has no length to check.

Arguments

  • x: The values of the keyword, one UniverseSets, or nothing.
  • n: The number of predictions.
  • name: The name of the keyword.

Validation

  • length(x) == n. Otherwise the function raises a DimensionMismatch that names the keyword.

Returns

  • nothing.

Related

source
PortfolioOptimisers.report_figure_pairs — Function
report_figure_pairs(figs, name::Symbol) -> Vector

Check the figures of portfolio_report, and collect them into a vector of pairs caption => f.

Arguments

  • figs: A collection of pairs caption => f.
  • name: The name of the keyword.

Validation

  • Each element is a pair whose first part is an AbstractString. Otherwise the function raises an ArgumentError that names the keyword.

Returns

  • figs::Vector: The pairs, in order.

Related

source
PortfolioOptimisers.report_figures — Function
report_figures(figs::AbstractVector, args...) -> Vector{AbstractReportBlock}

The figures of a report: one ReportFigure for each pair caption => f of figs whose f(args...) is not nothing.

A function that throws stops the build with its own error.

Arguments

  • figs: The pairs, from report_figure_pairs.
  • args...: The prediction of an entry, or the vector of predictions of the overview and their names.

Returns

  • blocks::Vector{AbstractReportBlock}: The figures, in the order of figs.

Related

source
PortfolioOptimisers.overview_table — Function
overview_table(df::DataFrames.AbstractDataFrame, nm::AbstractVector,
               groups::Option{<:AbstractVector}) -> DataFrames.DataFrame

The table of the overview of a Portfolio Report: the summary table, with a group column first when the caller gives groups.

Arguments

  • df: The summary table.
  • nm: The name of each prediction.
  • groups: The group of each prediction, or nothing.

Returns

  • tab::DataFrames.DataFrame: The table.

Related

source
PortfolioOptimisers.entry_sections — Function
entry_sections(pred::AbstractPredictionResult, rows::DataFrames.AbstractDataFrame,
               alloc, threshold::Real, figs::AbstractVector,
               sets::Option{<:UniverseSets},
               taxonomy::AbstractVector{<:AbstractString}) -> Vector{ReportSection}

The sections of the entry of one prediction, in the order that portfolio_report states.

The Allocation section is built before the Exposure section, so the checks of the allocation run before the Exposure section reads it.

Arguments

  • pred: The prediction.
  • rows: The rows of the summary table of the prediction.
  • alloc: The finite allocation result of the prediction, or nothing.
  • threshold: The least absolute weight that a weights table shows.
  • figs: The figures of an entry, from report_figure_pairs.
  • sets: The UniverseSets of the prediction, or nothing.
  • taxonomy: The names of the taxonomy columns of sets.

Returns

  • sections::Vector{ReportSection}: Statistics, Weights, then Exposure, Allocation and Figures when the entry has them.

Related

source
PortfolioOptimisers.statistics_table — Function
statistics_table(rows::DataFrames.AbstractDataFrame) -> ReportTable

The table of the statistics of one prediction.

The name column is not shown, and the path and member columns are shown only when they hold a key. One row gives a table of two columns, the figure and its value. Many rows give a sortable table, one row for each path and member.

Arguments

  • rows: The rows of the summary table of the prediction.

Returns

  • tab::ReportTable: The table.

Related

source
PortfolioOptimisers.distribution_table — Function
distribution_table(rows::DataFrames.AbstractDataFrame) -> ReportTable

The distribution of each figure of a population over its paths.

A figure is a column of the summary table other than the keys and the dates. For each figure, the table gives the count of finite values, and the minimum, the 25 % quantile, the median, the 75 % quantile and the maximum of those values. A figure with no finite value shows empty cells.

Arguments

  • rows: The rows of the summary table of the population.

Returns

  • tab::ReportTable: The table, one row for each figure.

Related

source
PortfolioOptimisers.report_statistics — Function
report_statistics(pred::PredRes_MultiPredRes, rows::DataFrames.AbstractDataFrame)
report_statistics(pred::PopulationPredictionResult, rows::DataFrames.AbstractDataFrame)

The Statistics section of the entry of one prediction: its table of statistics, and for a population the distribution of each figure over its paths.

Arguments

  • pred: The prediction.
  • rows: The rows of the summary table of the prediction.

Returns

  • s::ReportSection: The section.

Related

source
PortfolioOptimisers.weights_table — Function
weights_table(names::AbstractVector, W::MatNum, labels::AbstractVector,
              threshold::Real, prefix::AbstractString) -> ReportTable

The weights table of one member of a prediction, from the rows of prediction_weights.

One row of W gives one column of weights. Many rows give a mean column, the mean over the rows, then one column for each row. The rows of the table are sorted by the absolute value of the first column of weights. A row whose largest absolute weight is less than threshold is not shown. A NaN weight is not less than threshold, so its row shows.

Arguments

  • names: The asset names.
  • W: The weights, one row for each portfolio of the prediction.
  • labels: The label of each row of W.
  • threshold: The least absolute weight that a row shows.
  • prefix: The start of the caption, which names the member.

Returns

  • tab::ReportTable: The table.

Related

source
PortfolioOptimisers.report_exposure — Function
report_exposure(pred::AbstractPredictionResult, sets::Nothing,
                taxonomy::AbstractVector, alloc)
report_exposure(pred::AbstractPredictionResult, sets::UniverseSets,
                taxonomy::AbstractVector{<:AbstractString}, alloc)

The Exposure section of the entry of one prediction, or nothing when the entry has no sets or taxonomy is empty.

The section holds one subsection for each name of taxonomy, from exposure_section, and each subsection holds one table for each member. portfolio_report states the content of the tables.

Arguments

  • pred: The prediction.
  • sets: The UniverseSets of the prediction, or nothing.
  • taxonomy: The names of the taxonomy columns of sets.
  • alloc: The finite allocation result of the prediction, or nothing. Its checks ran in report_allocation.

Returns

  • s::Option{<:ReportSection}: The section, or nothing.

Related

source
PortfolioOptimisers.exposure_section — Function
exposure_section(sets::UniverseSets, key::AbstractString, ws::AbstractVector,
                 aw::Option{<:Tuple}) -> ReportSection

The subsection of the Exposure section for one taxonomy column: one table for each member, from exposure_table. The allocation is the allocation of the first member, so only its table reads aw.

Arguments

Returns

  • s::ReportSection: The subsection.

Related

source
PortfolioOptimisers.allocation_weights — Function
allocation_weights(pred::AbstractPredictionResult, alloc::Nothing)
allocation_weights(pred::PredictionResult, alloc::FiniteAllocationOptimisationResult)
allocation_weights(pred::MultiPeriodPredictionResult, alloc::FiniteAllocationOptimisationResult)

The realised weights of a finite allocation on the names of the portfolio that it allocates, or nothing when the entry has no allocation.

A single fold reads the names of its weights, and a path reads the names of its last fold, as report_allocation does.

Arguments

  • pred: The prediction.
  • alloc: The finite allocation result, or nothing.

Returns

  • aw::Option{<:Tuple}: The pair (names, w), or nothing.

Related

source
PortfolioOptimisers.exposure_labels — Function
exposure_labels(sets::UniverseSets, key::AbstractString,
                names::AbstractVector) -> Vector{String}

The group label of each asset of names, from the taxonomy column sets.dict[key].

An asset maps to its label by name, through sets.dict[sets.xkey]. An asset that the universe does not name, or whose label is missing, takes the label (none).

Arguments

  • sets: The UniverseSets.
  • key: The name of the taxonomy column.
  • names: The asset names.

Validation

  • haskey(sets.dict, key), through taxonomy_column.
  • length(sets.dict[key]) == length(sets.dict[sets.xkey]). Otherwise the function raises a DimensionMismatch.

Returns

  • labels::Vector{String}: One label for each name.

Related

source
PortfolioOptimisers.exposure_sums — Function
exposure_sums(labels::AbstractVector{<:AbstractString}, w::AbstractVector,
              groups::AbstractVector{<:AbstractString}) -> Tuple

The long and the short sums of the weights w in each group of groups.

The long sum adds max(x, 0) and the short sum adds min(x, 0) for each weight x of the group, so a short shows on the short side, and a NaN weight gives a NaN on both sides. The sums take the element type of w.

Arguments

  • labels: The group label of each weight.
  • w: The weights.
  • groups: The groups, which hold every label of labels.

Returns

  • L::Vector: The long sum of each group.
  • S::Vector: The short sum of each group, which is not positive.

Related

source
PortfolioOptimisers.exposure_table — Function
exposure_table(sets::UniverseSets, key::AbstractString, names::AbstractVector,
               W::MatNum, labels::AbstractVector, aw::Option{<:Tuple},
               prefix::AbstractString) -> ReportTable

The Exposure table of one member of a prediction for one taxonomy column, from the rows of prediction_weights.

The groups are the labels of the assets of names and of the allocation, in order of first appearance, with (none) last. One row of W gives the table of exposure_group_table, and many rows give the table of exposure_row_table.

Arguments

  • sets: The UniverseSets.
  • key: The name of the taxonomy column.
  • names: The asset names of the columns of W.
  • W: The weights, one row for each portfolio of the prediction.
  • labels: The label of each row of W.
  • aw: The realised weights of the allocation, from allocation_weights, or nothing.
  • prefix: The start of the caption, which names the member.

Returns

  • tab::ReportTable: The table.

Related

source
PortfolioOptimisers.exposure_group_table — Function
exposure_group_table(groups::AbstractVector, s::Tuple, asum::Option{<:Tuple},
                     lead::AbstractString) -> ReportTable

The Exposure table of one row of weights: one row for each group, with the columns long, short and net, and the same three columns of the allocation after the prefix alloc_.

The rows are sorted by the absolute value of net, and the caption gives the gross exposure.

Arguments

  • groups: The groups.
  • s: The long and the short sums of the weights, from exposure_sums.
  • asum: The long and the short sums of the realised weights of the allocation, or nothing.
  • lead: The start of the caption.

Returns

  • tab::ReportTable: The table.

Related

source
PortfolioOptimisers.exposure_row_table — Function
exposure_row_table(groups::AbstractVector, sums::AbstractVector,
                   labels::AbstractVector, asum::Option{<:Tuple},
                   lead::AbstractString) -> ReportTable

The Exposure table of many rows of weights: one row for each portfolio of the prediction, with the column portfolio, one column of net exposure for each group, and the column gross.

With an allocation, the last row allocation sums its realised weights. 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. So the two fixed columns keep their names, and a group gross_1 beside a group gross makes the renamed column gross_2.

Arguments

  • groups: The groups.
  • sums: The long and the short sums of each row of weights, from exposure_sums.
  • labels: The label of each row of weights.
  • asum: The long and the short sums of the realised weights of the allocation, or nothing.
  • lead: The start of the caption.

Returns

  • tab::ReportTable: The table.

Related

source
PortfolioOptimisers.report_allocation — Function
report_allocation(pred::AbstractPredictionResult, alloc::Nothing)
report_allocation(pred::PredictionResult, alloc::FiniteAllocationOptimisationResult)
report_allocation(pred::MultiPeriodPredictionResult, alloc::FiniteAllocationOptimisationResult)
report_allocation(pred::PopulationPredictionResult, alloc::FiniteAllocationOptimisationResult)

The Allocation section of the entry of one prediction, or nothing when the entry has no allocation.

A finite allocation is the allocation of one portfolio. A single fold reads the names of its weights. A path reads the names of its last fold, the portfolio to hold now. A population holds no single portfolio, so it has no allocation.

Arguments

  • pred: The prediction.
  • alloc: The finite allocation result, or nothing.

Validation

  • length(alloc.shares) is the number of assets of the portfolio. Otherwise the function raises a DimensionMismatch.
  • A population has no allocation. Otherwise the function raises an ArgumentError.

Returns

  • s::Option{<:ReportSection}: The section, or nothing.

Related

source