Back to skills
extension
Category: Data & AnalyticsNo API key required

股价利润走势图

Generate a quarterly dual-axis chart of a stock's post-adjustment price versus its single-quarter net profit, with auto-generated Chinese analysis. Use when a user asks to visualize a stock's quarterly price and profit trend, e.g. '画一下XX的季度股价和净利润图', '对比XX股价和利润', 'XX季度业绩趋势', or any request to chart a company's quarterly share price against its earnings. Works for A-share / HK / US stocks covered by the Tencent self-selected stock data source.

personAuthor: user_ece50f06hubcommunity

Quarterly Profit Chart(季度股价 vs 单季净利润对比图)

Overview

Given a stock (by name or code), produce a self-contained HTML report containing:

  • A dual-axis chart: blue bars = single-quarter net profit attributable to parent (left axis, in 亿元), red line = post-adjustment (后复权) closing price (right axis, in 元), plus a sub-chart green line = single-quarter net profit YoY growth (%).
  • A data-driven Chinese analysis section (key metrics + trend interpretation).

The chart is pure inline SVG (no CDN dependency), so it renders offline and is easy to save.

When to Use

  • "画一下海康威视的季度股价和净利润图"
  • "对比比亚迪的股价和利润趋势"
  • "XX 季度业绩走势 / 利润和股价背离分析"
  • Any request to chart a stock's quarterly price against its earnings.

Dependencies

  • westock-data skill — provides the CLI (index.js) used to fetch K-line and financial data. Load it first via the westock-data skill to obtain the CLI path.
  • node — to run the westock-data CLI.
  • This skill's bundled script: scripts/gen_chart.py.

Workflow

Step 1 — Resolve the stock code

The westock-data CLI does not accept Chinese names (it returns empty). If the user gives a name (e.g. "海康威视"), resolve it to a standard code first:

  • Use WebSearch: search "名称 股票代码" and pick the standard code (formats: sz002415, sh600519, bj430047, or HK hk00700, US usAAPL).
  • If the user already supplied a code, use it directly.

Step 2 — Load westock-data and locate its CLI

Invoke the westock-data skill to load its instructions, which expose the path to .../westock-data/scripts/index.js. Pass that path to the script via --westock. (The script also auto-discovers the path under ~/.workbuddy and /Applications/WorkBuddy.app, so --westock is optional if the default layout matches.)

Step 3 — Run the generator

python3 SKILL_DIR/scripts/gen_chart.py CODE \
    --name "股票名称" \
    --westock "PATH/to/westock-data/scripts/index.js" \
    --out "OUTPUT.html"

The script prints a progress log and ends with a SUMMARY_JSON:... line containing the key metrics (profit peak, price peak, latest quarter) — use it for your narration.

Step 4 — Present the result

Use present_files on the generated HTML so the user can view (and save) it. Then, based on the SUMMARY_JSON and the script's auto-analysis, add a short contextual read-out (e.g. note whether price and profit peaks are synchronized, or whether profit is at a high while valuation has pulled back — a "profit up, price flat" divergence worth flagging in a Lynch-style lens).

Implementation Notes (non-obvious gotchas)

  • Single-quarter profit: the finance API does not expose a single-quarter field. The script computes it as cumulative(this quarter) − cumulative(prior quarter in same year) (Q1 = cumulative directly). Finance returns cumulative net profit in NPParentCompanyOwners (unit: 元 → ÷1e8 for 亿元).
  • Standard quarter-ends only: filter out non-standard report dates (e.g. re-statement dates like 2016-07-31) to avoid polluting the cumulative-difference calculation.
  • Empty-result retry: the westock-data CLI intermittently returns empty [] / null on frequent/consecutive calls (likely internal rate-limiting). gen_chart.py already retries with exponential backoff; if a call still fails, simply re-run.
  • History window: the finance endpoint typically returns ~42 quarters (from about 2016Q1). The X-axis is built dynamically from whatever quarters are available, so older/newer listings are handled automatically.
  • Post-adjustment price: K-line uses --fq hfq (后复权) so splits/dividends don't distort the long-term trend.

Resources

scripts/

  • gen_chart.py — fetches seasonal post-adjustment K-line + quarterly profit, computes single-quarter profit and YoY, and renders the self-contained HTML report. Args: CODE (required), --westock PATH, --name NAME, --out FILE.