Skip to content
GeneratedGenerated from the built extension by scripts/generate_python_api_reference.py; CI fails if it is stale.

openquant.viz

Pure Python. Signatures are as written in the source; descriptions are the docstrings. All Python modules.

Functions

prepare_cluster_payload

prepare_cluster_payload(
    node_id: Sequence[str],
    parent_id: Sequence[str | None],
    height: Sequence[float] | None = None,
) -> dict[str, Any]

Build a tree payload (for example a dendrogram) from parent links.

Parameters

node_id : Sequence[str]

Identifier of each node.

parent_id : Sequence[str or None]

Parent of each node, None for a root. Not checked against node_id.

height : Sequence[float] or None, default None

Optional height (for example merge distance) per node.

Returns

dict[str, Any]

chart ("tree"), node_id, parent_id and, if given, height.

Raises

ValueError

If parent_id or height differs in length from node_id.

prepare_drawdown_payload

prepare_drawdown_payload(
    timestamps: Sequence[str],
    equity_curve: Sequence[float],
) -> dict[str, Any]

Build a line-chart payload of an equity curve and its drawdown.

Drawdown is equity / running_max(equity) - 1, so it is 0 at each new high and negative below it; it assumes a positive equity curve. Timestamps are parsed and re-rendered with str, so a timestamp that fails to parse comes out as "None".

Parameters

timestamps : Sequence[str]

Timestamp strings, one per equity value.

equity_curve : Sequence[float]

Equity values.

Returns

dict[str, Any]

chart ("line"), x (timestamps as strings), equity, drawdown and y_label ("drawdown").

Raises

ValueError

If equity_curve differs in length from timestamps.

prepare_feature_importance_comparison_payload

prepare_feature_importance_comparison_payload(
    left_labels: Sequence[str],
    left_values: Sequence[float],
    right_labels: Sequence[str],
    right_values: Sequence[float],
    left_name: str = 'left',
    right_name: str = 'right',
) -> dict[str, Any]

Build a grouped-bar payload comparing two sets of importances.

The two sides are passed through as given (not sorted or aligned by label), so the label lists may differ, for example raw features against principal components.

Parameters

left_labels : Sequence[str]

Labels of the left series.

left_values : Sequence[float]

Values of the left series.

right_labels : Sequence[str]

Labels of the right series.

right_values : Sequence[float]

Values of the right series.

left_name : str, default "left"

Display name of the left series.

right_name : str, default "right"

Display name of the right series.

Returns

dict[str, Any]

chart ("grouped_bar"), and left and right, each a dict with name, labels and values.

Raises

ValueError

If a side's labels and values differ in length.

prepare_feature_importance_payload

prepare_feature_importance_payload(
    feature_names: Sequence[str],
    importance: Sequence[float],
    std: Sequence[float] | None = None,
    top_n: int | None = None,
) -> dict[str, Any]

Build a plotting-library-agnostic bar-chart payload for feature importances.

Features are sorted by importance, highest first, before top_n is applied.

Parameters

feature_names : Sequence[str]

Feature names.

importance : Sequence[float]

Importance per feature.

std : Sequence[float] or None, default None

Optional error-bar size per feature.

top_n : int or None, default None

Keep only the top_n most important features.

Returns

dict[str, Any]

chart ("bar"), x (feature names), y (importances), y_label ("importance") and, if std is given, error_y.

Raises

ValueError

If importance or std differs in length from feature_names.

prepare_frontier_payload

prepare_frontier_payload(
    volatility: Sequence[float],
    returns: Sequence[float],
    sharpe: Sequence[float] | None = None,
) -> dict[str, Any]

Build a scatter payload of an efficient frontier, optionally colored by Sharpe ratio.

Parameters

volatility : Sequence[float]

Volatility of each point (x axis).

returns : Sequence[float]

Return of each point (y axis).

sharpe : Sequence[float] or None, default None

Optional Sharpe ratio per point, used as the color.

Returns

dict[str, Any]

chart ("scatter"), x, y, x_label ("volatility"), y_label ("return") and, if sharpe is given, color and color_label ("sharpe").

Raises

ValueError

If returns or sharpe differs in length from volatility.

prepare_regime_payload

prepare_regime_payload(
    timestamps: Sequence[str],
    score: Sequence[float],
    threshold: float = 0.0,
) -> dict[str, Any]

Build a line-plus-step payload of a regime score and the regime it implies.

Each point is regime 1 when score >= threshold and -1 otherwise. Timestamps are passed through unparsed.

Parameters

timestamps : Sequence[str]

Timestamp per score.

score : Sequence[float]

Regime score.

threshold : float, default 0.0

Score at or above which the regime is 1.

Returns

dict[str, Any]

chart ("line+step"), x (timestamps), score, threshold and regime (list of 1/-1).

Raises

ValueError

If score differs in length from timestamps.