Skip to main content

Backtester Agent

Project description

BackTesterAgent 🚀

Join our Discord Subscribe on YouTube Connect on LinkedIn Follow on X.com

License: MIT Python 3.8+ Swarms Code style: black Downloads

An enterprise-grade AI-powered backtesting framework built on the Swarms framework for automated trading strategy validation and optimization.

🌟 Features

  • Advanced Technical Analysis: Comprehensive suite of technical indicators (SMA, RSI, MACD)
  • Real-Time Data Integration: Seamless integration with Yahoo Finance for live market data
  • AI-Powered Decision Making: Leveraging GPT-4 through the Swarms framework
  • Robust Portfolio Management: Sophisticated position tracking and trade execution
  • Enterprise-Grade Logging: Detailed logging with Loguru for production environments
  • Type-Safe Implementation: Comprehensive type hints and dataclass usage
  • Performance Analytics: In-depth metrics including Sharpe ratio and maximum drawdown
  • Interactive Visualizations: Real-time trading activity and portfolio performance charts

🛠️ Installation

pip3 install -U backtester_agent

📋 Requirements

  • Python 3.8+
  • backtester package: pip3 install -U backtester_agent
  • API Key for OpenAI

🚀 Quick Start

from backtester_agent.main import run_backtest

run_backtest(cash=500.0, symbol="AAPL", start_date="2024-11-16", end_date="2024-11-18", trade_size=10)

📊 Example Output

2024-01-18 10:30:15 | INFO | Starting backtest for AAPL
2024-01-18 10:30:16 | INFO | Processing 252 trading days
2024-01-18 10:30:45 | SUCCESS | Backtest completed

Backtest Results:
Initial Portfolio Value: $100,000.00
Final Portfolio Value: $125,432.10
Total Return: 25.43%
Sharpe Ratio: 1.85
Maximum Drawdown: -8.32%
Total Trades: 45

🔧 Configuration

Configure the agent through environment variables or a config file:

OPENAI_API_KEY=your_api_key_here
WORKSPACE_DIR="agent_workspace"
SWARMS_API_KEY=your_swarms_api_key_here # Get from swarms.ai dashboard

🏗️ Architecture

graph TD
    A[FinancialData] -->|Price Data| B[BackTester]
    B -->|Market State| C[FinancialAgent]
    C -->|Decisions| D[Portfolio]
    D -->|Execution| B
    E[Technical Indicators] -->|Analysis| C

📈 Performance Metrics

The BackTesterAgent provides comprehensive performance analytics:

  • Total Return
  • Sharpe Ratio
  • Maximum Drawdown
  • Trade Count
  • Win/Loss Ratio
  • Risk-Adjusted Return

🔍 Logging and Monitoring

Detailed logging is implemented using Loguru:

logger.add(
    "backtester_{time}.log",
    rotation="500 MB",
    retention="10 days",
    level="INFO"
)

🔒 Security

  • Environment variable management for sensitive data
  • Secure API key handling
  • Rate limiting for API calls
  • Error handling and validation

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

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

🙏 Acknowledgments

📞 Support

🗺️ Roadmap

  • Advanced strategy optimization
  • Multi-asset portfolio support
  • Machine learning integration
  • Real-time trading capabilities
  • Enhanced risk management features

📊 Benchmarks

Performance benchmarks against standard trading strategies:

Strategy Return Sharpe Ratio Max Drawdown
Buy & Hold 15.2% 0.95 -12.3%
BackTesterAgent 25.4% 1.85 -8.3%
Market Index 12.1% 0.82 -15.7%

Built with ❤️ by Swarms

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backtester_agent-0.0.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

backtester_agent-0.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file backtester_agent-0.0.1.tar.gz.

File metadata

  • Download URL: backtester_agent-0.0.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.3.0

File hashes

Hashes for backtester_agent-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ba22b7ca75c67eae8d309d120e469a3918e1febbc60c21e5f34e62f55cacd7a6
MD5 da7ad7e30bf3251304981930e7406d5b
BLAKE2b-256 da1c95f0002a732ee8fcab9d6a3c8f2b4dcc1649f1d9da4e9941032154d90153

See more details on using hashes here.

File details

Details for the file backtester_agent-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for backtester_agent-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 333b72e3cb001fe9720a9f81421be1a807804130c8eae06b5380a76c0f23d65e
MD5 6c029c305af1b5dfcd9d6d127f31a149
BLAKE2b-256 d3755b3d9bb01a8befb4038ace0ec571ecaa00492006f3fcc7eefd7742c4e123

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page