← Back to Open Source

Trading Analysis Skill

Claude Code skill for systematic US stock technical & fundamental analysis

Claude Code Python Finance API
Coreychen4444/agent-skills License: MIT Language: Python

About

A Claude Code agent skill that performs comprehensive trading analysis combining technical indicators, fundamental data, and macro context to generate actionable trading insights.

Key Highlights

1

Multi-dimensional analysis: technical, fundamental, macro, and sentiment

2

Automated data fetching via integrated scripts

3

Structured output with clear buy/sell/hold recommendations

4

Reference-backed analysis with curated knowledge base

Trading Analysis

A six-step workflow inspired by TradingAgents that turns raw market data into a risk-reviewed, actionable trade plan with dynamic execution zones.

Data-source mapping

Configure data sources for your environment. The skill expects four categories of input — use whichever providers you have access to.

Price / technical context

Use in priority order:

  1. Broker API (e.g. Interactive Brokers, moomoo OpenAPI, Alpaca) for real-time quotes and K-line data
  2. Portfolio CSV / JSON — a local file tracking current holdings with price columns
  3. Free data fallback — Yahoo Finance, Stooq, or similar public source

News / macro

Use web search and prioritize source quality:

  1. Official company source / IR / filing / transcript
  2. Reuters or other high-quality hard-news source
  3. Major financial media
  4. Social reposts / commentary only as supporting color

Social / sentiment

Use any social search tool (e.g. X/Twitter search, Reddit, StockTwits) for sentiment data.

  • Treat social posts as sentiment evidence, not fact evidence.
  • If no social tool is available, fall back to web search and mark sentiment confidence lower.

Rules / behavior context

Use workspace files for standing rules and trading discipline:

  • Trading rules document
  • Pre-trade checklist
  • Entry strategy rules (e.g. staged-entry framework)

Do not invent prices, valuation numbers, technical indicators, social statistics, or fundamental metrics. If data is unavailable, label it TBD (待核实).

Pre-flight checklist

Before analysis:

  1. Read your trading rules document if the discussion may lead to a trade decision.
  2. Read your pre-trade checklist if the user is preparing to trade.
  3. Read your entry strategy rules if the analysis may lead to an entry/add decision.
  4. Refresh quotes from your broker API or data provider when current price is needed.
  5. Read your portfolio file and extract the target ticker row if present.
  6. Determine whether the ticker belongs to:
    • current = active holding / already in portfolio
    • watchlist = intended entry but not yet held

Dynamic execution-zone policy

Execution zones are analysis outputs, not static notes.

Every meaningful trading analysis should try to produce these fields when enough evidence exists:

  • accumulation_zone_1
  • accumulation_zone_2
  • trim_zone
  • no_chase_above
  • invalid_if
  • zone_timeframe
  • valid_until
  • last_updated
  • update_trigger
  • zone_reasoning_summary

Zone philosophy

  • accumulation_zone_1: first participation zone — the first tranche that secures participation.
  • accumulation_zone_2: deeper weakness zone — the second tranche, not a replacement for zone 1.
  • trim_zone: area where partial profit-taking / de-risking becomes reasonable.
  • no_chase_above: price above which buying is no longer attractive without new confirmation.
  • invalid_if: the concrete condition that breaks the setup or makes prior zones obsolete.

Hard rules for zone generation

  • Do not create fake precision. If evidence only supports rough bands, use rough bands.
  • Zones must be tied to actual context: support/resistance, post-event range, prior gap, valuation comfort, event window, or sentiment washout.
  • Zone 2 must not replace zone 1. It exists only as the deeper-weakness tranche.
  • Dynamic does not mean emotional. Do not rewrite zones intraday just because price moved. Rewrite only when the analysis basis changed.

Zone refresh triggers

Refresh zones when any of these is true:

  1. Earnings / guidance / conference / product event materially changed the setup
  2. Macro regime changed (rates, tariffs, geopolitics, policy shock)
  3. Price structure broke or confirmed a key range
  4. Previous zone is stale (valid_until passed)
  5. The user explicitly asks to refresh / re-analyze / update trade plan

Default zone validity

Use one of these and say which one applies:

  • intraday
  • swing_1w
  • swing_2w
  • event_window
  • post_earnings

Default to:

  • swing_1w for normal trade planning
  • event_window when the main driver is a known event

Write-back policy

After analysis, if the zones are specific enough to be actionable, update your position zones file.

Use the bundled script:

python3 scripts/update_position_zones.py \
  --data-dir <your-data-directory> \
  --ticker {TICKER} \
  --bucket {current|watchlist} \
  --instrument-type {stock|option} \
  --role {role} \
  --zone1 {LOW1} {HIGH1} \
  --zone2 {LOW2} {HIGH2} \
  --trim {LOWT} {HIGHT} \
  --no-chase-above {PRICE} \
  --invalid-if "{condition}" \
  --timeframe {intraday|swing_1w|swing_2w|event_window|post_earnings} \
  --valid-until {YYYY-MM-DD or ISO} \
  --update-trigger "{trigger text}" \
  --reasoning-summary "{short basis}" \
  --thesis "{optional short thesis}" \
  --key-risk "{optional key risk}" \
  --notes "{optional notes}" \
  --remove-from-other

If writing back:

  • Upsert only the analyzed ticker
  • Preserve other tickers already in the file
  • Set last_updated using current UTC time
  • Set valid_until explicitly when possible
  • Set zone_reasoning_summary to a short 1-3 bullet style string

If the ticker migrated from watchlist to current (real position opened):

  • Add/update it in current/position_zones.json
  • Remove it from watchlist/position_zones.json using --remove-from-other

If the analysis is too uncertain to produce useful zones:

  • Say so explicitly
  • Do not force write-back
  • Use TBD

Required six-step workflow

Follow all six steps in order. Do not skip. Do not give the final trade recommendation before steps 1-5 are complete.


Step 1 — Fundamental Analyst

Analyze:

  • Revenue / profit trend
  • Valuation context (PE/PB/PS if available; otherwise mark TBD)
  • Balance sheet / cash flow quality if available
  • Business model / moat
  • Recent major events: earnings, guidance, customer/order updates, management changes, policy
  • Compare against prior thesis when relevant

Allowed evidence:

  • User-provided numbers
  • Official company sources / earnings materials
  • High-quality news search results
  • Known workspace thesis files
  • If hard numbers are missing, say so explicitly

Output format:

【基本面报告】 评级:强劲 / 一般 / 偏弱 关键结论:

  • ...
  • ...
  • ... 数据说明:
  • 用户提供:...
  • 已核实:...
  • 待核实:...

Step 2 — Technical Analyst

Data collection (mandatory before analysis)

Fetch K-line data from your data provider. Example using a broker API:

# Daily K-line: recent 20 trading days
<your-kline-tool> {TICKER} --ktype 1d --num 20

# Weekly K-line: recent 12 weeks
<your-kline-tool> {TICKER} --ktype 1w --num 12

# Current snapshot for intraday context
<your-quote-tool> {TICKER}

If K-line fetch fails, fall back to portfolio CSV fields and mark depth as TBD.

Analysis using real K-line data

From the fetched K-line data, identify:

Daily structure (from 1d K-line):

  • Recent swing high / swing low (highest high and lowest low in past 5-10 days)
  • Panic low if any (sharp intraday wick with recovery)
  • Gap regions (where open significantly differs from prior close)
  • Volume spikes (days with 2x+ average volume = institutional participation)
  • Whether price is trending, consolidating, or breaking down
  • Key support: prior lows that held, gap-fill zones, high-volume pivot areas
  • Key resistance: prior highs that rejected, gap-down open areas, high-volume rejection candles

Weekly structure (from 1w K-line):

  • Multi-week range (high/low of past 4-12 weeks)
  • Weekly trend direction
  • Whether current price is near weekly support/resistance

Intraday context (from snapshot):

  • Current price / last price
  • Change percent
  • Open / high / low / prev close
  • Volume / turnover
  • Where today's price sits within the daily and weekly structure

Deriving support/resistance for zones

When producing execution zones later in Step 5, the K-line derived levels feed directly into zone boundaries:

  • accumulation_zone_1 should align with identifiable daily support / retrace area
  • accumulation_zone_2 should align with deeper support / panic low area
  • trim_zone should align with resistance / prior high / extension area
  • no_chase_above should align with resistance or overextension level

Important boundary

  • Use the actual K-line numbers. Do not invent round numbers that feel right.
  • If 20 daily bars are not enough for a pattern, say so and note confidence is lower.
  • Do not fake MACD / RSI / moving averages unless you actually compute them from K-line data.
  • Mark anything unverifiable as TBD.

Output format:

【技术报告】 评级:买入信号 / 中性 / 卖出信号 信号强度:强 / 中 / 弱 关键价位: 支撑:___ 压力:___ 技术结论:

  • ...

Step 3 — News Analyst

Analyze with web search:

  • Recent company-specific developments
  • Sector developments
  • Macro backdrop
  • Catalyst timing and source credibility
  • Policy / tariff / rates / geopolitics if relevant

Separate clearly:

  • Confirmed company catalyst
  • Sector narrative
  • Macro background
  • Items still unverified

Output format:

【新闻报告】 评级:偏多 / 中性 / 偏空 已确认催化:

  • ... 主要风险点:
  • ...
  • ...

Step 4 — Sentiment Analyst

Use available social search tools to inspect current discussion around:

  • Ticker
  • Company name
  • Core product / theme
  • Current catalyst keywords

Goal:

  • Identify whether sentiment is supportive, crowded, skeptical, or fractured
  • Distinguish signal from hype
  • Detect whether the market is already over-positioned in the narrative

Rules:

  • Social posts are not source-of-truth facts
  • Treat them as mood / positioning / crowd-attention evidence
  • If social tools fail or return low-quality results, say sentiment confidence is lower and use web search as backup

Output format:

【情绪报告】 评级:偏多 / 中性 / 偏空 情绪强度:强 / 中 / 弱 情绪观察:

  • ...
  • ... 潜在情绪风险:
  • ...

Step 5 — Bull/Bear Debate + Trade Decision

First run a structured bull/bear debate using only evidence already established in steps 1-4. Then translate the outcome into an action plan.

Apply standing trading discipline when relevant:

  • Verification before judgment
  • Confirmation over perfect price
  • Anti-FOMO: do not chase
  • Event-day early strength is not confirmation
  • Check trading rules before acting
  • Avoid turning the right macro concern into one uniform blunt action across all positions

Output format:

【多空辩论】 多头核心论据:

  1. ...
  2. ...
  3. ... 空头核心论据:
  4. ...
  5. ...
  6. ... 辩论裁定:___ 关键分歧:___

【交易决策】 评级:Buy / Overweight / Hold / Underweight / Sell 操作建议:买入 / 持有观察 / 减仓 / 回避 建议仓位:%(占总仓位) 入场区间: 至 ___ 止损位:(理由:) 目标价:___(3个月视角) 置信度:高 / 中 / 低 决策逻辑摘要:...

Mandatory execution-zone block

After the trade decision, produce:

【执行区间】 标的归属:current / watchlist 时间框架:intraday / swing_1w / swing_2w / event_window / post_earnings 首档吸纳区:___ 至 ___ / TBD 二档吸纳区:___ 至 ___ / TBD 减仓观察区:___ 至 ___ / TBD 不追价上限:___ / TBD 失效条件:... 有效期至:... 触发重算条件:... 区间依据摘要:

  • ...
  • ...

Notes:

  • If the user already holds the name, the block should still exist; it defines add / trim / no-chase levels for the existing position.
  • If there is no responsible way to set a field, mark it TBD.

Step 6 — Risk Review

Do an independent review of Step 5.

Must check:

  • Concentration / correlation with current holdings
  • Overlap with existing themes
  • Maximum likely loss and whether it fits the proposed plan
  • Ignored tail risks
  • Whether the recommendation is thesis-driven or emotion/FOMO-driven
  • Whether this is a confirmed setup or an early/riskier entry
  • Whether the plan respects current trading rules instead of chasing narrative elegance
  • Whether the generated execution zones are still valid under the stated catalyst / macro scenario

Output format:

【风险审查】 风险项:

  • ... 最终裁定:批准 / 批准但建议降低仓位至___% / 否决 否决或调整理由:...

Constraints

  • Mark unknown figures as TBD (待核实).
  • Prefer current data over stale memory.
  • Do not present fabricated precision.
  • Do not let the final recommendation front-run the earlier steps.
  • Degrade gracefully when a data source is unavailable.

Customization

The output format uses Chinese headers by default. To localize, replace the 【...】 section headers and field labels with your preferred language while keeping the same structure.