Skip to content

xhqing/MarketForecastingAgents

Repository files navigation

MarketForecastingAgents

An AI-powered automated market research report generation system based on multi-agent collaboration, covering A-shares, Hong Kong stocks, and US stocks.


Features

  • Multi-Agent Collaboration: Integrates four specialized investment agents — Livermore (trend following), Buffett (valuation anchoring), Cathie Wood (disruptive innovation), and Ray Dalio (macro cycles), each with unique analytical philosophies, providing multi-perspective market assessments.
  • Full Market Coverage: Supports A-shares (SSE/SZSE), Hong Kong stocks (HKEX), and US stocks (NYSE/NASDAQ), including indices, individual stocks, and ETFs.
  • Real-time Data Integration: Connects to multiple MCP (Model Context Protocol) servers for real-time quotes, financial statements, technical indicators, sector fund flows, and research report data.
  • Automated Validation: Built-in targets_validator.py ensures generated reports fully cover all configured targets with zero omissions; price_checker.py ensures all target prices are accurate and reasonable with zero pricing errors.
  • Flexible Target Configuration: All analysis targets are centrally managed through targets.json, allowing easy addition, removal, or modification at any time.

System Architecture

Agent Team

Agent Role Philosophy MCP / Capabilities
@Livermore Market Analyst Trend following, pivot point trading, volume-price confirmation Own MCP servers + web search + financial market analysis
@Buffett Valuation Anchor Intrinsic value, margin of safety, valuation ceiling/floor China Stock MCP + Market Data Fetcher + research reports
@CathieWood Innovation Investor Disruptive technology, cross-industry convergence, 5-year horizon FinanceKit + Market Data Fetcher + research reports
@RayDalio Macro Cycle Analyst Debt cycles, four-environment framework, liquidity-first AKShare + Market Data Fetcher + research reports
@SOLO Agent Coordinator Merges all agent outputs, saves reports, runs validation File system + command execution

MCP Servers

MCP Server Functionality Associated Agents
market-data-fetcher Fetches index, stock, and ETF data (Longport / AKShare / Yahoo Finance) Livermore, Buffett, CathieWood, RayDalio
financekit Stock quotes, company info, technical analysis, risk metrics, option chains CathieWood
china-stock-mcp A-share financial data, balance sheets, income statements, cash flow statements, shareholder information Buffett
mcp-aktools AKShare-based tools: stock indicators, sector fund flows, trading recommendations Livermore
financemcp-dcths Tonghuashun and East Money sector indices, constituent stocks, and daily quote data Livermore
akshare-one-mcp Historical data, real-time data, financial indicators (HTTP-based) Livermore, Buffett, RayDalio
Time Current time and timezone conversion All agents
FaXianBaoGao (Discover Reports) Research report search and content retrieval All agents
tushareMcp TuShare financial data API (HTTP-based) Buffett

Workflow

+------------------------------------------------------------------+
|                        User Instruction                           |
|  (Sent to SOLO Agent in TRAE CN SOLO mode)                       |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 1: Study Historical Reports                                |
|  All agents study historical analysis patterns in reports/       |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 2: Macro Framework First (RayDalio)                        |
|  RayDalio diagnoses the economic machine state, determines       |
|  short-term debt cycle position, evaluates four-environment      |
|  probabilities, providing macro top-down constraints for all     |
|  subsequent analysis                                             |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 3: Collect Real-time Data                                  |
|  Each agent uses MCP tools and WebSearch to gather latest data   |
|  WARNING: Every agent must return the latest price for each      |
|  target                                                          |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 4: Build Reference Prices                                  |
|  SOLO Agent collects prices from four agents, cross-validates,   |
|  then saves to reference_prices.json                             |
|  Missing prices must be supplemented via WebSearch               |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 5: Multi-Agent Discussion                                  |
|  5 agents jointly discuss and generate probability-weighted      |
|  scenario predictions for each target                            |
|  (Prices must come from reference_prices.json)                   |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 6: Merge and Save Report                                   |
|  SOLO Agent merges all outputs into a Markdown report            |
|  Saved to reports/                                               |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 7: Validate Prices                                         |
|  SOLO Agent runs price_checker.py                                |
|  If exit code = 1 -> Return to Step 4 to fix price issues       |
|  If exit code = 0 -> Continue                                    |
+---------------------------+--------------------------------------+
                            |
                            v
+------------------------------------------------------------------+
|  Step 8: Validate Coverage                                       |
|  SOLO Agent runs targets_validator.py                            |
|  If exit code = 1 -> Return to Step 1 and re-execute            |
|  If exit code = 0 -> Complete                                    |
+------------------------------------------------------------------+

Project Structure

MarketForecastingAgents
+-- .trae/
|   +-- mcp.json.example       # MCP server configuration template
|   +-- rules/
|       +-- toolcallingrules.md          # Tool calling rules
|       +-- report_generation_rules.md   # Report generation mandatory rules
+-- agents_info/
|   +-- Livermore_info.md      # Livermore agent prompt and instructions
|   +-- Buffet_info.md         # Buffett agent prompt and instructions
|   +-- CathieWood_info.md     # Cathie Wood agent prompt and instructions
|   +-- RayDalio_info.md       # Ray Dalio agent prompt and instructions
+-- reports/               # Generated reports
|   +-- ...
+-- report_examples/           # Static report templates for reference
|   +-- standard_report_with_confidence.md  # Standard report with confidence indicators
|   +-- early_format_report.md              # Early format reference
+-- targets.json               # Target configuration (indices, stocks, ETFs)
+-- targets_validator.py       # Report coverage validation script
+-- price_checker.py           # Report price validation script
+-- reference_prices.json      # Price validation reference prices (generated by SOLO Agent)
+-- .gitignore
+-- README.md                  # Project documentation
+-- CLAUDE.md                  # Project guide

Target Configuration (targets.json)

All analysis targets are centrally managed through the targets.json file in the project root, covering A-shares, Hong Kong stocks, and US stocks, with flexible configuration for indices, individual stocks, and ETFs. Users can directly edit this file to add or remove targets.

Structure

{
  "a_shares": {
    "index_major": [{"name": "...", "code": "000001.SH"}],
    "sse_stocks":   [{"name": "...", "code": "688981.SH"}],
    "sse_etf":      [{"name": "...", "code": "513310.SH"}],
    "szse_stocks":  [{"name": "...", "code": "000063.SZ"}],
    "szse_etf":     [{"name": "...", "code": ""}]
  },
  "hk_shares": {
    "index_major":  [{"name": "...", "code": "800000.HK"}],
    "hkex_stocks":  [{"name": "...", "code": "00700.HK"}],
    "hkex_etf":     [{"name": "...", "code": "02800.HK"}]
  },
  "us_shares": {
    "index_major":  [{"name": "...", "code": ".NDX"}],
    "stocks":       [{"name": "...", "code": "NVDA"}],
    "adr":          [{"name": "...", "code": "BABA"}],
    "etf":          [{"name": "...", "code": "QQQ"}]
  }
}

Current Preset Targets

  • A-share Indices: Shanghai Composite Index (000001.SH), Shenzhen Component Index (399001.SZ)
  • A-share Stocks: SMIC (688981.SH), ZTE Corporation (000063.SZ)
  • A-share ETFs: China-Korea Semiconductor (513310.SH)
  • HK Indices: Hang Seng Index (800000.HK), Hang Seng TECH Index (800700.HK)
  • HK Stocks: Tencent Holdings, Alibaba, Xiaomi, Kuaishou, JD.com, Meituan, SMIC, Pop Mart, CATL, BYD Company, Hong Kong Exchanges and Clearing, AIA Group, China Mobile, NetEase, Baidu Group, Li Auto, XPeng Inc., ANTA Sports, Horizon Robotics, and 40+ others
  • HK ETFs: Tracker Fund of Hong Kong (02800.HK), CSOP Hang Seng TECH Index ETF (03033.HK)
  • US Indices: Nasdaq 100 (.NDX), S&P 500 (.SPX)
  • US Stocks: NVIDIA (NVDA)
  • US ADRs: Alibaba (BABA)
  • US ETFs: QQQ, SPY

Note: Entries with empty name and code are placeholders. Please fill in or delete them as needed.


Report Validation

Coverage Validation (targets_validator.py)

The targets_validator.py script validates whether the generated report fully covers all targets defined in targets.json.

Usage

python targets_validator.py <report.md> [--targets <targets.json>]

Functionality

  1. Extracts all valid targets (entries with non-empty name and code) from targets.json
  2. Searches for each target's name or code in the report Markdown
  3. Output: list of missing targets, coverage statistics

Exit Codes

Exit Code Meaning
0 Fully covered, no omissions
1 Missing or extra targets found

Price Validation (price_checker.py)

The price_checker.py script validates whether the current price for each target in the report is complete and reasonable, preventing price fabrication or estimation errors.

Usage

python price_checker.py <report.md> [--targets <targets.json>] [--ref <reference_prices.json>] [--deviation <percentage>]

Functionality

  1. Extracts all valid targets from targets.json
  2. Extracts the "current price" field for each target in the report Markdown
  3. Checks four types of issues:
    • Missing price — Current price not found for the target in the report
    • Zero price — Price is 0 or negative
    • Fundamental anomaly — Price below the minimum reasonable threshold for that market
    • Deviation anomaly — Report price deviates from reference_prices.json by more than the threshold (default 50%)

Exit Codes

Exit Code Meaning
0 All price data complete and reasonable
1 Missing or anomalous prices found

Quick Start

Prerequisites

  • TRAE CN IDE (SOLO mode support required)
  • Python 3.10+ (for running targets_validator.py and price_checker.py)
  • uv (for installing MCP servers via uvx)
  • Node.js (for installing MCP servers via npx)
  • Optional: Longport account (for HK/US stock real-time data)

Configuration Steps

  1. Configure MCP servers: Copy the example configuration and fill in your credentials:
    cp .trae/mcp.json.example .trae/mcp.json
    Edit .trae/mcp.json and replace the following placeholders:
    • LONGPORT_APP_KEY, LONGPORT_APP_SECRET, LONGPORT_ACCESS_TOKEN — Your Longport API credentials
    • TARGETS_JSON_PATH — Absolute path to targets.json
    • tushareMcp URL — Replace your_tushare_token_here with your TuShare token
  2. Configure targets: Edit targets.json as needed to add or remove indices, stocks, and ETFs for analysis.
  3. Set up agents: Import the four agents into TRAE CN using the information in agents_info/:
    • Livermore: See agents_info/Livermore_info.md for the prompt
    • Buffett: See agents_info/Buffet_info.md for the prompt
    • Cathie Wood: See agents_info/CathieWood_info.md for the prompt
    • Ray Dalio: See agents_info/RayDalio_info.md for the prompt

Generating Reports

Once configured, switch to SOLO mode in TRAE CN and send the following instruction to the SOLO Agent:

1. You and @Livermore @Buffett @CathieWood @RayDalio jointly study the financial market analysis logic and response framework in the reports in this directory (/path/to/MarketForecastingAgents/reports/).
2. First, @RayDalio completes the macro framework analysis: diagnose the economic machine state, determine the short-term debt cycle position, evaluate four-environment probabilities (growth up + inflation up, growth up + inflation down, growth down + inflation up, growth down + inflation down), providing macro top-down constraints for all subsequent analysis.
3. You 5 agents (@Livermore @Buffett @CathieWood @RayDalio @SOLO Agent) jointly use MCP tools or WebSearch to search for as much latest data and information as possible. WARNING: Every agent must return the latest price for each target. Missing price data for any target is considered a failure.
4. You (SOLO Agent) collect the latest prices returned by the four investment agents, cross-validate them, and save to reference_prices.json (format: {"000001.SH": 4152.000, "00700.HK": 460.000, ...}). If any target's price is not returned by all four agents, you must search via WebSearch to supplement it before continuing.
5. You 5 agents (@Livermore @Buffett @CathieWood @RayDalio @SOLO Agent) discuss and provide a forecast for the next six months for all targets mentioned in this file (/path/to/MarketForecastingAgents/targets.json) as of the current moment, providing the probability and price range for each of the following scenarios with reasoning: 1. Oscillating bullish; 2. Oscillating bearish; 3. Oscillating upward; 4. Oscillating downward; 5. Direct upward; 6. Direct downward. WARNING: All prices in the report must come from reference_prices.json. Estimating from memory or filling in independently is prohibited.
6. You consolidate the outputs from all 5 agents (@Livermore @Buffett @CathieWood @RayDalio @SOLO Agent), save the consolidated analysis as a Markdown document (the content must clearly indicate that the forecast period is the next six months!) and store it in this directory (/path/to/MarketForecastingAgents/reports/).
7. You perform price validation: run this Python file (/path/to/MarketForecastingAgents/price_checker.py). If the exit code is 1, return to Step 4 to fix price issues until the exit code is 0.
8. Finally, you perform target coverage validation: run this Python file (/path/to/MarketForecastingAgents/targets_validator.py). If the exit code is 1, re-execute Steps 1-8 until the exit code is 0.

Important: Please replace /path/to/MarketForecastingAgents/ with the actual absolute path on your system.


Trend Forecast Scenarios

The report's trend forecast for each target covers the following six probability-weighted scenarios:

No. Scenario Description
1 Oscillating Bullish Price oscillates within a range but biased upward
2 Oscillating Bearish Price oscillates within a range but biased downward
3 Oscillating Upward Price generally moves up but with significant oscillation
4 Oscillating Downward Price generally moves down but with significant oscillation
5 Direct Upward Price steadily rises with no significant pullback
6 Direct Downward Price steadily declines with no significant rebound

Disclaimer

The reports generated by this project are for reference only and do not constitute any investment advice. Financial markets carry inherent risks; invest with caution and always make independent judgments.

Copyright Notice

© 2026 MarketForecastingAgents Contributors. All rights reserved.

License

This project is licensed under the PolyForm Noncommercial License 1.0.0. For detailed terms, please refer to the LICENSE file in the repository root.

Noncommercial Use — including personal research, study, hobby projects, and use by educational or charitable institutions — is free and permitted under the license terms.

Commercial Use — including but not limited to integrating this software into commercial products or services — requires a separate commercial license. For commercial licensing or business collaboration inquiries, please contact the project maintainer:

Contributing

By submitting contributions to this project, you agree to the terms in CONTRIBUTING.md, including granting the project maintainer the right to relicense your contributions.

About

基于多智能体协作的AI市场研报自动生成系统,覆盖A股/港股/美股 | AI-powered multi-agent market research report auto-generation system covering A-shares, HK & US stocks

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages