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 NoneOptional height (for example merge distance) per node.
Returns
- dict[str, Any]
chart("tree"),node_id,parent_idand, if given,height.
Raises
- ValueError
If
parent_idorheightdiffers in length fromnode_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,drawdownandy_label("drawdown").
Raises
- ValueError
If
equity_curvediffers in length fromtimestamps.
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"), andleftandright, each a dict withname,labelsandvalues.
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 NoneOptional error-bar size per feature.
top_n: int or None, default NoneKeep only the
top_nmost important features.
Returns
- dict[str, Any]
chart("bar"),x(feature names),y(importances),y_label("importance") and, ifstdis given,error_y.
Raises
- ValueError
If
importanceorstddiffers in length fromfeature_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 NoneOptional Sharpe ratio per point, used as the color.
Returns
- dict[str, Any]
chart("scatter"),x,y,x_label("volatility"),y_label("return") and, ifsharpeis given,colorandcolor_label("sharpe").
Raises
- ValueError
If
returnsorsharpediffers in length fromvolatility.
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.0Score at or above which the regime is 1.
Returns
- dict[str, Any]
chart("line+step"),x(timestamps),score,thresholdandregime(list of 1/-1).
Raises
- ValueError
If
scorediffers in length fromtimestamps.