Skip to content

morarez/trade-wave

Repository files navigation

Trade Wave

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.

What it does

  • 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.

Prerequisites

  • Python 3.12+
  • Node.js and npm

Installation

  1. Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate
  1. Install Python dependencies:
python -m pip install -r requirements.txt
  1. Install frontend dependencies:
npm install

Running locally

Use 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 dev

This will launch:

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 5000

and in another terminal:

npm run dev:frontend

Run a benchmark backtest:

python main.py backtest --symbols AAPL,MSFT --strategies sma_rsi,bollinger_rsi --start 2024-01-01 --end 2024-06-01

Compare 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.pkl

In another terminal, start the frontend:

npm run dev

Open the Vite URL shown in the frontend terminal.

Project structure

  • main.py - CLI entrypoint for training, backtesting, comparison, and serving the API
  • api.py - Flask API definition for /api/backtest and /api/predict
  • backtest.py - backtest runner and strategy bridge
  • data_handler.py - yfinance data fetcher
  • strategies/ - strategy implementations and registry
  • ai/ - AI model prediction and training helpers
  • frontend/ - React + TypeScript UI
  • tests/ - pytest tests for strategy and backtest behavior

Backend API

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 metrics
  • per_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:

  • symbol
  • latest_price
  • change_pct
  • ai_signal
  • strategy_signals

AI

The AI model training pipeline lives in ai/.

Train a model with:

python main.py train --mode final --model-path ai/models/pipeline_model.pkl

Or 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.pkl

Then include the trained AI model in backtest comparison:

python main.py backtest --symbols AAPL --strategies sma_rsi --model ai_model=ai/models/pipeline_model.pkl

Use 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"}'

About

market waves and trends.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors