Skip to content

9lfx/Backtester-py

Repository files navigation

📈 Backteting Framework Backend

This repository contains the backend engine of a modular trading framework built in Python. It handles backtesting, market data processing, and strategy execution, designed to integrate seamlessly with a separate frontend dashboard for visualization and user interaction.

👉 Frontend Repository: Backtest Dashboard (React/Next.js)
👉 Results Viewer: Backtest Results Viewer (React/Next.js)

Demo preview

🧰 Tech Stack

  • Python: 3.10+
  • Libraries: Pandas, NumPy, PyYAML, Plotly, Pillow
  • API: FastAPI (REST), WebSocket for real-time updates
  • Server: Uvicorn (ASGI)

⚙️ Key Features

  • 🔁 Backtesting Engine: Realistic order simulation with robust risk management.
  • 📊 Performance Analytics: Compute trade statistics and generate visual reports.
  • 💾 Market Data Module: Flexible data loader supporting CSV.
  • 🧩 Strategy Plugin System: Easily extendable with new strategies.
  • 📸 Screenshot Capture System: Automatically generates snapshots of trade entries, including indicators and analysis, for later review in the Results Viewer.
  • 🪵 Logging System: color-formatted runtime logs with adjustable verbosity.
  • 🧠 Walk-Forward Testing: 🚧 Currently under development – Evaluate strategies across multiple time periods.
  • 🌐 API Integration: Communicates with the frontend via REST and WebSocket interfaces.

📸 Example Trade Capture

example

🗂️ Project Structure

Backtesting/
 ├─ Engine.py             # Core backtesting logic
 ├─ MarketData/           # Data loading and formatting
 ├─ OrderManager/         # Order handling and validation
 ├─ Statistics/           # Performance metrics
 └─ ChartRenderer/        # Visualization utilities

Strategies/
 ├─ Template.py           # Template strategy
 └─ configs/              # YAML configs for strategies

main.py                   # Backend entry point
config.yaml               # Global configuration
chart_config.yaml         # Chart settings for screenshots

🚀 Getting Started

Prerequisites

  • Python 3.10+
  • pip for installing dependencies

Install Dependencies

pip install -r requirements.txt

Run the Backend

uvicorn main:app --reload --log-level critical

🔗 Connecting with the Frontend

  • The backend exposes REST endpoints and WebSocket streams consumed by the Frontend Dashboard.
  • The frontend visualizes live or backtested results in real-time.
  • Communication is handled via REST API and WebSocket updates.

🧩 Adding a New Strategy

To create a custom strategy:

  1. Add a new Python file under Strategies/ (use Template.py as a reference).
  2. Create a corresponding YAML config file in Strategies/configs/.
  3. Launch the backend and view results in the connected frontend.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A clean FastAPI backend to run and monitor backtests in real time.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages