Visualization¶
fincore provides pluggable visualization backends via the VizBackend protocol.
Built-in Backends¶
Matplotlib¶
from fincore.viz import get_backend
viz = get_backend("matplotlib")
viz.plot_returns(cum_returns)
viz.plot_drawdown(drawdown)
viz.plot_rolling_sharpe(rolling_sharpe)
viz.plot_monthly_heatmap(returns)
HTML (no extra dependencies)¶
from fincore.viz.html_backend import HtmlReportBuilder
builder = HtmlReportBuilder()
builder.add_title("My Report")
builder.add_stats_table(stats)
builder.save("report.html")
Via AnalysisContext¶
ctx = fincore.analyze(returns, factor_returns=benchmark)
ctx.plot(backend="matplotlib")
ctx.to_html(path="report.html")
API Reference¶
The backend protocol is documented on the viz API page.
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.