Status: 🚧 In progress
Introduce a monitoring layer that works for both backtests and (future) live runs. Engines now emit structured events that are easy to inspect, plot, and embed inside lightweight dashboards.
- New
alphaweave.monitoringpackageBarSnapshot,TradeRecord, andMonitorprotocolInMemoryMonitorthat stores events and exposes pandas DataFramesRunMonitorhelper with derived metrics (equity, drawdown, exposure, turnover, costs)
- Engines
VectorBacktester.run(..., monitor=...)wires monitoring hooks- Minimal
LiveEnginewrapper shares the same monitoring API - Strategies get
log_metric()to publish custom scalar telemetry
- Visualization
monitoring.plotsexposes backend-agnostic Matplotlib helpersmonitoring.dashboard.generate_html_dashboard()builds a reusable HTML report
- Drift analysis
analysis.compute_live_drift_seriescompares live monitoring vs backtest equity
- Docs + examples:
examples/backtest_with_dashboard.pyexamples/live_replay_with_dashboard.pyexamples/strategy_custom_metrics_logging.py
class Monitor(Protocol):
def on_run_start(self, meta: Mapping[str, Any] | None = None) -> None: ...
def on_bar(self, snapshot: BarSnapshot) -> None: ...
def on_trade(self, trade: TradeRecord) -> None: ...
def on_metric(self, name: str, value: float, timestamp: datetime) -> None: ...
def on_run_end(self) -> None: ...InMemoryMonitor stores bars, trades, and metrics in lists and exposes bars_df(), trades_df(), metrics_df() for notebook-friendly inspection.
Wraps an InMemoryMonitor and provides derived analytics:
equity_curve(),drawdown_curve()exposure_over_time()weights per symbolturnover_over_time()simple 0.5 * sum(|Δw|)cost_over_time()cumulative fees + slippage from trades
VectorBacktester.run(..., monitor=None, monitor_meta=None)- Emits
on_run_start, per-barBarSnapshot, per-fillTradeRecord, andon_run_end - Supplies metadata (
mode,performance_mode, etc.) for dashboards
- Emits
- Strategies automatically receive
_monitorand can callself.log_metric(name, value) LiveEngine(new package) reusesVectorBacktesterbut tags runs withmode="live"
monitoring.plotsincludesplot_equity_and_drawdown,plot_exposure_heatmap,plot_turnover,plot_trade_pnl_histogrammonitoring.dashboard.generate_html_dashboard(...)- Embeds Matplotlib PNGs as base64
- Shows overview metrics, exposures, turnover, trades table, and optional backtest vs live drift comparison
compute_live_drift_series(backtest_equity, live_run) aligns backtest equity with live monitoring data and returns (live / backtest) - 1. Dashboards surface this when backtest equity is supplied.
backtest_with_dashboard.py— run a multi-asset backtest, emit monitor events, and write an HTML dashboardlive_replay_with_dashboard.py— reuse the monitoring stack with the newLiveEnginestrategy_custom_metrics_logging.py— demonstrateStrategy.log_metricpiping into dashboards
- Extend
LiveEnginewith real broker/datafeed integrations - Add Plotly/Streamlit front-ends leveraging the same
RunMonitor - Stream monitor events over sockets for distributed deployments