community_usecase/a_share_investment_agent_camel/README_EN.md
English | äøę | Acknowledgements | Example Results
</h4> </div> <div align="center"> </div>This project is a multi-agent A-share investment analysis system based on the OWL framework and Camel framework (v0.2.36), which completes investment analysis through multiple professional role agents working together to provide investment decision recommendations for users. The system adopts multi-model support and can flexibly use different large language models (such as Gemini, OpenAI, Qwen) for analysis.
This project participated in the OWL community use case challenge and is an improved version of the open-source project A_Share_investment_Agent, restructured using the OWL and Camel frameworks.
The system architecture includes the following core agents:
git clone https://github.com/camel-ai/owl.git
cd owl/community_usecase/a_share_investment_agent_camel
pip install -r requirements.txt
# Gemini Configuration
GEMINI_API_KEY=your_gemini_api_key
GEMINI_MODEL=gemini-1.5-flash
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key
OPENAI_MODEL=gpt-4o
# Qwen Configuration
QWEN_API_KEY=your_qwen_api_key
QWEN_MODEL=qwen-max
QWEN_API_URL=https://your-qwen-api-endpoint
To simplify the installation process, we provide Docker support.
docker build -t a-share-investment-agent .
# Create a .env file with the same format as above
touch .env
# Edit the .env file to add your API keys
python src/main.py --ticker 000001 --model qwen
# Use default parameters (Qwen model and 000001 stock) for testing
python src/main.py --test
# Specify stock for testing
python src/main.py --test --ticker 600036
--ticker: Stock code--start-date: Start date (YYYY-MM-DD)--end-date: End date (YYYY-MM-DD)--show-reasoning: Display analysis reasoning process--num-of-news: Number of news used for sentiment analysis--initial-capital: Initial cash amount--initial-position: Initial stock position--model: Model to use (gemini, openai, qwen)--test: Run test function with preset parametersBelow is an example of the analysis results for Cambricon-U (688256) stock during the period 2025/01/04-2025/03/24:
python src/main.py --ticker 688256 --start-date 2025-01-04 --end-date 2025-03-24 --model qwen --show-reasoning
Market Data Agent:
{
"trend": "Short-term trend is downward, but long-term trend still needs observation",
"judgment": "Current price is below the middle Bollinger band, RSI is close to neutral level, MACD line is below the signal line, indicating short-term adjustment may continue. However, considering the previous significant rise, the long-term trend still needs further observation. Recommend paying attention to support level 670.66 and resistance level 747.57."
}
Technical Analyst:
{
"signal": "bearish",
"confidence": 0.8,
"reasoning": "From technical indicators, the stock is currently in a relatively weak state. First, the 5-day moving average (718.856) has crossed below the 10-day (743.927) and 20-day (747.574) moving averages, indicating the short-term trend is weakening. The MACD indicator also shows a similar trend, with the MACD line (8.994) below the signal line (20.004), and the MACD histogram (-11.009) negative, indicating market momentum is weakening. The RSI indicator (48.676) is in neutral territory but approaching oversold territory, which may indicate a short-term rebound, but the overall trend remains weak. On the Bollinger Bands, the current price (685.05) is close to the lower band (670.657), which may provide some support, but considering the weakness shown by other indicators, the support may be limited. Overall, the current market environment and technical indicators point toward a bearish trend."
}
Fundamentals Analyst:
{
"signal": "bearish",
"confidence": 0.8,
"reasoning": "Cambricon-U's financial condition and business performance show clear negative trends. First, the company's net profit continues to be negative, and the loss amount has increased in recent quarters, indicating serious problems with profitability. Second, although the company's operating revenue increased in the fourth quarter of 2023, it experienced a significant decline in subsequent quarters, which may indicate a decrease in market demand or company market share. Additionally, the company's P/E ratio is negative, and its P/B ratio is as high as 52.58, indicating overvaluation in the market with significant bubble risk. From a financial health perspective, although the company has a low debt-to-asset ratio, its operating cash flow continues to be negative, indicating the company faces significant financial pressure in operations. Considering these factors, we believe Cambricon-U's stock is currently bearish."
}
Sentiment Analyst:
{
"signal": "bullish",
"confidence": 0.8,
"reasoning": "From the news data, the overall market sentiment is positive, with positive news far outnumbering negative news. Although one news item mentions the decline of chip ETFs and Cambricon-U, most news emphasizes the positive performance of Cambricon-U and its sector, including stock price increases and technological breakthroughs. Additionally, the news of Cambricon-U being included in the FTSE China A50 Index indicates the market's optimistic outlook for its long-term prospects. Social media discussions also mainly focus on the company's positive developments, further supporting the bullish view.",
"key_events": [
"Cambricon-U included in FTSE China A50 Index",
"Cambricon-U stock price rises multiple times",
"AI AIETF holding stock Cambricon-U surges",
"ZhiYuan QiYuan large model released"
]
}
Valuation Analyst:
{
"signal": "bearish",
"confidence": 0.85,
"reasoning": "Cambricon-U's financial condition and business performance show clear negative trends. First, the company's net profit continues to be negative, and the loss amount has increased in recent quarters, indicating serious problems with profitability. Second, although the company's operating revenue increased in the fourth quarter of 2023, it experienced a significant decline in subsequent quarters, which may indicate a decrease in market demand or company market share. Additionally, the company's P/E ratio is negative, and its P/B ratio is as high as 52.58, indicating overvaluation in the market with significant bubble risk. From a financial health perspective, although the company has a low debt-to-asset ratio, its operating cash flow continues to be negative, indicating the company faces significant financial pressure in operations. Considering these factors, we believe Cambricon-U's stock is currently bearish. Furthermore, calculated through DCF model and relative valuation methods, the company's intrinsic value is significantly lower than the current market price, further supporting the bearish view.",
"fair_value": 200.0,
"key_metrics": [
"P/E Ratio",
"P/B Ratio",
"Operating Revenue",
"Net Profit",
"Operating Cash Flow"
]
}
Researcher Bull:
{
"key_points": [
"Market sentiment is positive, news and social media discussions lean optimistic",
"Cambricon-U included in FTSE China A50 Index, indicating market's optimistic outlook for its long-term prospects",
"Positive news of technological breakthroughs and stock price increases",
"Despite weakness in technical and fundamental aspects, market sentiment and potential catalysts may drive stock price rebound"
],
"confidence": 0.6,
"reasoning": "Despite technical and fundamental analysis showing Cambricon-U is currently in a weak state, market sentiment and potential catalysts may drive stock price rebound. Cambricon-U being included in the FTSE China A50 Index indicates the market's optimistic outlook for its long-term prospects. Additionally, recent positive news about technological breakthroughs and stock price increases also support the bullish view. Although current financial conditions and valuations are high, market sentiment and potential positive factors may provide support for the stock price. Therefore, we recommend maintaining caution in the short term, but in the long term, Cambricon-U still has investment potential."
}
Researcher Bear:
{
"key_points": [
"Technical indicators show short-term trend weakening",
"Net profit continues to be negative and losses increase",
"Declining operating revenue indicates decreased market demand",
"P/B ratio as high as 52.58, overvalued",
"Operating cash flow continues to be negative, significant financial pressure",
"DCF model and relative valuation methods show intrinsic value lower than market price"
],
"confidence": 0.8,
"reasoning": "Combining technical analysis, fundamental analysis, market sentiment analysis, and valuation analysis, Cambricon-U's stock is currently bearish. Technical indicators show short-term trend weakening, fundamental analysis shows poor profitability, decreased market demand, overvaluation, and significant financial pressure. Although market sentiment leans positive, these positive sentiments mainly focus on short-term events and cannot mask long-term fundamental issues. Valuation analysis further supports the bearish view, with intrinsic value significantly lower than current market price. Therefore, selling Cambricon-U stock is recommended."
}
Debate Room:
{
"signal": "neutral",
"confidence": 0.7,
"reasoning": "Both bull and bear researchers' views have rationality and basis. The bull researcher emphasizes positive market sentiment, Cambricon-U's inclusion in the FTSE China A50 Index, and positive news about technological breakthroughs and stock price increases, which may provide support for the stock price in the short term. However, the bear researcher points out technical indicators show short-term trend weakening, fundamental analysis shows poor profitability, decreased market demand, overvaluation, and significant financial pressure. Although market sentiment leans positive, these positive sentiments mainly focus on short-term events and cannot mask long-term fundamental issues. Overall, in the short term, market sentiment and technological breakthroughs may drive stock price rebound, but long-term fundamental issues still exist, so maintaining a neutral attitude and waiting for more clear signals is recommended.",
"final_verdict": "Investors are advised to remain cautious in the short term and pay attention to the continuity of market sentiment and technological breakthroughs. In the long term, close attention should be paid to the company's fundamental improvements, especially in areas such as profitability, market demand, and financial pressure. Before more clear signals emerge, maintaining a neutral attitude and avoiding excessive optimism or pessimism is recommended."
}
Risk Manager:
{
"max_position_size": 0.2,
"volatility": 0.15,
"risk_score": 0.7,
"max_drawdown": 0.25,
"suggested_position_size": 0.15,
"reasoning": "Given stock 688256's high volatility and fundamental risks, a cautious approach is recommended. Although there is potential for technical breakthrough in the short term, the company faces issues such as poor profitability in the long term. Therefore, it is recommended to control position ratio not exceeding 20% and set appropriate stop-loss points to protect capital. At the same time, diversify investments to spread risk."
}
Portfolio Manager (Final Decision):
{
"action": "hold",
"quantity": 0,
"confidence": 0.8,
"reasoning": "Considering various analysts' trading signals, debate results, risk analysis, current portfolio status, and latest market price, we decide to adopt a holding strategy for stock 688256. Technical analysis and fundamental analysis both show the stock is in a weak state, with technical indicators showing short-term trend weakening, and fundamentals showing poor profitability, decreased market demand, overvaluation, and significant financial pressure. Although sentiment analysis shows positive market sentiment, these positive sentiments mainly focus on short-term events and cannot mask long-term fundamental issues. The debate result also recommends caution in the short term, paying attention to the continuity of market sentiment and technological breakthroughs. In the long term, close attention should be paid to the company's fundamental improvements. Risk analysis recommends controlling position ratio not exceeding 20% and setting appropriate stop-loss points to protect capital. Therefore, we decide to temporarily hold the stock and wait for more clear signals."
}
Final Investment Decision: Hold (Confidence: 0.8)
The analysis results from multiple professional agents indicate that Cambricon-U (688256) stock is currently in a weak state in terms of technicals and fundamentals, but market sentiment and short-term events may provide support for the stock price. Considering all factors, the system recommends adopting a holding strategy for this stock and closely monitoring subsequent changes in fundamentals and market sentiment. At the same time, risk management recommends controlling the maximum position ratio of this stock to within 20% of the portfolio and setting appropriate stop-loss points to control risk.
The system's data process follows these steps:
community_usecase/a_share_investment_agent_camel/
āāā src/ # Source code directory
ā āāā agents/ # Agent implementations
ā ā āāā base_agent.py # Base agent class
ā ā āāā market_data_agent.py # Market data agent
ā ā āāā technical_analyst.py # Technical analyst agent
ā ā āāā ...
ā āāā tools/ # Tool modules
ā ā āāā data_helper.py # Data helper tools
ā āāā utils/ # Utility tools
ā ā āāā logging_utils.py # Logging tools
ā āāā models.py # Data model definitions
ā āāā roles.py # Role definitions
ā āāā main.py # Main program
āāā tests/ # Test directory
āāā logs/ # Log files
āāā .env # Environment variables
āāā pyproject.toml # Poetry configuration
āāā requirements.txt # Dependencies
āāā README.md # Documentation
This project implements 10 professional role agents, with each agent responsible for specific tasks in the investment analysis process. Agents collaborate through message passing, forming a complete analysis decision chain.
# Create agents
market_data_agent = MarketDataAgent(show_reasoning=show_reasoning, model_name=model_name)
technical_analyst = TechnicalAnalystAgent(show_reasoning=show_reasoning, model_name=model_name)
fundamentals_analyst = FundamentalsAnalystAgent(show_reasoning=show_reasoning, model_name=model_name)
sentiment_analyst = SentimentAnalystAgent(show_reasoning=show_reasoning, model_name=model_name)
valuation_analyst = ValuationAnalystAgent(show_reasoning=show_reasoning, model_name=model_name)
researcher_bull = ResearcherBullAgent(show_reasoning=show_reasoning, model_name=model_name)
researcher_bear = ResearcherBearAgent(show_reasoning=show_reasoning, model_name=model_name)
debate_room = DebateRoomAgent(show_reasoning=show_reasoning, model_name=model_name)
risk_manager = RiskManagerAgent(show_reasoning=show_reasoning, model_name=model_name)
portfolio_manager = PortfolioManagerAgent(show_reasoning=show_reasoning, model_name=model_name)
The system supports multiple large language models including Gemini, OpenAI, and Qwen, implementing flexible switching through a unified interface.
def get_llm_client(model_name: str):
"""Get the specified LLM client"""
if model_name.lower() == 'gemini':
return GeminiClient()
elif model_name.lower() == 'openai':
return OpenAIClient()
elif model_name.lower() == 'qwen':
return QwenClient()
else:
raise ValueError(f"Unsupported model: {model_name}")
Compared to the original version, the system restructured based on the Camel framework has the following innovations and improvements:
This project is for educational and research purposes only.
By using this software, you agree to use it for learning purposes only.
This project is improved based on the following open-source projects:
Thanks to all the original authors for their contributions and inspiration, providing a solid foundation for this project.