Skip to main content

autohedge - TGSC

Project description

AutoHedge 🚀

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

PyPI version License: MIT Python 3.8+ Documentation Status Code style: black

Build your autonomous hedge fund in minutes. AutoHedge harnesses the power of swarm intelligence and AI agents to automate market analysis, risk management, and trade execution.

🌟 Features

  • Multi-Agent Architecture: Leverages specialized AI agents for different aspects of trading

    • Director Agent for strategy and thesis generation
    • Quant Agent for technical analysis
    • Risk Management Agent for position sizing and risk assessment
    • Execution Agent for trade implementation
  • Real-Time Market Analysis: Integrates with market data providers for live analysis

  • Risk-First Approach: Built-in risk management and position sizing

  • Structured Output: JSON-formatted trade recommendations and analysis

  • Comprehensive Logging: Detailed logging system for trade tracking and debugging

  • Extensible Framework: Easy to customize and extend with new capabilities

📋 Requirements

  • Python 3.8+
  • swarms package
  • tickr-agent
  • Additional dependencies listed in requirements.txt

🚀 Quick Start

Installation

pip install -U autohedge

Environment Variables

OPENAI_API_KEY=""
WORKSPACE_DIR="agent_workspace"

Basic Usage

# Example usage
from autohedge import AutoFund

# Define the stocks to analyze
stocks = ["NVDA"]

# Initialize the trading system with the specified stocks
trading_system = AutoFund(stocks)

# Define the task for the trading cycle
task = "Let's analyze nvidia to see if we should buy it, we have 50k$ in allocation"

# Run the trading cycle and print the results
print(trading_system.run(task=task))

🏗️ Architecture

AutoHedge uses a multi-agent architecture where each agent specializes in a specific aspect of the trading process:

graph TD
    A[Director Agent] --> B[Quant Agent]
    B --> C[Risk Manager]
    C --> D[Execution Agent]
    D --> E[Trade Output]

Agent Roles

  1. Director Agent

    • Generates trading theses
    • Coordinates overall strategy
    • Analyzes market conditions
  2. Quant Agent

    • Performs technical analysis
    • Evaluates statistical patterns
    • Calculates probability scores
  3. Risk Manager

    • Assesses trade risks
    • Determines position sizing
    • Sets risk parameters
  4. Execution Agent

    • Generates trade orders
    • Sets entry/exit points
    • Manages order execution

📊 Output Format

AutoHedge generates structured output using Pydantic models:

class AutoHedgeOutput(BaseModel):
    id: str                         # Unique identifier
    name: Optional[str]             # Strategy name
    description: Optional[str]      # Strategy description
    stocks: Optional[List[str]]     # List of stocks
    task: Optional[str]             # Analysis task
    thesis: Optional[str]           # Trading thesis
    risk_assessment: Optional[str]  # Risk analysis
    order: Optional[Dict]           # Trade order details
    timestamp: str                  # Timestamp
    current_stock: str              # Current stock being analyzed

🔧 Configuration

AutoHedge can be configured through environment variables or initialization parameters:

trading_system = AutoFund(
    name="CustomStrategy",
    description="My Trading Strategy",
    stocks=["NVDA", "AAPL"],
    output_dir="custom_outputs"
)

📝 Logging

AutoHedge uses the loguru library for comprehensive logging:

logger.add(
    "trading_system_{time}.log",
    rotation="500 MB",
    retention="10 days",
    level="INFO",
    format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}"
)

🔍 Advanced Usage

Custom Agent Configuration

from autohedge import TradingDirector, QuantAnalyst, RiskManager

# Custom director configuration
director = TradingDirector(
    stocks=["NVDA", "AAPL"],
    output_dir="custom_outputs"
)

# Custom analysis
analysis = director.generate_thesis(
    task="Generate comprehensive analysis",
    stock="NVDA"
)

Risk Management

from autohedge import RiskManager

risk_manager = RiskManager()
assessment = risk_manager.assess_risk(
    stock="NVDA",
    thesis=thesis,
    quant_analysis=analysis
)

Diagrams

🏗️ System Architecture

High-Level Component Overview

flowchart TB
    subgraph Client
        A[AutoHedge Client] --> B[Trading System]
    end
    
    subgraph Agents["Multi-Agent System"]
        B --> C{Director Agent}
        C --> D[Quant Agent]
        C --> E[Risk Agent]
        C --> F[Execution Agent]
        
        D --> G[Technical Analysis]
        D --> H[Statistical Analysis]
        
        E --> I[Risk Assessment]
        E --> J[Position Sizing]
        
        F --> K[Order Generation]
        F --> L[Trade Execution]
    end
    
    subgraph Output
        K --> M[JSON Output]
        L --> N[Trade Logs]
    end

Trading Cycle Sequence

sequenceDiagram
    participant C as Client
    participant D as Director
    participant Q as Quant
    participant R as Risk
    participant E as Execution
    
    C->>D: Initialize Trading Cycle
    activate D
    D->>D: Generate Thesis
    D->>Q: Request Analysis
    activate Q
    Q-->>D: Return Analysis
    deactivate Q
    D->>R: Request Risk Assessment
    activate R
    R-->>D: Return Risk Profile
    deactivate R
    D->>E: Generate Order
    activate E
    E-->>D: Return Order Details
    deactivate E
    D-->>C: Return Complete Analysis
    deactivate D

Trade State Machine

stateDiagram-v2
    [*] --> Initialization
    Initialization --> ThesisGeneration
    
    ThesisGeneration --> QuantAnalysis
    QuantAnalysis --> RiskAssessment
    
    RiskAssessment --> OrderGeneration: Risk Approved
    RiskAssessment --> ThesisGeneration: Risk Rejected
    
    OrderGeneration --> OrderExecution
    OrderExecution --> Monitoring
    
    Monitoring --> ThesisGeneration: New Cycle
    Monitoring --> [*]: Complete

Data Flow

flowchart LR
    subgraph Input
        A[Market Data] --> B[Technical Indicators]
        A --> C[Fundamental Data]
    end
    
    subgraph Processing
        B --> D[Quant Analysis]
        C --> D
        D --> E[Risk Analysis]
        E --> F[Order Generation]
    end
    
    subgraph Output
        F --> G[Trade Orders]
        F --> H[Risk Reports]
        F --> I[Performance Metrics]
    end

Class Structure

classDiagram
    class AutoFund {
        +String name
        +String description
        +List stocks
        +Path output_dir
        +run()
    }
    
    class TradingDirector {
        +Agent director_agent
        +TickrAgent tickr
        +generate_thesis()
    }
    
    class QuantAnalyst {
        +Agent quant_agent
        +analyze()
    }
    
    class RiskManager {
        +Agent risk_agent
        +assess_risk()
    }
    
    class ExecutionAgent {
        +Agent execution_agent
        +generate_order()
    }
    
    AutoFund --> TradingDirector
    AutoFund --> QuantAnalyst
    AutoFund --> RiskManager
    AutoFund --> ExecutionAgent

🤝 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 some 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


Created with ❤️ by The Swarm Corporation

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

autohedge-0.0.6.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autohedge-0.0.6-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file autohedge-0.0.6.tar.gz.

File metadata

  • Download URL: autohedge-0.0.6.tar.gz
  • Upload date:
  • Size: 12.9 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 autohedge-0.0.6.tar.gz
Algorithm Hash digest
SHA256 b85092a3003cf7bfc2cff4a61c9a27b346e4c2117980c225b886f8920980d7c7
MD5 abc0327e0ea2fc4ab77a69381f038361
BLAKE2b-256 e76db04962cac778b8f76c65448e92379584b0a8fb731c29ff4174cac4a4b05a

See more details on using hashes here.

File details

Details for the file autohedge-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: autohedge-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.3.0

File hashes

Hashes for autohedge-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2b97ece87cd23a99b2c9a54d5f2d644080727aa3b8b1417f8d007f42b3debd13
MD5 f815806a457d3a70c1ae3fd345c5900f
BLAKE2b-256 0589a0d7154492331e5f1e750b816bee25fc15bae27ece3494beb272289c88ee

See more details on using hashes here.

Supported by

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