fincore.viz¶
VizBackend Protocol¶
fincore.viz.base.VizBackend
¶
Bases: Protocol
Protocol that every visualization backend must implement.
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.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
sharpe
|
Series
|
Rolling Sharpe ratio series. |
必需 |
benchmark_sharpe
|
Series
|
Optional benchmark rolling Sharpe series. |
None
|
window
|
int
|
Window size (used for title/annotation). |
252
|
plot_monthly_heatmap(returns, **kwargs)
¶
Plot monthly returns heatmap.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
returns
|
Series or DataFrame
|
Either a daily returns series (will be aggregated internally) or a year x month table of monthly returns. |
必需 |
get_backend¶
fincore.viz.base.get_backend(name='matplotlib')
¶
Resolve a visualization backend by name.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Backend identifier. Supported 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.