Trade Wave is a lightweight trading research workspace for exploring how technical strategies and machine learning models behave over time. The project brings together historical backtesting, model training, prediction workflows, and a small web interface so users can compare ideas, inspect results, and iterate quickly.
- Trains AI models for price prediction using the
ai/pipeline. - Runs historical backtests for benchmark strategies and AI models.
- Generates prediction summaries for a symbol using the trained model and selected strategies.
- Exposes a REST API for programmatic backtest and prediction workflows.
- Python 3.12+
- Node.js and npm
- Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate- Install Python dependencies:
python -m pip install -r requirements.txt- Install frontend dependencies:
npm installUse the CLI entrypoint in main.py for training, backtesting, comparing, and serving the API.
Start both the backend API server and the Vite frontend together with one command:
source venv/bin/activate
npm run devThis will launch:
- the Python backend on http://127.0.0.1:5000
- the Vite frontend on the local URL shown in the terminal
If you want to run them separately, you can still use:
source venv/bin/activate
python main.py serve --host 127.0.0.1 --port 5000and in another terminal:
npm run dev:frontendRun a benchmark backtest:
python main.py backtest --symbols AAPL,MSFT --strategies sma_rsi,bollinger_rsi --start 2024-01-01 --end 2024-06-01Compare benchmark strategies with one or more AI models:
python main.py compare --symbols AAPL,MSFT --strategies sma_rsi --model ai_model=ai/models/pipeline_model.pklIn another terminal, start the frontend:
npm run devOpen the Vite URL shown in the frontend terminal.
main.py- CLI entrypoint for training, backtesting, comparison, and serving the APIapi.py- Flask API definition for/api/backtestand/api/predictbacktest.py- backtest runner and strategy bridgedata_handler.py- yfinance data fetcherstrategies/- strategy implementations and registryai/- AI model prediction and training helpersfrontend/- React + TypeScript UItests/- pytest tests for strategy and backtest behavior
The backend exposes JSON POST APIs at:
/api/backtest/api/predict
Example request body:
{
"symbols": "AAPL, MSFT, GOOG",
"strategies": "sma_rsi,bollinger_rsi",
"models": ["ai_model=ai/models/pipeline_model.pkl"]
}The backtest response includes:
summary— aggregated strategy metricsper_symbol— detailed per-symbol stats for each strategy
The prediction endpoint accepts a symbol, model path, and optional strategies, and returns a structured result with:
symbollatest_pricechange_pctai_signalstrategy_signals
The AI model training pipeline lives in ai/.
Train a model with:
python main.py train --mode final --model-path ai/models/pipeline_model.pklOr use walk-forward validation:
python main.py train --mode walk_forward --train-size 500 --test-size 100 --step-size 50 --model-path ai/models/pipeline_model.pklThen include the trained AI model in backtest comparison:
python main.py backtest --symbols AAPL --strategies sma_rsi --model ai_model=ai/models/pipeline_model.pklUse the UI or API to run a prediction for a symbol:
curl -X POST http://127.0.0.1:5000/api/predict \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","model_path":"ai/models/pipeline_model.pkl","strategies":"sma_rsi,bollinger_rsi"}'