fincore.viz¶
VizBackend Protocol¶
fincore.viz.base.VizBackend
¶
Bases: Protocol
Protocol implemented by each visualization backend.
plot_returns(cum_returns, **kwargs)
¶
Plot cumulative returns.
plot_drawdown(drawdown, **kwargs)
¶
Plot drawdown underwater chart.
plot_rolling_sharpe(sharpe, benchmark_sharpe=None, window=252, **kwargs)
¶
Plot rolling Sharpe ratio.
plot_monthly_heatmap(returns, **kwargs)
¶
Plot monthly returns heatmap.
get_backend¶
fincore.viz.base.get_backend(name='matplotlib', *, extension_snapshot=None)
¶
Resolve a visualization backend by name.
A renderer from extension_snapshot takes precedence over built-in
backends. The snapshot protocol is intentionally small: it must provide a
callable renderer(name) method, and the returned renderer must be
instantiable without arguments.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Backend identifier. Built-in backends:
- |
'matplotlib'
|
返回:
| 类型 | 描述 |
|---|---|
VizBackend
|
An instance satisfying the :class: |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the requested backend is not recognized. |
ImportError
|
If the backend's dependencies are not installed. |
HtmlReportBuilder¶
fincore.viz.html_backend.HtmlReportBuilder()
¶
Build a standalone HTML performance report.
This class also satisfies the :class:~fincore.viz.base.VizBackend
protocol (the plot_* methods append HTML sections and return
self for chaining).
Usage::
from fincore.viz.html_backend import HtmlReportBuilder
builder = HtmlReportBuilder()
builder.add_title("Performance Report")
builder.add_stats_table(perf_stats_series)
html_str = builder.build()
add_title(title='Performance Report')
¶
Append an <h1> title section to the report.
add_heading(text, level=2)
¶
Append a heading (<h2> … <h6>) section to the report.
add_stats_table(stats)
¶
Render a two-column key/value table from a pandas Series.
add_metric_cards(stats, keys=None)
¶
Render inline metric cards for selected keys from stats.
add_html(raw_html)
¶
Append raw HTML directly to the report body.
plot_returns(cum_returns, **kwargs)
¶
Append a cumulative-returns table section (VizBackend protocol).
plot_drawdown(drawdown, **kwargs)
¶
Append a drawdown table section (VizBackend protocol).
plot_rolling_sharpe(sharpe, benchmark_sharpe=None, window=APPROX_BDAYS_PER_YEAR, **kwargs)
¶
Append a rolling Sharpe ratio table section (VizBackend protocol).
plot_monthly_heatmap(returns, **kwargs)
¶
Append a monthly-returns pivot table section (VizBackend protocol).
build()
¶
Assemble all sections into a complete HTML document string.
save(path)
¶
Write the report to a file at path.
MatplotlibBackend¶
fincore.viz.matplotlib_backend.MatplotlibBackend
¶
Visualization backend powered by matplotlib.
All methods return the matplotlib.axes.Axes object so callers
can further customise the plot.
plot_returns(cum_returns, *, title='Cumulative Returns', ax=None, **kwargs)
¶
Plot cumulative returns as a line chart.
plot_drawdown(drawdown, *, title='Drawdown', ax=None, **kwargs)
¶
Plot drawdown as a filled area chart.
plot_rolling_sharpe(sharpe, benchmark_sharpe=None, window=252, *, title=None, ax=None, **kwargs)
¶
Plot rolling Sharpe ratio with optional benchmark overlay.
plot_monthly_heatmap(returns, *, title='Monthly Returns (%)', ax=None, **kwargs)
¶
Plot a year × month heatmap of returns using imshow.