A simple Python quantitative testing framework for backtesting trading strategies, with a focus on testing AI-generated strategies.
- 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
- Clone the repository:
git clone https://github.com/yourusername/quantflow.git
cd quantflow- Create a virtual environment and install dependencies using uv:
uv venv
source .venv/bin/activate
uv pip install -r requirements.txtstreamlit run app.pyThis will start the Streamlit app, which provides a user-friendly interface for backtesting strategies.
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)
passfrom 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)app.py: Main Streamlit applicationbacktest/: Core backtesting enginedata/: Directory for storing stock datastrategies/: Directory for trading strategiesutils/: Utility functionsvisualization/: Frontend visualization components
MIT