股票解套分析 (Stock Break-Even Analyzer)
Overview
Analyze one or more A-share holdings to answer two questions: (1) what price is needed to
break even, and how much must it rise; (2) how likely is that, given recent technicals.
Deliver either a self-contained web app (best for beginners — open link, fill cost, get report)
or a Python script (best for users who want code).
When to use
- User mentions being "套牢 / 被套 / 回本 / 解套" or asks "还要涨多少才能回本".
- User provides holdings as name + cost + quantity and wants a break-even target.
- User asks for a reusable stock break-even / unstuck analysis tool.
Workflow
- Collect holdings. For each stock get: 名称, 6位代码, 市场(sh/sz), 持仓成本价, 持仓数量.
If the user only gave names, ask for cost and quantity (required for break-even math). - Choose deliverable by audience.
- Non-technical user → build the web app (Step A). This is the default for beginners.
- User explicitly wants code / a script → also provide the Python script (Step B). - Run / deploy, then present the report (target price, required gain %, probability, strategy).
- Append disclaimer: "本报告仅供研究参考,不构成个人投资建议。"
Step A — Web app (preferred for beginners)
- Copy
assets/index.htmlto a fresh directory (e.g../web_app/). - Pre-fill the user's holdings into the
DEFAULT_STOCKSarray near the top of the<script>
(fields: name, code, market, cost, qty, cur:""). Leavecur:""so price auto-fetches. - Deploy that directory with
workbuddy_cloudstudio_deploy(action: deploy, entry: index.html).
Present the returned 分享链接 to the user. Tell them they just open the link, optionally
edit holdings in the table, and click "开始分析". - Note: the page fetches data client-side via
<script>tags (no backend, no CORS issues):
realtime from 腾讯qt.gtimg.cn, history K-line from 东方财富 JSONP. Works by double-clicking
the localindex.htmltoo.
Step B — Python script
- Copy
scripts/stock_break_even_analyzer.pyto the user's workspace. - Edit the
STOCKSlist at the top with the user's holdings. - Run with the managed Python:
C:\Users\Administrator\.workbuddy\binaries\python\versions\3.13.12\python.exe stock_break_even_analyzer.py - The script prints a per-stock report to stdout.
Data sources & field mapping (do not re-derive)
- Realtime (web): 腾讯
https://qt.gtimg.cn/q=<market><code>returns
v_sh600172="1~名称~代码~当前~昨收~今开~...". Field indices:1=名称,
3=当前价,4=昨收,5=今开,33=最高,34=最低,30=时间(YYYYMMDDHHMMSS). - Realtime (python): 新浪
https://hq.sinajs.cn/list=<market><code>returns 34 fields;
date/time are at indices 30 and 31 (NOT the last two). RequiresReferer: https://finance.sina.com.cn. - History K-line (both): 东方财富 JSONP
https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=<1|0>.<code>&klt=101&fqt=1&lmt=120&end=20500101&fields1=f1,f2,f3&fields2=f51,f52,f53,f54,f55,f56&cb=<callback>.
secid prefix: sh→1, sz→0.klinesentries:日期,开,收,高,低,量.
Probability model (transparent, 0–100)
Four dimensions, summed and clamped:
- Distance (0–50): target vs historical window high. a = (1 - need%/headroom%)*50
when target ≤ window high; else decays. headroom% = (histHigh - current)/current*100.
- MA / trend (0–25): +15 if price above all of MA5/20/60; +8 if above some; +0 if below all.
Plus clamp(MA20_slope%, 0, 10).
- Volume (0–15): clamp((vol5/vol20 - 0.8)*15, 0, 15).
- Volatility (0–10): clamp((histHigh-histLow)/histLow% / 5, 0, 10).
Already-profitable (current ≥ target) → 100. Strategy thresholds: ≥60 hold/wait breakout,
40–60 watch + stop-loss, <40 hard / consider stop or averaging-down (caution).
Pitfalls
- The agent's sandbox often blocks 东方财富 (push2his "Remote end closed"). This does NOT
affect the deployed web page (runs in the user's real browser). If the Python script's K-line
fetch fails in-sandbox, report it as[MISSING]and fall back to realtime-only; the user's
browser/web version still works. - Do not invent prices. If a fetch fails, mark it
[MISSING]; never fabricate. 嘉林杰is commonly a typo for嘉麟杰(002486.SZ) — confirm with the user if ambiguous.
Bundled resources
assets/index.html— self-contained web app (realtime + K-line + full report, no backend).scripts/stock_break_even_analyzer.py— equivalent Python version with comments.