China Stock Analysis Skill
A Chinese A-share analysis tool based on value investment theory, targeting ordinary investors with low-frequency trading.
When to Use
Call this skill when the user requests the following operations:
- Analyze a specific A-share stock
- Screen stocks that meet criteria
- Compare multiple stocks or stocks within an industry
- Calculate stock valuation or intrinsic value
- Check the financial health of a stock
- Detect financial anomaly risks
Prerequisites
Python Environment Requirements (venv is mandatory)
All script commands should be run in the project virtual environment.
bash
python3 -m venv .venv
source .venv/bin/activate
Install Dependencies:
bash
pip install tushare pandas numpy
Environment Bootstrap (Must be completed automatically before execution)
Before running any scripts, execute the following in the current project directory:
bash
cd <skill project directory>
if [ ! -d ".venv" ]; then
python3 -m venv .venv
fi
source .venv/bin/activate
python3 -m pip install -U pip
python3 -m pip install tushare pandas numpy
Notes:
- must be located in the root directory of the skill project (not a global directory)
- If fails, the above bootstrap must be executed first before proceeding with subsequent analysis processes
/
are recommended to be stored in
, and loaded into the current shell before execution:
bash
set -a
source ~/.aj-skills/.env
set +a
Notes:
- The script will not automatically read
- Must be explicitly passed via CLI parameters:
--token "${TUSHARE_TOKEN}"
, --brave-api-key "${BRAVE_API_KEY}"
Pre-execution Parameter Check (using
command):
bash
test -n "${TUSHARE_TOKEN}" || { echo "Missing TUSHARE_TOKEN"; exit 1; }
# Check only when using Brave news source
test -n "${BRAVE_API_KEY}" || { echo "Missing BRAVE_API_KEY (required when news-provider=brave)"; exit 1; }
Dependency Check
Before performing any analysis, check if tushare is installed:
bash
python3 -c "import tushare; print(tushare.__version__)"
Core Modules
1. Stock Screener
Screen stocks that meet criteria
2. Financial Analyzer
In-depth financial analysis of individual stocks
3. Industry Comparator
Horizontal comparison analysis within the same industry
4. Valuation Calculator
Intrinsic value measurement and margin of safety calculation
5. News & Sentiment
Capture recent public news and generate sentiment risk assessment
Workflow 1: Stock Screening
Used when the user requests stock screening.
Step 1: Collect Screening Criteria
Ask the user for screening criteria. Provide the following options for selection or customization:
Valuation Metrics:
- PE (Price-to-Earnings Ratio): e.g., PE < 15
- PB (Price-to-Book Ratio): e.g., PB < 2
- PS (Price-to-Sales Ratio): e.g., PS < 3
Profitability:
- ROE (Return on Equity): e.g., ROE > 15%
- ROA (Return on Assets): e.g., ROA > 8%
- Gross Profit Margin: e.g., > 30%
- Net Profit Margin: e.g., > 10%
Growth:
- Revenue Growth Rate: e.g., > 10%
- Net Profit Growth Rate: e.g., > 15%
- Consecutive Growth Years: e.g., >= 3 years
Dividends:
- Dividend Yield: e.g., > 3%
- Consecutive Dividend Years: e.g., >= 5 years
Financial Safety:
- Asset-Liability Ratio: e.g., < 60%
- Current Ratio: e.g., > 1.5
- Quick Ratio: e.g., > 1
Screening Scope:
- All A-shares
- CSI 300 Constituents
- CSI 500 Constituents
- ChiNext/STAR Market
- User-defined list
Step 2: Execute Screening
bash
python scripts/stock_screener.py \\
--scope "hs300" \\
--token "${TUSHARE_TOKEN}" \\
--pe-max 15 \\
--roe-min 15 \\
--debt-ratio-max 60 \\
--dividend-min 2 \\
--output screening_result.json
Parameter Explanation:
- : Screening scope (all/hs300/zz500/cyb/kcb/custom:600519,000858,...)
- : PE range
- : PB range
- : Minimum ROE
- : Minimum growth rate
- : Maximum asset-liability ratio
- : Minimum dividend yield
- : tushare token (required)
- : Output format (json/table)
- : Silent mode
- : Output file path
Step 3: Present Results
Read
and present to the user in table format:
| Code | Name | PE | PB | ROE | Dividend Yield | Score |
|---|
| 600519 | Kweichow Moutai | 25.3 | 8.5 | 30.2% | 2.1% | 85 |
Workflow 2: Stock Analysis
Used when the user requests analysis of a specific stock.
Step 1: Collect Stock Information
Ask the user:
- Stock code or name
- Analysis depth level:
- Summary Level: Key indicators + investment conclusion (1 page)
- Standard Level: Financial analysis + valuation + industry comparison + risk warning
- In-depth Level: Complete research report including historical data tracking
Step 1.5: Prepare Output Directory
When analyzing a single stock, the skill needs to automatically create an output directory with the naming rule:
${stock_name}_${stock_code}
Example:
bash
stock_dir="Kweichow Moutai_600519"
mkdir -p "${stock_dir}"
Step 2: Fetch Stock Data
Recommended to use "module-wise fetch + aggregation" process (CLI decoupling):
bash
mkdir -p "${stock_dir}/data"
# 1) Basic Information
python scripts/fetch_basic.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--output "${stock_dir}/data/basic.json"
# 2) Financial Data
python scripts/fetch_financial.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--years 5 \\
--output "${stock_dir}/data/financial.json"
# 3) Valuation & Market Data
python scripts/fetch_valuation.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--output "${stock_dir}/data/valuation.json"
python scripts/fetch_price.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--days 180 \\
--output "${stock_dir}/data/price.json"
# 4) News & Sentiment
python scripts/fetch_news_data.py \\
--code "600519" \\
--name "Kweichow Moutai" \\
--days 7 \\
--limit 20 \\
--provider brave \\
--brave-api-key "${BRAVE_API_KEY}" \\
--output "${stock_dir}/data/news.json"
# 5) Real-time & Event Window
python scripts/fetch_realtime.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--benchmark hs300 \\
--window 60 \\
--output "${stock_dir}/data/realtime.json"
python scripts/fetch_event_window.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--name "Kweichow Moutai" \\
--benchmark hs300 \\
--pre-days 1 \\
--post-days 1,3,5 \\
--provider brave \\
--brave-api-key "${BRAVE_API_KEY}" \\
--output "${stock_dir}/data/event_window.json"
# 6) Aggregate into Analysis Input
python scripts/assemble_data.py \\
--input-dir "${stock_dir}/data" \\
--output "${stock_dir}/stock_data.json"
Compatibility mode (single command fetch) is retained as follows:
bash
python scripts/data_fetcher.py \\
--code "600519" \\
--token "${TUSHARE_TOKEN}" \\
--data-type all \\
--with-news \\
--news-provider brave \\
--brave-api-key "${BRAVE_API_KEY}" \\
--with-realtime \\
--with-event-window \\
--benchmark hs300 \\
--realtime-window 60 \\
--event-window-pre 1 \\
--event-window-post 1,3,5 \\
--news-days 7 \\
--news-limit 20 \\
--years 5 \\
--output "${stock_dir}/stock_data.json"
Parameter Explanation:
- : Stock code
- : Data type (basic/financial/valuation/holder/news/all)
- : Number of years of historical data to fetch
- : tushare token (required)
- : Attach news and sentiment data
- : News window days
- : Maximum number of news items
- : News source filter (comma-separated)
- : News source (auto/brave/tushare/rss)
- : Brave Search API Key (required when )
- : Attach real-time indicators (trend/confirmation/risk/筹码)
- : Attach event window analysis (1/3/5-day reaction after events)
- : Relative strength benchmark index (hs300/zz500/zz1000/cyb/kcb)
- : Real-time indicator calculation window (days)
- : Event window pre-days
- : Event window post-days (comma-separated)
- : Cache validity period (minutes)
- : Output format (json/table)
- : Silent mode
- : Output file
Optional: Execute News & Sentiment Process Separately
bash
python scripts/news_fetcher.py --code 600519 --name Kweichow Moutai --token "${TUSHARE_TOKEN}" --days 7 --limit 20 --provider brave --brave-api-key "${BRAVE_API_KEY}" --output "${stock_dir}/news.json"
python scripts/sentiment_analyzer.py --input "${stock_dir}/news.json" --output "${stock_dir}/sentiment.json"
Step 3: Run Financial Analysis
bash
python scripts/financial_analyzer.py \\
--input "${stock_dir}/stock_data.json" \\
--level standard \\
--output "${stock_dir}/analysis_result.json"
Or directly read module-wise directory (auto-aggregation):
bash
python scripts/financial_analyzer.py \\
--input-dir "${stock_dir}/data" \\
--level standard \\
--output "${stock_dir}/analysis_result.json"
Parameter Explanation:
- : Input stock data file
- : Module-wise directory (auto-read and aggregate into analysis input)
- : Analysis depth (summary/standard/deep)
- : Output file
Step 4: Calculate Valuation
bash
python scripts/valuation_calculator.py \\
--input "${stock_dir}/stock_data.json" \\
--methods dcf,ddm,relative \\
--discount-rate 10 \\
--growth-rate 8 \\
--output "${stock_dir}/valuation_result.json"
Parameter Explanation:
- : Stock data file
- : Valuation methods (dcf/ddm/relative/all)
- : Discount rate (%)
- : Perpetual growth rate (%)
- : Compatible alias for perpetual growth rate (%)
- : Margin of safety (%)
- : Output format (json/table)
- : Silent mode
- : Output file
Step 5: Generate Report
Read analysis results and generate a Chinese analysis report referring to the
templates/analysis_report.md
template.
Mandatory Inspection Items for Report Generation (All must be satisfied):
0. The final report must be saved as a Markdown file (
)
- Must include the "News & Sentiment" chapter
- Must use
news_sentiment/news_items
from to fill corresponding fields
- If news fetching fails, clearly state the failure reason in the report (from )
- Must not omit the and "Performance & Audit Signals" chapters in the template
- If contains , the report must include the "Real-time Indicator Dashboard" chapter (trend/confirmation/risk/筹码)
- If contains , the report must include "Event Window Reaction" content (number of events, 1/3/5-day returns after events, 1/3/5-day excess returns after events)
- If exists, the comprehensive score must adopt 40% Financial + 60% Real-time (real-time priority)
Report Structure (Standard Level):
- Company Overview: Basic information, main business
- Financial Health: Balance sheet analysis
- Profitability: DuPont analysis, profit margin trends
- Growth Analysis: Revenue/profit growth trends
- Real-time Indicator Dashboard: Trend/confirmation/risk/筹码
- Event Window Analysis: Post-event returns and excess returns
- Valuation Analysis: DCF/DDM/Relative Valuation
- Risk Warning: Financial anomaly detection, shareholder reduction
- Investment Conclusion: Comprehensive score, operation suggestions (real-time priority)
Report Title Specification:
- uses the format:
Stock Name(Stock Code): Summary Conclusion
- Example:
Kweichow Moutai(600519): Financially Stable, Valuation and Risk Matching is Good
Output File:
${stock_dir}/final_report.md
Step 6: Humanize Output
Read
${stock_dir}/final_report.md
and call the
skill for polishing and optimization.
Output File:
${stock_dir}/final_report_humanized.md
Workflow 3: Industry Comparison
CLI Method (Sector Analysis, Recommended)
bash
# 1) Fetch Sector Data
python scripts/sector_fetcher.py \\
--sector-name "Computing Power Sector" \\
--token "${TUSHARE_TOKEN}" \\
--sector-file config/sector_computing_default.json \\
--output "${stock_dir}/sector_data.json"
# 2) Generate Sector Analysis Results + Markdown Report
python scripts/sector_analyze.py \\
--input "${stock_dir}/sector_data.json" \\
--output "${stock_dir}/sector_analysis.json"
Step 1: Collect Comparison Targets
Ask the user:
- Target stock codes (multiple allowed)
- Or: Industry classification + number of comparisons
Step 2: Fetch Industry Data
bash
python scripts/data_fetcher.py \\
--codes "600519,000858,002304" \\
--token "${TUSHARE_TOKEN}" \\
--data-type comparison \\
--output industry_data.json
Or fetch by industry:
bash
python scripts/data_fetcher.py \\
--industry "Liquor" \\
--token "${TUSHARE_TOKEN}" \\
--top 10 \\
--output industry_data.json
Step 3: Generate Comparison
bash
python scripts/financial_analyzer.py \\
--input industry_data.json \\
--mode comparison \\
--output comparison_result.json
Step 4: Present Comparison Table
| Indicator | Kweichow Moutai | Wuliangye | Yanghe Co., Ltd. | Industry Average |
|---|
| PE | 25.3 | 18.2 | 15.6 | 22.4 |
| ROE | 30.2% | 22.5% | 20.1% | 18.5% |
| Gross Profit Margin | 91.5% | 75.2% | 72.3% | 65.4% |
| Score | 85 | 78 | 75 | - |
Workflow 4: Valuation Calculator
Step 1: Collect Valuation Parameters
Ask the user for valuation parameters (or use default values):
DCF Model Parameters:
- Discount Rate (WACC): Default 10%
- Forecast Period: Default 5 years
- Perpetual Growth Rate: Default 3%
DDM Model Parameters:
- Required Rate of Return: Default 10%
- Dividend Growth Rate: Derived from historical data
Relative Valuation Parameters:
- Comparison Benchmark: Industry average / Historical average
Step 2: Run Valuation
bash
python scripts/valuation_calculator.py \\
--code "600519" \\
--methods all \\
--discount-rate 10 \\
--terminal-growth 3 \\
--forecast-years 5 \\
--margin-of-safety 30 \\
--output valuation.json
Step 3: Present Valuation Results
| Valuation Method | Intrinsic Value | Current Price | Margin of Safety Price | Conclusion |
|---|
| DCF | ¥2,150 | ¥1,680 | ¥1,505 | Undervalued |
| DDM | ¥1,980 | ¥1,680 | ¥1,386 | Undervalued |
| Relative Valuation | ¥1,850 | ¥1,680 | ¥1,295 | Reasonable |
Financial Anomaly Detection
Automatically detect the following anomaly signals during analysis:
Detection Items
-
Abnormal Accounts Receivable
- Accounts receivable growth rate > Revenue growth rate × 1.5
- Significant increase in accounts receivable turnover days
-
Cash Flow Divergence
- Sustained net profit growth but declining operating cash flow
- Cash-to-income ratio < 80%
-
Abnormal Inventory
- Inventory growth rate > Revenue growth rate × 2
- Significant increase in inventory turnover days
-
Abnormal Gross Profit Margin
- Gross profit margin volatility > Industry average volatility × 2
- Severe deviation from peers' gross profit margin
-
Related Party Transactions
- High proportion of related party transactions (> 30%)
-
Shareholder Reduction
- Recent reduction announcements by major shareholders
- Concentrated reduction by executives
Risk Levels
- 🟢 Low Risk: No obvious anomalies
- 🟡 Medium Risk: 1-2 minor anomalies
- 🔴 High Risk: Multiple anomalies or severe anomalies
A-Share Specific Analysis
Policy Sensitivity
Provide policy-related prompts based on industry classification:
- Real Estate: "Houses are for living, not for speculation" policy
- New Energy: Changes in subsidy policies
- Pharmaceuticals: Impact of volume-based procurement policies
- Internet: Anti-monopoly, data security
Shareholder Structure Analysis
- Controlling shareholder type (SOE/Private Enterprise/Foreign Capital)
- Ownership concentration
- Recent increase/reduction situations
- Pledge ratio
Output Format
JSON/Table Output Format
- Default
- Optional for quick terminal viewing
- Use to disable process logs
All scripts output JSON format for easy subsequent processing:
json
{
"code": "600519",
"name": "Kweichow Moutai",
"analysis_date": "2025-01-25",
"level": "standard",
"summary": {
"score": 85,
"conclusion": "Undervalued",
"recommendation": "Recommended to pay attention"
},
"financials": { ... },
"valuation": { ... },
"risks": [ ... ]
}
Markdown Report
Generate structured Chinese Markdown report, referring to
templates/analysis_report.md
.
Data Contract
Core data structures are constrained by
. Analysis scripts will verify before running:
- Required top-level fields:
code/fetch_time/data_type/basic_info
- Common optional fields:
financial_data/financial_indicators/valuation/price/holder/dividend
- News-related fields:
news_items/news_sentiment
- Performance audit fields: (including
forecast/express/audit/main_business
)
- Report field requirements:
financial_data.balance_sheet
must be an array
financial_data.income_statement
must be an array
- must be an array
Field Mapping (Akshare -> Tushare)
| Compatible Semantics | Current Field (Recommended) | Compatible Aliases/Source |
|---|
| PE(TTM) | | |
| PB | | - |
| Net Profit | financial_data.income_statement[].净利润
| |
| Net Operating Cash Flow | financial_data.cash_flow[].经营活动产生的现金流量净额
| |
| Capital Expenditure Cash | financial_data.cash_flow[].购建固定资产、无形资产和其他长期资产支付的现金
| |
| ROE | financial_indicators[].净资产收益率
| |
| Asset-Liability Ratio | financial_indicators[].资产负债率
| |
Error Handling
Network Errors
If tushare data fetching fails, prompt the user:
- Check network connection
- Retry later (may be interface rate limiting)
- Try switching data sources
Invalid Stock Code
Prompt the user to check if the stock code is correct, and provide possible matching suggestions.
Incomplete Data
For newly listed stocks or those with incomplete financial data, explain the data limitations and perform analysis based on available data.
Best Practices
- Data Timeliness: Financial data is based on the latest quarterly/annual report, price data is the closing price of the day; when / is enabled, supplement dynamic indicators of trends and event impacts
- Investment Advice: All analysis is for reference only and does not constitute investment advice
- Risk Warning: Always include risk warnings, especially the results of financial anomaly detection
- Comparison Analysis: When analyzing a single stock, automatically include industry average comparison
- Scoring Weight: Use
40% Financial + 60% Real-time
when real-time data exists; fallback to financial score when real-time data is missing
Important Notes
- All analysis is based on public financial data and does not involve any insider information
- Parameter assumptions of valuation models have a significant impact on results, which should be explained to users
- The A-share market is greatly affected by policies, so quantitative analysis should be combined with qualitative judgments
",