Skip to content

SonicFlash703/demo_algify_backend

 
 

Repository files navigation

QuantFlow

A simple Python quantitative testing framework for backtesting trading strategies, with a focus on testing AI-generated strategies.

Features

  • Download and manage historical stock data
  • Backtest trading strategies on historical data
  • Calculate performance metrics
  • Visualize results with an interactive Streamlit dashboard
  • Support for AI-generated strategies

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/quantflow.git
cd quantflow
  1. Create a virtual environment and install dependencies using uv:
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt

Usage

Running the Streamlit App

streamlit run app.py

This will start the Streamlit app, which provides a user-friendly interface for backtesting strategies.

Creating a Custom Strategy

To create a custom strategy, create a new Python file in the strategies directory that inherits from BaseStrategy:

from strategies.base_strategy import BaseStrategy

class MyCustomStrategy(BaseStrategy):
    def __init__(self, param1=10, param2=20, name="My Custom Strategy"):
        super().__init__(name=name)
        self.param1 = param1
        self.param2 = param2
    
    def generate_signals(self, data):
        # Implement your strategy logic here
        # Return a pandas Series of signals (1 for buy, -1 for sell, 0 for hold)
        pass

Using the Backtesting Engine Programmatically

from backtest.engine import BacktestEngine
from strategies.moving_average_strategy import MovingAverageCrossover

# Create a strategy
strategy = MovingAverageCrossover(short_window=50, long_window=200)

# Create a backtesting engine
engine = BacktestEngine(initial_capital=100000.0)

# Run a backtest
result = engine.run_backtest(strategy, 'QQQ', start_date='2018-01-01', end_date='2023-01-01')

# Plot the results
engine.plot_results()

# Get performance metrics
metrics = engine.get_performance_summary()
print(metrics)

Project Structure

  • app.py: Main Streamlit application
  • backtest/: Core backtesting engine
  • data/: Directory for storing stock data
  • strategies/: Directory for trading strategies
  • utils/: Utility functions
  • visualization/: Frontend visualization components

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%