Virtuoso is a Python-based backtesting tool designed for traders and quantitative analysts who want to evaluate scalping and intraday trading strategies using historical market data. By leveraging cutting-edge libraries like Polars for high-speed data processing and PyTorch for advanced computations, this tool offers unparalleled performance, enabling users to test strategies on large datasets in just seconds.
- Instructions on how to install the necessary dependencies. Do this: pip install -r requirements.txt
- Download the csv file https://drive.google.com/file/d/1eOcxFOqMeQjEqqXu-BibLyycKAQnjY5k/view?usp=sharing
- Make sure the csv file and the python script are in the same folder. You only need those 2 files.
- Utilizes the Polars library, a lightning-fast DataFrame library optimized for large-scale data analysis.
- Efficient handling of millions of rows of historical market data, including candlestick data at various timeframes (e.g., 1-minute, 5-minute, hourly).
- Specifically tailored for scalping and intraday trading strategies, with support for:
- Take Profit (TP) and Stop Loss (SL) levels.
- Entry and exit time constraints.
- Flexible lot sizing and order types (buy/sell).
- Supports multiple strategies, including:
- Strategy 1: Simple TP/SL-based execution.
- Strategy 2: Smart Money Concept (SMC)-based strategies (future development).
- Handles time zone conversions seamlessly, ensuring accurate alignment between market data and strategy execution times.
- Generates insightful visualizations using Plotly, including cumulative profit graphs.
- Saves results as PNG images for easy sharing and reporting.
- Outputs trading journals in CSV format, detailing every trade's entry/exit time, profit/loss, and cumulative utility.
- Future plans include generating PDF reports summarizing strategy performance.
- Modular design allows easy addition of new strategies or enhancements to existing ones.
- Includes placeholders for GPU acceleration using PyTorch for even faster computations.
-
Data Preparation:
- Load historical candlestick data from CSV files.
- Automatically process raw data into various timeframes (e.g., 1-minute, 5-minute) with features like Open, High, Low, Close.
-
Strategy Definition:
- Define trading strategies with parameters such as entry time, TP/SL levels, lot size, and maximum order duration.
-
Backtesting:
- Simulate trades based on historical data.
- Analyze performance metrics such as cumulative profit/loss.
-
Visualization & Reporting:
- Generate visualizations of cumulative utility over time.
- Export results as CSV files or PNG images.
- Processes millions of rows of data in seconds using Polars' lazy computation model.
- Handles complex time zone adjustments and ensures precise alignment between strategy parameters and historical data.
- Provides detailed trading journals and visualizations to help you evaluate strategy performance effectively.
- Easily extendable to include new strategies or integrate additional features like Monte Carlo simulations or advanced risk management techniques.
-
CSVProcessor:
- Handles loading, cleaning, and processing of historical market data from CSV files.
- Supports grouping candlestick data into custom timeframes (e.g., 5m, 15m).
-
StrategyFactory:
- Houses predefined trading strategies with customizable parameters.
- Includes placeholders for adding more advanced strategies in the future.
-
BackTesting:
- Performs historical backtesting by simulating trades based on strategy parameters.
- Calculates key metrics such as cumulative utility and trade outcomes.
-
DataVisualizer:
- Creates visualizations of strategy performance using Plotly.
- Exports results as PNG images or CSV files for further analysis.
-
Future Modules:
- FinancialNewsAnalyzer: Analyze the impact of fundamental news on trading strategies (planned).
- Risk Management: Optimize position sizing based on investor profiles (planned).
- Monte Carlo Testing: Evaluate strategy robustness under varying market conditions (planned).
- Load historical candlestick data for a financial instrument (e.g., XAUUSD).
- Define a scalping strategy with specific TP/SL levels and entry times.
- Run backtesting to simulate trades over the historical dataset.
- Analyze the results using the generated trading journal and cumulative profit chart.
- Python >= 3.9
- Libraries:
polarstorchnumpypandasplotlypathlib2pytzcolorama
Install dependencies using:
pip install polars torch numpy pandas plotly colorama- Clone the repository:
git clone https://github.com/FatherMonkey916/backtest-virtuoso.git
cd backtest-virtuoso-
Place your historical candlestick data in the same directory as the script (
XAUUSD.csvby default). -
Run the main script:
python main.py- View results in the generated CSV (
XAUUSD_back_testing.csv) or PNG (XAUUSD_utility.png) files.
- GPU acceleration for backtesting using PyTorch tensors.
- Integration with live market data feeds for real-time strategy evaluation.
- Advanced visualization dashboards with interactive charts.
- Support for multi-strategy optimization and portfolio-level backtesting.