feat: add standalone HTML reports

This commit is contained in:
Khizar
2026-07-17 14:54:59 +00:00
parent 4fcadca02e
commit c31e0088db
13 changed files with 539 additions and 17 deletions
+1
View File
@@ -15,5 +15,6 @@ fn backtestingfx(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<broker::Broker>()?;
m.add_class::<engine::Engine>()?;
m.add_class::<types::Position>()?;
m.add_class::<types::Trade>()?;
Ok(())
}
+7
View File
@@ -1,4 +1,5 @@
use crate::broker::Broker;
use crate::types::Trade;
use pyo3::prelude::*;
#[pyclass]
@@ -27,6 +28,10 @@ pub struct Stats {
pub max_drawdown_pct: f64,
#[pyo3(get)]
pub sharpe_ratio: f64,
#[pyo3(get)]
pub equity_curve: Vec<f64>,
#[pyo3(get)]
pub trades: Vec<Trade>,
}
fn sharpe_ratio(equity_curve: &[f64]) -> f64 {
@@ -134,6 +139,8 @@ impl Stats {
profit_factor,
max_drawdown_pct,
sharpe_ratio,
equity_curve: equity_curve.to_vec(),
trades: broker.trade_history.clone(),
}
}
}
+1 -2
View File
@@ -1,8 +1,7 @@
use crate::types::Bar;
use crate::broker::Broker;
use crate::types::Bar;
pub trait Strategy {
fn init(&mut self, _data: &[Bar]) {}
fn next(&mut self, bar: &Bar, broker: &mut Broker);
}
+8
View File
@@ -66,14 +66,22 @@ impl Position {
}
}
#[pyclass(from_py_object)]
#[derive(Debug, Clone)]
pub struct Trade {
// the actual trade
#[pyo3(get)]
pub entry_price: f64,
#[pyo3(get)]
pub exit_price: f64,
#[pyo3(get)]
pub lot_size: f64,
#[pyo3(get)]
pub is_long: bool,
#[pyo3(get)]
pub pnl: f64,
#[pyo3(get)]
pub entry_timestamp: i64,
#[pyo3(get)]
pub exit_timestamp: i64,
}