Quick Start
This guide will get you up and running with TradingAgents in under 5 minutes. We'll walk through a basic example of using the framework to analyze a stock and make a trading decision.
Prerequisites
Before starting, ensure you have:
- ✅ Completed the Installation
- ✅ Set up your API keys (FinnHub and OpenAI)
- ✅ Activated your virtual environment
Basic Usage Example
Here's a simple example to get you started with TradingAgents:
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG
# Initialize TradingAgents with default configuration
ta = TradingAgentsGraph(debug=True, config=DEFAULT_CONFIG.copy())
# Analyze NVIDIA stock for a specific date
symbol = "NVDA"
date = "2024-05-10"
# Run the multi-agent analysis
state, decision = ta.propagate(symbol, date)
# Print the trading decision
print(f"Trading Decision for {symbol} on {date}:")
print(decision)
Understanding the Output
The propagate()
method returns two values:
- State: Contains all intermediate analysis from different agents
- Decision: The final trading recommendation
A typical decision output includes:
- Action: BUY, SELL, or HOLD
- Confidence: Decision confidence score
- Reasoning: Summary of analysis
- Risk Assessment: Identified risks and mitigation strategies
Customizing the Configuration
You can customize the framework behavior by modifying the configuration:
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG
# Create custom configuration
custom_config = DEFAULT_CONFIG.copy()
# Use different LLM models (cost-effective for testing)
custom_config["deep_think_llm"] = "gpt-4o-mini"
custom_config["quick_think_llm"] = "gpt-4o-mini"
# Adjust debate rounds (fewer rounds = faster execution)
custom_config["max_debate_rounds"] = 1
# Enable/disable online data tools
custom_config["online_tools"] = True
# Initialize with custom config
ta = TradingAgentsGraph(debug=True, config=custom_config)
# Run analysis
_, decision = ta.propagate("AAPL", "2024-05-10")
print(decision)
Configuration Options
Key configuration parameters you can adjust:
Parameter | Description | Default | Options |
---|---|---|---|
deep_think_llm | Model for complex analysis | o1-preview | o1-preview , gpt-4o , gpt-4o-mini |
quick_think_llm | Model for quick responses | gpt-4o | gpt-4o , gpt-4o-mini |
max_debate_rounds | Number of researcher debates | 3 | 1-5 |
online_tools | Use real-time vs cached data | False | True , False |
Data Sources
Online Tools (Recommended for Experimentation)
When online_tools = True
, agents access:
- Real-time market data via FinnHub API
- Current news and sentiment data
- Live technical indicators
Cached Data (Default)
When online_tools = False
, agents use:
- Curated historical data from Tauric TradingDB
- Pre-processed technical indicators
- Historical news and sentiment data
Common Use Cases
1. Single Stock Analysis
# Analyze a specific stock on a specific date
_, decision = ta.propagate("TSLA", "2024-03-15")
2. Multiple Stock Comparison
stocks = ["AAPL", "GOOGL", "MSFT", "NVDA"]
date = "2024-05-10"
results = {}
for stock in stocks:
_, decision = ta.propagate(stock, date)
results[stock] = decision
# Compare decisions
for stock, decision in results.items():
print(f"{stock}: {decision['action']} (Confidence: {decision['confidence']})")
3. Time Series Analysis
import datetime
symbol = "AAPL"
dates = ["2024-05-01", "2024-05-02", "2024-05-03"]
for date in dates:
_, decision = ta.propagate(symbol, date)
print(f"{date}: {decision['action']}")
Performance Tips
For Testing and Development
- Use
gpt-4o-mini
models to reduce API costs - Set
max_debate_rounds = 1
for faster execution - Enable
debug=True
to see detailed logs
For Production Analysis
- Use
o1-preview
for deep analysis tasks - Increase
max_debate_rounds
for more thorough debates - Enable
online_tools
for real-time data
Next Steps
Now that you're up and running:
- Explore Agent Details: Learn about individual agents
- Try the CLI: Use the command-line interface
- View Examples: Check out advanced examples
- Understand Configuration: Read the API documentation
Troubleshooting
If you encounter issues:
- API Errors: Verify your API setup
- Model Errors: Check troubleshooting guide
- Performance Issues: Review optimization tips