Go to file
quanliangliu 4f71df50ec
Update paths for confidence utilities and adapters
2025-12-07 20:50:07 -06:00
.vscode modification on evaluation part to include the SFT-model included agentic system 2025-12-07 19:47:28 -06:00
Finllama added SFT files 2025-11-21 16:07:51 -06:00
cli WIP 2025-09-26 16:17:50 +08:00
evaluation_buy_sell Replace old evaluation/ with evaluation_long_short/ and add evaluation_buy_sell/ 2025-11-10 11:47:20 -06:00
evaluation_long_short Removed personal path 2025-12-07 20:47:55 -06:00
tradingagents Update paths for confidence utilities and adapters 2025-12-07 20:50:07 -06:00
.env.example Add environment variable configuration support 2025-09-26 23:58:51 +08:00
.gitignore modification on evaluation part to include the SFT-model included agentic system 2025-12-07 19:47:28 -06:00
.python-version main works, cli bugs 2025-06-15 22:20:59 -07:00
LICENSE chore(release): v0.1.0 – initial public release of TradingAgents 2025-06-05 04:27:57 -07:00
README.md Plan updates to README.md 2025-11-09 15:55:56 -08:00
confidence.py New updates 2025-12-06 14:59:16 -06:00
main.py Switch default data vendor 2025-09-30 12:43:27 +08:00
pyproject.toml update readme 2025-10-06 20:33:12 -07:00
requirements.txt necessary req.txt 2025-12-07 17:27:02 -06:00
setup.py chore(release): v0.1.0 – initial public release of TradingAgents 2025-06-05 04:27:57 -07:00
test.py optimized yfin fetching to be much faster 2025-10-06 19:58:01 -07:00
test_dapt.py modification on evaluation part to include the SFT-model included agentic system 2025-12-07 19:47:28 -06:00
uv.lock update readme 2025-10-06 20:33:12 -07:00

README.md

📌 Note: This repository is a fork of the original TradingAgents repository from the paper "TradingAgents: Multi-Agents LLM Financial Trading Framework" (arXiv:2412.20138). This fork implements FinAgents, an extension that integrates a domain-adapted language model (FinLLaMA+) to enhance sentiment analysis and improve trading performance.


FinAgents: Multi-Agent Financial Trading with Domain-Adapted Language Models

FinAgents extends the TradingAgents framework by integrating FinLLaMA+, a fine-tuned version of Llama 3.18B trained via LoRA on financial filings, earnings calls, and labeled sentiment datasets. This domain-adapted model provides ticker-grounded, confidence-calibrated sentiment embeddings that enhance textual reasoning and improve decision precision in multi-agent trading systems.

🚀 FinAgents Framework | Installation | 🎬 Demo | 📦 Package Usage | 🤝 Contributing | 📄 Citation

FinAgents Framework

FinAgents extends the TradingAgents multi-agent trading framework, which mirrors the dynamics of real-world trading firms. By deploying specialized LLM-powered agents—from fundamental analysts, sentiment experts, and technical analysts, to trader and risk management teams—the platform collaboratively evaluates market conditions and informs trading decisions. These agents engage in dynamic discussions to pinpoint the optimal strategy.

Key Enhancements

FinLLaMA+ Integration: The framework integrates a domain-adapted language model (FinLLaMA+) that replaces the generic sentiment analysis used in the original TradingAgents. This enhancement includes:

  • Domain-Adaptive Pretraining (DAPT): Pre-training on earnings call transcripts (~304M tokens) to improve financial language understanding, achieving a 22.52% reduction in perplexity
  • Supervised Fine-Tuning (SFT): Fine-tuning on Financial PhraseBank and SemEval-2017 Task 5 datasets (~6,000 labeled examples) for sentiment classification
  • Ticker-Grounded Sentiment Analysis: Produces structured JSON outputs with sentiment polarity, confidence scores, and relevance metrics
  • Confidence-Weighted Aggregation: Aggregates multiple news items into daily sentiment scores using confidence-weighted means

Project Team

TradingAgents framework is designed for research purposes. Trading performance may vary based on many factors, including the chosen backbone language models, model temperature, trading periods, the quality of data, and other non-deterministic factors. It is not intended as financial, investment, or trading advice.

Our framework decomposes complex trading tasks into specialized roles. This ensures the system achieves a robust, scalable approach to market analysis and decision-making.

Analyst Team

  • Fundamentals Analyst: Evaluates company financials and performance metrics, identifying intrinsic values and potential red flags.
  • Sentiment Analyst: Analyzes social media and public sentiment using sentiment scoring algorithms to gauge short-term market mood.
  • News Analyst: Enhanced with FinLLaMA+ for domain-specialized sentiment analysis. Monitors global news and macroeconomic indicators, interpreting the impact of events on market conditions with improved financial language understanding.
  • Technical Analyst: Utilizes technical indicators (like MACD and RSI) to detect trading patterns and forecast price movements.

Researcher Team

  • Comprises both bullish and bearish researchers who critically assess the insights provided by the Analyst Team. Through structured debates, they balance potential gains against inherent risks.

Trader Agent

  • Composes reports from the analysts and researchers to make informed trading decisions. It determines the timing and magnitude of trades based on comprehensive market insights.

Risk Management and Portfolio Manager

  • Continuously evaluates portfolio risk by assessing market volatility, liquidity, and other risk factors. The risk management team evaluates and adjusts trading strategies, providing assessment reports to the Portfolio Manager for final decision.
  • The Portfolio Manager approves/rejects the transaction proposal. If approved, the order will be sent to the simulated exchange and executed.

Installation and CLI

Installation

Clone this fork:

git clone <YOUR_REPO_URL>
cd TradingAgents

Or clone the original repository:

git clone https://github.com/TauricResearch/TradingAgents.git
cd TradingAgents

Create a virtual environment in any of your favorite environment managers:

conda create -n tradingagents python=3.13
conda activate tradingagents

Install dependencies:

pip install -r requirements.txt

Required APIs

You will need the OpenAI API for all the agents, and Alpha Vantage API for fundamental and news data (default configuration).

export OPENAI_API_KEY=$YOUR_OPENAI_API_KEY
export ALPHA_VANTAGE_API_KEY=$YOUR_ALPHA_VANTAGE_API_KEY

Alternatively, you can create a .env file in the project root with your API keys (see .env.example for reference):

cp .env.example .env
# Edit .env with your actual API keys

Note: We are happy to partner with Alpha Vantage to provide robust API support for TradingAgents. You can get a free AlphaVantage API here, TradingAgents-sourced requests also have increased rate limits to 60 requests per minute with no daily limits. Typically the quota is sufficient for performing complex tasks with TradingAgents thanks to Alpha Vantage's open-source support program. If you prefer to use OpenAI for these data sources instead, you can modify the data vendor settings in tradingagents/default_config.py.

TradingAgents Package

Implementation Details

We built TradingAgents with LangGraph to ensure flexibility and modularity. We utilize o1-preview and gpt-4o as our deep thinking and fast thinking LLMs for our experiments. However, for testing purposes, we recommend you use o4-mini and gpt-4.1-mini to save on costs as our framework makes lots of API calls.

Python Usage

To use TradingAgents inside your code, you can import the tradingagents module and initialize a TradingAgentsGraph() object. The .propagate() function will return a decision. You can run main.py, here's also a quick example:

from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG

ta = TradingAgentsGraph(debug=True, config=DEFAULT_CONFIG.copy())

# forward propagate
_, decision = ta.propagate("NVDA", "2024-05-10")
print(decision)

You can also adjust the default configuration to set your own choice of LLMs, debate rounds, etc.

from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG

# Create a custom config
config = DEFAULT_CONFIG.copy()
config["deep_think_llm"] = "gpt-4.1-nano"  # Use a different model
config["quick_think_llm"] = "gpt-4.1-nano"  # Use a different model
config["max_debate_rounds"] = 1  # Increase debate rounds

# Configure data vendors (default uses yfinance and Alpha Vantage)
config["data_vendors"] = {
    "core_stock_apis": "yfinance",           # Options: yfinance, alpha_vantage, local
    "technical_indicators": "yfinance",      # Options: yfinance, alpha_vantage, local
    "fundamental_data": "alpha_vantage",     # Options: openai, alpha_vantage, local
    "news_data": "alpha_vantage",            # Options: openai, alpha_vantage, google, local
}

# Initialize with custom config
ta = TradingAgentsGraph(debug=True, config=config)

# forward propagate
_, decision = ta.propagate("NVDA", "2024-05-10")
print(decision)

The default configuration uses yfinance for stock price and technical data, and Alpha Vantage for fundamental and news data. For production use or if you encounter rate limits, consider upgrading to Alpha Vantage Premium for more stable and reliable data access. For offline experimentation, there's a local data vendor option available, though this is still in development.

You can view the full list of configurations in tradingagents/default_config.py.

FinLLaMA+ Model Details

Training Pipeline

  1. Domain-Adaptive Pretraining (DAPT)

    • Base model: Llama 3.18B
    • Dataset: Earnings call transcripts (~304M tokens, 20% of full dataset)
    • Method: QLoRA with 4-bit NF4 quantization
    • Training: 1 epoch on NVIDIA A40 GPU (~6 days)
    • Result: 22.52% perplexity reduction (6.4076 → 4.9649)
  2. Supervised Fine-Tuning (SFT)

    • Datasets: Financial PhraseBank + SemEval-2017 Task 5 (~6,000 examples)
    • Task: Sentiment classification (positive/neutral/negative/uncertain)
    • Method: LoRA (rank r=16, α=32, dropout=0.05)
    • Output: Structured JSON with sentiment, confidence, and relevance scores

Integration Architecture

FinLLaMA+ serves as a drop-in replacement for the News and Social Sentiment agents. It processes financial news and social media updates, producing structured outputs that are aggregated into daily sentiment scores per ticker. The model includes:

  • Caching and Deduplication: Content hash-based caching and embedding similarity filtering to reduce redundant LLM calls
  • Relevance Scoring: Hybrid semantic similarity and keyword matching to prioritize ticker-specific news
  • Market Sentiment Reports: Generates interpretable narrative summaries for the Researcher Team

Evaluation Metrics

Performance is evaluated using standard financial metrics:

  • Cumulative Return (CR): Total portfolio return over the evaluation period
  • Annualized Return (AR): Return normalized to an annual basis
  • Sharpe Ratio (SR): Risk-adjusted return metric
  • Maximum Drawdown (MDD): Largest peak-to-trough decline

Contributing

This is a fork implementing FinAgents extensions to the TradingAgents framework. For contributions to the original TradingAgents project, please refer to the original repository.

Citation

Original TradingAgents Paper

@misc{xiao2025tradingagentsmultiagentsllmfinancial,
      title={TradingAgents: Multi-Agents LLM Financial Trading Framework}, 
      author={Yijia Xiao and Edward Sun and Di Luo and Wei Wang},
      year={2025},
      eprint={2412.20138},
      archivePrefix={arXiv},
      primaryClass={q-fin.TR},
      url={https://arxiv.org/abs/2412.20138}, 
}

This project builds upon several key papers:

  • FinBERT (Araci, 2019): Domain-specific transformers for finance
  • FinLLaMA (Konstantinidis et al., 2024): Financial sentiment classification
  • Trading-R1 (Xiao et al., 2025a): Reinforcement learning for trading
  • ElliottAgents (Wawer & Chudziak, 2025): Multi-agent LLM-based forecasting