Skip to content

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.

Notifications You must be signed in to change notification settings

frostyalce000/backtest-virtuoso

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Virtuoso: A High-Performance Backtesting Tool for Scalping and Intraday Trading Strategies

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.

Installation

  1. Instructions on how to install the necessary dependencies. Do this: pip install -r requirements.txt
  2. Download the csv file https://drive.google.com/file/d/1eOcxFOqMeQjEqqXu-BibLyycKAQnjY5k/view?usp=sharing
  3. Make sure the csv file and the python script are in the same folder. You only need those 2 files.

Key Features

1. High-Speed Data Processing

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

2. Scalping and Intraday Strategy Backtesting

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

3. Time Zone Adjustments

  • Handles time zone conversions seamlessly, ensuring accurate alignment between market data and strategy execution times.

4. Data Visualization

  • Generates insightful visualizations using Plotly, including cumulative profit graphs.
  • Saves results as PNG images for easy sharing and reporting.

5. Comprehensive Output

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

6. Extensibility

  • Modular design allows easy addition of new strategies or enhancements to existing ones.
  • Includes placeholders for GPU acceleration using PyTorch for even faster computations.

How It Works

  1. 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.
  2. Strategy Definition:

    • Define trading strategies with parameters such as entry time, TP/SL levels, lot size, and maximum order duration.
  3. Backtesting:

    • Simulate trades based on historical data.
    • Analyze performance metrics such as cumulative profit/loss.
  4. Visualization & Reporting:

    • Generate visualizations of cumulative utility over time.
    • Export results as CSV files or PNG images.

Why Use Virtuoso?

⚡ Speed:

  • Processes millions of rows of data in seconds using Polars' lazy computation model.

🔍 Accuracy:

  • Handles complex time zone adjustments and ensures precise alignment between strategy parameters and historical data.

📊 Insights:

  • Provides detailed trading journals and visualizations to help you evaluate strategy performance effectively.

🛠️ Customization:

  • Easily extendable to include new strategies or integrate additional features like Monte Carlo simulations or advanced risk management techniques.

Core Components

  1. CSVProcessor:

    • Handles loading, cleaning, and processing of historical market data from CSV files.
    • Supports grouping candlestick data into custom timeframes (e.g., 5m, 15m).
  2. StrategyFactory:

    • Houses predefined trading strategies with customizable parameters.
    • Includes placeholders for adding more advanced strategies in the future.
  3. BackTesting:

    • Performs historical backtesting by simulating trades based on strategy parameters.
    • Calculates key metrics such as cumulative utility and trade outcomes.
  4. DataVisualizer:

    • Creates visualizations of strategy performance using Plotly.
    • Exports results as PNG images or CSV files for further analysis.
  5. 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).

Example Use Case

  1. Load historical candlestick data for a financial instrument (e.g., XAUUSD).
  2. Define a scalping strategy with specific TP/SL levels and entry times.
  3. Run backtesting to simulate trades over the historical dataset.
  4. Analyze the results using the generated trading journal and cumulative profit chart.

Getting Started

Prerequisites

  • Python >= 3.9
  • Libraries:
    • polars
    • torch
    • numpy
    • pandas
    • plotly
    • pathlib2
    • pytz
    • colorama

Install dependencies using:

pip install polars torch numpy pandas plotly colorama

Running the Tool

  1. Clone the repository:
git clone https://github.com/FatherMonkey916/backtest-virtuoso.git
cd backtest-virtuoso
  1. Place your historical candlestick data in the same directory as the script (XAUUSD.csv by default).

  2. Run the main script:

python main.py
  1. View results in the generated CSV (XAUUSD_back_testing.csv) or PNG (XAUUSD_utility.png) files.

Future Enhancements

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

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages