mirror of
https://github.com/KhizarImran/backtestingfx.git
synced 2026-07-27 20:17:44 +00:00
feat: add standalone HTML reports
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user