| Crates.io | quantstats-rs |
| lib.rs | quantstats-rs |
| version | 0.1.0 |
| created_at | 2025-11-19 15:45:43.876019+00 |
| updated_at | 2025-11-19 15:45:43.876019+00 |
| description | Rust implementation of QuantStats-style performance tear sheets with SVG charts and HTML reports. |
| homepage | https://github.com/netcan/quantstats-rs |
| repository | https://github.com/netcan/quantstats-rs |
| max_upload_size | |
| id | 1940298 |
| size | 3,704,541 |
quantstats-rs is a Rust library that generates QuantStats-style HTML performance tear sheets
from return time series. It aims to closely match the behaviour and visuals of the original
Python QuantStats project.
Preview of the benchmark tear sheet:

PerformanceMetrics), including:
#348dc1, benchmark #ff9933, etc.)src/
lib.rs – public API: html, HtmlReportOptions, ReturnSeries, PerformanceMetrics.reports.rs – report assembly, metrics table rendering, and template filling.stats.rs – performance statistics and drawdown segment logic.plots.rs – all SVG chart generation.report_template.html – HTML template, roughly mirroring QuantStats’ report.html.examples/
html_report.rs – strategy only; writes tearsheet.html.html_with_benchmark.rs – strategy + benchmark; writes tearsheet_with_benchmark.html.common.rs – shared demo data, generated from data/ by the script.data/ – CSVs / time series used to build the example report.scripts/gen_examples_common.py – generates examples/common.rs from data/.From the repository root:
cargo build
# Strategy-only demo report (writes `tearsheet.html`)
cargo run --example html_report
# Strategy + benchmark demo report (writes `tearsheet_with_benchmark.html`)
cargo run --example html_with_benchmark
# Tests (if present)
cargo test
The generated HTML files can be opened directly in a browser and visually compared against reports produced by the Python QuantStats library.
Add a dependency (path here assumes your project is a sibling of this repo):
[dependencies]
quantstats-rs = { path = "../quantstats-rs" }
Basic usage in Rust:
use chrono::NaiveDate;
use quantstats_rs::{ReturnSeries, HtmlReportOptions, html};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Prepare dates and returns (e.g. daily returns)
let dates: Vec<NaiveDate> = /* ... */;
let values: Vec<f64> = /* ... */; // e.g. 0.01 means +1%
let strategy = ReturnSeries::new(dates, values, Some("Strategy".to_string()))?;
// 2. Configure report options
let options = HtmlReportOptions::default()
.with_title("My Strategy Tearsheet")
.with_strategy_title("My Strategy")
.with_output("tearsheet.html");
// 3. Generate HTML string and write to file (if `output` is set)
let html_string = html(&strategy, options)?;
println!("Report generated ({} bytes)", html_string.len());
Ok(())
}
With a benchmark:
let strategy: ReturnSeries = /* ... */;
let benchmark: ReturnSeries = /* ... */;
let options = HtmlReportOptions::default()
.with_benchmark(&benchmark)
.with_title("Strategy vs Benchmark")
.with_strategy_title("Strategy")
.with_benchmark_title("Benchmark")
.with_output("tearsheet_with_benchmark.html");
let html_string = html(&strategy, options)?;
The example binaries use examples/common.rs, which is generated from data/:
python3 scripts/gen_examples_common.py
After changing the data under data/, re-run the script and then rerun the examples
to regenerate tearsheet.html and tearsheet_with_benchmark.html.
This implementation uses the vendored Python QuantStats code and its HTML output as the reference. The following aspects are intentionally aligned:
If you notice discrepancies compared to a Python QuantStats report (especially in a specific chart such as “Rolling Sortino” or “Underwater Plot”), please open an issue or PR and mention: