Enhance the existing "Strategy Studio" to rival frameworks like "Jesse" or "VectorBT" in terms of visualization and capability. This involves integrating vectorbt for high-performance backtesting and parameter optimization, and creating a rich frontend dashboard to visualize equity curves, trade lists, and optimization heatmaps.
Important
This plan introduces vectorbt as a dependency. It is a powerful library but can be heavy. We will aim for the standard (non-PRO) version which is open source.
Note
We will use recharts for the frontend visualization as it is already in the project, creating a consistent look and feel with the existing dashboard.
- Add
vectorbtandschedule(if needed for advanced timing, thoughvectorbtusually suffices for backtest).
- Fully implement
run_backtestusingvectorbt. - Add support for Parameter Optimization: Detect if parameters are lists/ranges and run
vbt.Portfolio.from_signalsin batch mode. - Return comprehensive JSON:
metrics: Existing scalar metrics.equity: Time series of equity.trades: List of individual trades (entry/exit time, price, PnL).optimization_results: (Optional) Table of Params vs. Return/Sharpe for heatmaps.
- Helper functions to parse natural language ranges (e.g., "fast 10 to 50 step 10") into python lists for
vectorbt.
- A detailed dashboard component replacing the simple table.
- Charts: Equity Curve (Recharts AreaChart), Drawdown (Recharts AreaChart).
- Tables: Trade List (Scrollable table with Win/Loss coloring).
- Optimization View: If multiple results exist, show a heatmap or sorted table of best parameter sets.
- Integrate
BacktestDashboard. - Add UI inputs for parameter ranges (or rely on the Chatbot to parse "optimize ...").
- Update
runBacktestto handle the richer response.
- Backend Unit Test: Create
backend/tests/test_vectorbt.pyto ensurevectorbtruns a simple crossover and returns the expected JSON structure. - API Check: Use
curlto POST to/api/agent/execute_taskwith a backtest task and verify the JSON response containsequityandtrades.
- Optimization Flow:
- Go to Strategy Studio.
- Type: "Optimize SMA strategy on XAUUSD H1. Fast from 10 to 50 step 10, Slow from 60 to 100 step 10."
- Verify the backend runs multiple combinations.
- Verify the Frontend displays a heatmap/table of results.
- Click a result to see its specific Equity Curve.
- Visual Check:
- Run a single backtest.
- Check that the Equity Curve looks correct (starts at 0% or 100%, fluctuates).
- Check the Trade List matches the chart logic.