Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

35 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

DART Logo

D.A.R.T

Deep Adaptive Reinforcement Trader

An advanced AI-powered algorithmic trading system combining Deep Reinforcement Learning, ensemble machine learning, and sophisticated risk management.

Version Python PyTorch License Status

Features โ€ข Architecture โ€ข Installation โ€ข Usage โ€ข Configuration โ€ข Contributing


๐ŸŒŸ Overview

DART (Deep Adaptive Reinforcement Trader) is a sophisticated Python-based algorithmic trading platform that leverages cutting-edge AI technologies to analyze financial markets, generate trading strategies, and execute trades automatically. Built with a focus on adaptability and risk management, DART combines multiple ML paradigms to make intelligent trading decisions.

What Makes DART Unique?

  • ๐Ÿง  Hybrid AI Architecture: Combines traditional ML ensembles with Deep Reinforcement Learning
  • ๐Ÿ“Š Multi-Modal Analysis: Integrates technical indicators, price patterns, and market sentiment
  • ๐Ÿ›ก๏ธ Institutional-Grade Risk Management: Monte Carlo VaR, Kelly Criterion, and dynamic position sizing
  • ๐ŸŽฏ Uncertainty-Aware Trading: Epistemic and aleatoric uncertainty quantification for confident decisions
  • ๐Ÿ”„ Self-Adaptive Learning: Continuously improves from trade outcomes

๐Ÿš€ Key Features

๐Ÿค– AI & Machine Learning

Feature Description
Soft Actor-Critic (SAC) State-of-the-art deep RL with automatic entropy tuning
Ensemble Stacking Gradient Boosting + Random Forest + Logistic Regression meta-learner
Market Regime Detection VAE-based detection of 7 market conditions (trending, volatile, ranging, etc.)
Curiosity-Driven Exploration Intrinsic Curiosity Module (ICM) for better market exploration
Uncertainty Quantification Ensemble disagreement + Monte Carlo dropout for confidence estimation

๐Ÿ“ˆ Technical Analysis

Feature Description
50+ Technical Indicators RSI, MACD, Bollinger Bands, ATR, ADX, Stochastic, CCI, MFI, VWAP, and more
Market Structure Analysis Support/resistance levels, trend direction, volatility regimes
Pattern Recognition Gap detection, trend strength calculation, price pattern identification
Multi-Timeframe Analysis From 1-minute scalping to daily swing trading

๐Ÿ›ก๏ธ Risk Management

Feature Description
Monte Carlo VaR Value at Risk with 10,000+ simulations at 95% and 99% confidence
Kelly Criterion Optimal position sizing based on expected returns
Dynamic Drawdown Protection Automatic trading pause on configurable drawdown thresholds
Correlation-Based Limits Portfolio diversification with correlation exposure management
Regime-Adjusted Sizing Position sizes adapt to detected market conditions

๐Ÿ’ป User Interfaces

Interface Description
Desktop Application Modern CustomTkinter-based GUI with real-time charts and trading controls
Web Dashboard Streamlit-powered dashboard with glassmorphism design and live AI insights
API Integration Full Deriv.com API support for live trading and market data

๐Ÿ—๏ธ Architecture

DART/
โ”œโ”€โ”€ ๐Ÿ”Œ api/                          # API Integration Layer
โ”‚   โ”œโ”€โ”€ deriv_client.py              # Deriv API with OAuth 2.0 PKCE, trading, and account management
โ”‚   โ””โ”€โ”€ websocket_server.py          # Real-time WebSocket server for live UI push updates
โ”‚
โ”œโ”€โ”€ โš™๏ธ config/                        # Configuration
โ”‚   โ””โ”€โ”€ dart_config.py               # Pydantic v2 SOTA configuration settings and validator
โ”‚
โ”œโ”€โ”€ ๐Ÿง  ml/                            # Machine Learning Core
โ”‚   โ”œโ”€โ”€ deep_rl_agent.py             # Soft Actor-Critic with attention & curiosity modules
โ”‚   โ”œโ”€โ”€ trading_ai_v3.py             # Ensemble learning (RF + GB + MLP) and strategy generation
โ”‚   โ”œโ”€โ”€ feature_extractor.py         # 50+ technical indicators and sentiment analysis
โ”‚   โ”œโ”€โ”€ risk_manager.py              # Monte Carlo VaR, Kelly criterion, position sizing
โ”‚   โ”œโ”€โ”€ auto_trader.py               # Multi-symbol portfolio auto-trader with background monitoring
โ”‚   โ”œโ”€โ”€ backtester.py                # Event-driven backtesting framework with risk integration
โ”‚   โ”œโ”€โ”€ candlestick_patterns.py      # 8 vectorized candlestick pattern detectors
โ”‚   โ”œโ”€โ”€ evaluation_monitor.py        # Trade & model evaluation, W&B integration, degradation alerts
โ”‚   โ””โ”€โ”€ llm_market_analyzer.py       # LLM-powered market analysis via vLLM/OpenAI + LangChain
โ”‚
โ”œโ”€โ”€ ๐ŸŽจ ui/                            # User Interfaces
โ”‚   โ”œโ”€โ”€ app.py                       # Main desktop application (1900+ lines)
โ”‚   โ”œโ”€โ”€ modern_dashboard.py          # Streamlit web dashboard with glassmorphism & async caching
โ”‚   โ”œโ”€โ”€ chart_styles.py              # Chart theming and visualization
โ”‚   โ””โ”€โ”€ ui_theme.py                  # Theme management (dark/light modes)
โ”‚
โ”œโ”€โ”€ ๐Ÿ”ง utils/                         # Utilities
โ”‚   โ”œโ”€โ”€ api_utils.py                 # Circuit breaker, retry logic, and error handling
โ”‚   โ”œโ”€โ”€ logging.py                   # Structured logging with structlog
โ”‚   โ””โ”€โ”€ timeframe.py                 # Timeframe conversions
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ models/                        # Saved ML models (runtime generated)
โ”œโ”€โ”€ ๐Ÿ“ logs/                          # Trading logs and performance data
โ”œโ”€โ”€ ๐Ÿ“ tests/                         # Unit and integration tests (54 tests)
โ”‚
โ”œโ”€โ”€ ๐Ÿš€ main.py                        # Desktop app entry point
โ””โ”€โ”€ ๐Ÿ“‹ pyproject.toml                 # Dependencies and project metadata

Component Diagram

graph TB
    subgraph "Data Layer"
        API[Deriv API Client]
        FE[Feature Extractor]
        CP[Candlestick Patterns]
        LLM[LLM Market Analyzer]
    end
    
    subgraph "AI Core"
        SAC[Soft Actor-Critic]
        ENS[Ensemble Models]
        MRD[Market Regime Detector]
        UQ[Uncertainty Estimator]
    end
    
    subgraph "Risk Layer"
        RM[Risk Manager]
        PS[Position Sizer]
        DP[Drawdown Protection]
    end
    
    subgraph "Execution"
        AT[Auto Trader]
        TL[Trade Logger]
        BT[Backtester]
        EM[Evaluation Monitor]
    end
    
    subgraph "UI Layer"
        GUI[Desktop App]
        WEB[Web Dashboard]
        WS[WebSocket Server]
    end
    
    API --> FE
    FE --> CP
    FE --> SAC
    FE --> ENS
    LLM --> ENS
    SAC --> MRD
    ENS --> UQ
    MRD --> RM
    UQ --> RM
    RM --> PS
    PS --> AT
    DP --> AT
    AT --> TL
    AT --> EM
    AT --> API
    AT --> WS
    BT --> RM
    GUI --> AT
    WEB --> WS
Loading

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.14+ (required)
  • uv - Fast Python package installer

Quick Start

# 1. Clone the repository
git clone https://github.com/ItzSwapnil/DART.git
cd DART

# 2. Install uv (if not already installed)
# Windows (PowerShell)
curl -LsSf https://astral.sh/uv/install.ps1 | powershell

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# 3. Create virtual environment and install dependencies
uv venv .venv

# Activate (Windows)
.venv\Scripts\activate

# Activate (macOS/Linux)
source .venv/bin/activate

# 4. Install DART
uv pip install -e .

# 5. (Optional) Install deep learning extras
uv pip install -e ".[deep-learning]"

Verify Installation

python -c "import torch; print(f'PyTorch: {torch.__version__}')"
python -c "from ml.trading_ai_v3 import TradingAIv3; print('DART AI: OK')"

๐ŸŽฎ Usage

๐Ÿ–ฅ๏ธ Desktop Application

# Launch the main application
python main.py

Quick Guide:

  1. Select a market from the dropdown (e.g., Volatility 75 Index)
  2. Choose your timeframe (1 minute to 1 day)
  3. Click "Train Model" to train AI on 7 days of historical data
  4. Adjust the confidence threshold slider (higher = fewer but more confident trades)
  5. Click "Start Auto-Trading" to begin automated trading
  6. Monitor real-time performance in the trading dashboard

๐ŸŒ Web Dashboard

# Launch the Streamlit dashboard
streamlit run ui/modern_dashboard.py

The web dashboard features:

  • Real-time AI insights with epistemic/aleatoric uncertainty display
  • Interactive candlestick charts with technical indicators
  • Live performance metrics and trade history
  • Non-blocking async data fetching with background caching (zero UI freeze)
  • WebSocket real-time push updates from the Auto Trader
  • Multi-symbol portfolio trading support
  • Glassmorphism UI design with dark mode

๐Ÿ“Š Sample Trading Session

from ml.trading_ai_v3 import TradingAIv3
from api.deriv_client import DerivClient

# Initialize components
client = DerivClient(
    app_id="72212",
    access_token="YOUR_ACCESS_TOKEN",
    account_id="YOUR_ACCOUNT_ID"
)
ai = TradingAIv3(use_llm=True)

# Get historical data and train
data = await client.get_historical_data("R_75", 60, days=7)
ai.train(data)

# Generate strategy
current_data = await client.get_candles("R_75", 60, count=100)
strategy = ai.generate_strategy(current_data, use_llm=True)

print(f"Direction: {strategy['direction']}")
print(f"Confidence: {strategy['confidence']:.2%}")
print(f"Uncertainty: {strategy['uncertainty']:.4f}")

โš™๏ธ Configuration

API Setup (Required for Trading)

DART v3.0+ uses secure OAuth 2.0 PKCE authentication.

  1. Create a Deriv.com account.
  2. Register an application in the Deriv Developer Portal to obtain your App ID and OAuth Client ID. Set the Redirect URI to http://localhost:8080/callback.
  3. Set your environment variables in .env (located in the project root):
DERIV_APP_ID=your_app_id
DERIV_OAUTH_CLIENT_ID=your_client_id
DERIV_OAUTH_REDIRECT_URI=http://localhost:8080/callback
DERIV_ACCESS_TOKEN=your_access_token
DERIV_ACCOUNT_ID=your_account_id

Key Configuration Options

Setting Description Default
TRADE_AMOUNT Stake per trade 1.0
MAX_DAILY_LOSS Daily loss limit 50.0
CONFIDENCE_THRESHOLD Min confidence for trades 0.65
TRAINING_DAYS Historical data for training 7
MAX_CONSECUTIVE_LOSSES Losses before strategy recalc 3

Risk Management Settings

# config/dart_config.py
MAX_PORTFOLIO_RISK = 0.02        # 2% portfolio risk per trade
MAX_DRAWDOWN_THRESHOLD = 0.15   # 15% max drawdown
VAR_CONFIDENCE_LEVELS = [0.95, 0.99]  # VaR confidence

๐Ÿงฐ Dependencies

Core Dependencies

Package Purpose
torch>=2.9.1 Deep learning (SAC, neural networks)
scikit-learn>=1.8.0 Ensemble models, preprocessing
pandas>=2.3.3 Data manipulation
numpy>=2.4.0 Numerical computing
ta>=0.11.0 Technical analysis indicators
python-deriv-api>=0.1.6 Deriv.com API client
customtkinter>=5.2.2 Modern desktop UI
streamlit>=1.52.0 Web dashboard
matplotlib>=3.10.8 Chart visualization
plotly>=6.5.1 Interactive charts

Optional Dependencies

# Deep learning extras
uv pip install -e ".[deep-learning]"

# Development tools
uv pip install -e ".[dev]"

# Additional data sources
uv pip install -e ".[data-sources]"

๐Ÿ“ˆ Performance & Metrics

DART tracks comprehensive performance metrics:

  • Win Rate: Percentage of profitable trades
  • Sharpe Ratio: Risk-adjusted returns
  • Sortino Ratio: Downside risk-adjusted returns
  • Maximum Drawdown: Largest peak-to-trough decline
  • Calmar Ratio: Return/drawdown ratio
  • Value at Risk (VaR): 95% and 99% confidence
  • Expected Shortfall (CVaR): Tail risk measure

๐Ÿ›ฃ๏ธ Roadmap

Completed โœ…

  • Deep Reinforcement Learning (Soft Actor-Critic)
  • Ensemble ML with stacking meta-learner
  • Advanced risk management (VaR, Kelly, drawdown)
  • Market regime detection (7 regimes)
  • Uncertainty quantification
  • Web dashboard with Streamlit
  • Multi-modal feature extraction (50+ indicators)
  • Pattern recognition (8 candlestick patterns)
  • Backtesting framework
  • Portfolio management (multi-symbol, multi-position)
  • WebSocket real-time updates
  • Non-blocking async dashboard with background caching
  • LLM-powered market analysis (vLLM/OpenAI)

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

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

Development Setup

# Install dev dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Code formatting & linting
ruff format .
ruff check .

๐Ÿ“„ License

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


๐Ÿ™ Acknowledgments


Built with โค๏ธ for the future of algorithmic trading

Report Bug โ€ข Request Feature

Releases

Packages

Used by

Contributors

Languages