Stock Deep Analysis Workflow
wbh604/UZI-Skill
Runs a staged deep analysis of a single stock on China A-share, Hong Kong and US markets, ending in an HTML report with valuation models and investor-panel scores.
Covers bond pricing, credit ratings, default risk models (Altman Z-score, Merton, KMV), spread analysis and rate risk for fixed income work, with a focus on China's bond market; Chinese text.
SKILL.md written in Chinese; this summary is our English description.
$ npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install HKUDS/Vibe-Trading credit-analysis --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .claude/skills && cp -r skills-src/agent/src/skills/credit-analysis .claude/skills/credit-analysis && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "credit-analysis" agent skill from https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysis into .claude/skills/credit-analysis/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "credit-analysis", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysisType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install HKUDS/Vibe-Trading credit-analysis --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .agents/skills && cp -r skills-src/agent/src/skills/credit-analysis .agents/skills/credit-analysis && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "credit-analysis" agent skill from https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysis into .agents/skills/credit-analysis/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "credit-analysis", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install HKUDS/Vibe-Trading credit-analysis --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/agent/src/skills/credit-analysis .cursor/skills/credit-analysis && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "credit-analysis" agent skill from https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysis into .cursor/skills/credit-analysis/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "credit-analysis", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/HKUDS/Vibe-Trading.git --path agent/src/skills/credit-analysis--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install HKUDS/Vibe-Trading credit-analysis --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/agent/src/skills/credit-analysis .gemini/skills/credit-analysis && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "credit-analysis" agent skill from https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysis into .gemini/skills/credit-analysis/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "credit-analysis", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install HKUDS/Vibe-Trading credit-analysisInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .github/skills && cp -r skills-src/agent/src/skills/credit-analysis .github/skills/credit-analysis && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "credit-analysis" agent skill from https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysis into .github/skills/credit-analysis/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "credit-analysis", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install HKUDS/Vibe-Trading credit-analysis --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/agent/src/skills/credit-analysis .opencode/skills/credit-analysis && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "credit-analysis" agent skill from https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/credit-analysis into .opencode/skills/credit-analysis/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "credit-analysis", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
credit-analysisCovers bond pricing, credit ratings, default risk models (Altman Z-score, Merton, KMV), spread analysis and rate risk for fixed income work, with a focus on China's bond market; Chinese text.
The skill is meant to be the first stop for questions on bond pricing, yield to maturity, duration and convexity, issuer credit ratings, default probability, credit spreads, city investment (城投) bonds, ABS and MBS credit, interest rate risk such as DV01, and the structure of China's fixed income market. Its instructions are written in Chinese with English technical terms.
The credit framework starts with issuer versus issue ratings and a table lining up S&P, Moody's and Chinese scales, noting that domestic ratings run high. It then teaches the Altman Z-score with its zones and variants, the Merton structural model with its default probability and distance to default, the KMV expected default frequency approach, and a credit scorecard method using WOE and information value for retail loans and ABS collateral.
2 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit b1f6ce7. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
No scripts in the folder and no shell commands in SKILL.md (its code samples are python).
From the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Credit and Fixed Income Analysis loads about 4.8k tokens when it runs. Until then it costs about 14 tokens; SKILL.md has 984 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from HKUDS/Vibe-Trading at commit b1f6ce7, republished under its MIT licence (© HKUDS). 984 words, ~4,810 tokens.
.claude/skills/credit-analysis/SKILL.md (or your agent's skills folder).当用户提出以下类型问题时,优先调用本 skill:
| 类型 | 定义 | 评级对象 |
|---|---|---|
| 主体评级(Issuer Rating) | 发行人整体偿债能力 | 企业、政府、金融机构 |
| 债项评级(Issue Rating) | 特定债券的信用质量 | 具体债券,考虑抵押品、优先级、契约条款 |
债项评级可高于或低于主体评级(取决于担保结构)。
| S&P | Moody's | 中国评级 | 含义 |
|---|---|---|---|
| AAA | Aaa | AAA | 最高信用质量,极低违约风险 |
| AA+/AA/AA- | Aa1/Aa2/Aa3 | AA+/AA/AA- | 高质量,极低违约风险 |
| A+/A/A- | A1/A2/A3 | A+/A/A- | 较高信用质量 |
| BBB+/BBB/BBB- | Baa1/Baa2/Baa3 | BBB+/BBB/BBB- | 投资级下限(IG/HY分水岭) |
| BB+及以下 | Ba1及以下 | BB+及以下 | 高收益/投机级 |
| D | D | D | 违约 |
中国特点:国内评级虚高,AA级在国内约等同于国际BBB-,需结合评级展望(正面/稳定/负面)综合判断。
用于预测企业财务困境,原始模型适用于上市制造业:
Z = 1.2×X1 + 1.4×X2 + 3.3×X3 + 0.6×X4 + 1.0×X5| 变量 | 计算公式 | 含义 |
|---|---|---|
| X1 | 营运资本 / 总资产 | 流动性 |
| X2 | 留存收益 / 总资产 | 盈利积累 |
| X3 | EBIT / 总资产 | 盈利能力 |
| X4 | 股权市值 / 总负债账面值 | 财务杠杆 |
| X5 | 销售收入 / 总资产 | 资产效率 |
判断区间:
改进版本:
局限性:
将公司股权视为对公司资产的看涨期权(执行价格=债务面值):
核心假设:
dV = μV dt + σ_V V dW股权定价(BS公式):
E = V·N(d1) - D·e^(-rT)·N(d2)
d1 = [ln(V/D) + (r + σ_V²/2)T] / (σ_V·√T)
d2 = d1 - σ_V·√T违约概率(风险中性):
PD = N(-d2)距违约距离(DD, Distance to Default):
DD = [ln(V/D) + (μ - σ_V²/2)T] / (σ_V·√T)信用利差估算:
信用利差 ≈ -ln[N(d2) + (V/D·e^(rT))·N(-d1)] / T参数估算方法(联立方程组):
KMV 是 Merton 模型的商业化实现,由穆迪收购:
步骤:
DP = 短期债务 + 0.5×长期债务DD = (V - DP) / (V × σ_V)与 Merton 的区别:
EDF 参考区间(约):
适用于零售信贷/ABS 底层资产分析:
建模流程:
Score = A - B×ln(odds),通常基准分600,PDO=20WOE 和 IV 计算:
WOE_i = ln(好样本比例_i / 坏样本比例_i)
IV_i = (好样本比例_i - 坏样本比例_i) × WOE_i
总IV = Σ IV_iIV 参考标准:
即期利率曲线(Zero Curve):各期限无风险零息债收益率,通过 Bootstrap 方法从附息债提取。
远期利率曲线(Forward Curve):
f(T1, T2) = [(1+r2)^T2 / (1+r1)^T1]^(1/(T2-T1)) - 1期限利差:
收益率曲线形态:
| 形态 | 特征 | 经济含义 |
|---|---|---|
| 正斜率(Normal) | 长端>短端 | 经济扩张预期 |
| 平坦(Flat) | 各期限相近 | 经济转折点 |
| 倒挂(Inverted) | 短端>长端 | 衰退信号 |
| 驼峰(Humped) | 中端最高 | 流动性分层 |
票面利率(Coupon Rate):发行时约定,按面值计息。
到期收益率 YTM(Yield to Maturity): 使 债券现值 = 市场价格的内部收益率:
P = Σ [C/(1+y)^t] + F/(1+y)^n其中 C=票息,F=面值,y=YTM,n=期数。
当期收益率(Current Yield):CY = 年票息 / 市场价格(忽略本金损益)
修正久期(Modified Duration):
MD = -dP/P ÷ dy = Macaulay Duration / (1+y/m)含义:利率每变化1%,债券价格变化约MD%(反向)。
凸性(Convexity):
CX = [Σ t(t+1)·CF_t/(1+y)^(t+2)] / P
价格变化修正:ΔP/P ≈ -MD·Δy + 0.5·CX·(Δy)²定价函数是仓库里的实测代码,直接 import,不要在会话里重新手写:
from src.quantlib.fixedincome import bond_price
bond_price(face=100, coupon_rate=0.05, ytm=0.04, n_periods=5, freq=1)
# -> 104.4518... 5年期、票息5%、YTM=4%、年付两个约定在这里是显式参数,不是隐含假设:
compounding:"discrete"(默认,每年 freq 次离散复利,即上面 P = Σ C/(1+y/m)^t 的形式)或 "continuous"。bond_price 按整数付息期贴现,因此返回的是付息日的价格(净价,应计为 0)。
非付息日结算要另加应计利息才是全价(脏价):import datetime as dt
from src.quantlib.fixedincome import accrued_interest
accrued = accrued_interest(
face=100, coupon_rate=0.05, freq=2,
last_coupon=dt.date(2024, 1, 15),
settlement=dt.date(2024, 4, 15),
next_coupon=dt.date(2024, 7, 15),
day_count="30/360", # ACT/365F(默认) | ACT/360 | ACT/ACT | 30/360 | 30E/360
) # -> 1.25
dirty_price = bond_price(100, 0.05, 0.04, 10, 2) + accrued可转债的转股期权部分详见
convertible-bondskill,本节聚焦纯债价值。
纯债价值(Bond Floor):
纯债价值 = Σ [票息/(1+r_straight)^t] + 面值/(1+r_straight)^n其中 r_straight 为同评级同期限直债收益率。
转股溢价率与纯债溢价率:
下修条款信用含义: 下修转股价可能导致摊薄,需评估公司意愿(强赎冲动 vs 回售压力)。
资产质量指标:
早偿率模型:
CPR = 1 - (1 - SMM)^12
SMM = 1 - (1 - CPR)^(1/12)分层结构(Tranche)分析:
关键风险指标:
增信倍数 = (底层资产池规模 - 优先级规模) / 优先级规模
超额利差 = 底层资产池利率 - 优先级融资成本 - 服务费城投债(LGFV,地方政府融资平台债)是中国固收市场特有品种。
四维评估模型:
| 维度 | 核心指标 | 权重 |
|---|---|---|
| 区域财政实力 | 一般公共预算收入、GDP规模、财政自给率 | 40% |
| 平台层级 | 省级>市级>区县级,级别越高隐性支持越强 | 25% |
| 平台地位 | 是否唯一城投、资产注入力度、业务多元化 | 20% |
| 债务结构 | 有息负债规模、短期债务占比、再融资压力 | 15% |
隐性债务风险信号:
城投估值溢价结构(参考):
城投利率 ≈ 同期国债 + 流动性溢价(30-50bp) + 区域溢价(0-200bp) + 平台溢价(0-100bp)政策风险:2023年城投化债政策后分化加剧,关注:
时间加权现金流现值之和,单位为"年":
D_mac = Σ [t × CF_t/(1+y)^t] / P利率敏感性度量:
D_mod = D_mac / (1 + y/m)
ΔP ≈ -D_mod × P × Δy适用于含权债券(可赎回债、MBS等):
D_eff = (P_down - P_up) / (2 × P_0 × Δy)其中 P_down/P_up 为利率下移/上移Δy后的价格。
Dollar Duration = D_mod × P × 面值衡量久期对利率的敏感性(二阶效应):
C = Σ [t(t+1) × CF_t/(1+y)^(t+2)] / P
价格精确估算:
ΔP/P ≈ -D_mod·Δy + 0.5·C·(Δy)²凸性的价值:正凸性使债券在利率下行时涨幅大于预期(利率上行时跌幅小于预期),因此正凸性债券比负凸性债券(如可赎回债、MBS)更受青睐。
利率变动1基点(0.01%)导致的价格变化:
DV01 = D_mod × P × 0.0001组合层面:Portfolio DV01 = Σ (DV01_i × 持仓量_i)
用途:利率对冲比率计算
对冲比率 = DV01_被对冲头寸 / DV01_对冲工具衡量收益率曲线各关键期限平行移动1bp对价格的影响:
KRD_i = -ΔP/(P × Δy_i)(仅第i个关键利率变动1bp)Σ KRD_i ≈ D_mod(各关键利率久期之和约等于修正久期)应用:
久期匹配(Duration Matching):
使资产组合久期 = 负债久期,对利率平行移动免疫。
条件:Σ (w_i × D_i) = D_liability
现金流匹配(Cash Flow Matching): 直接匹配每期现金流,彻底消除再投资风险,但灵活性差、成本高。
条件免疫(Contingent Immunization): 当组合价值超过安全底线时主动管理,跌至底线时切换为被动免疫。
再平衡频率:
信用利差(Credit Spread)= 违约风险溢价 + 流动性溢价 + 税收溢价(部分市场)| 组成部分 | 影响因素 | 量化方式 |
|---|---|---|
| 违约风险溢价 | 评级、行业、财务状况、宏观周期 | CDS报价、模型测算 |
| 流动性溢价 | 发行规模、剩余期限、市场深度 | 买卖价差、换手率 |
| 税收溢价 | 国债免税优惠(部分国家/投资者) | 利率差异分析 |
利差衡量基准:
OAS(Option-Adjusted Spread): 剥离嵌入期权价值后的信用利差,适用于含权债比较:
P = Σ CF_t / (1 + r_t + OAS)^t正斜率(常见):长期利差 > 短期利差,反映期限不确定性叠加。
平坦/倒挂:
信用利差与国债收益率的相关性:
宏观因素:
行业因素:
个券因素:
利差压缩交易(Spread Tightening): 做多被低估(高利差)信用债,做空国债对冲利率风险。
利差扩大交易(Spread Widening): 做空信用债(通过CDS),做多国债。
跨评级利差交易: 做多高收益/做空投资级(利差压缩时),或相反。
蝶式利差交易(Butterfly): 做多中期、做空短端和长端,获利于信用曲线中段的相对价值。
中国特色工具:
本章的模型已经是仓库里的实测代码,位于 src/quantlib/fixedincome.py(债券数学 + 曲线拟合)
与 src/quantlib/credit.py(Altman Z / Merton-KMV / 利差)。两个模块都有对应的
tests/quantlib/test_fixedincome.py、tests/quantlib/test_credit.py,久期与 DV01 是对
"重新定价 ±1bp" 逐点核过的。
直接 import 调用,不要在会话里重写这些公式。 手写一遍既拿不到测试保障,也不可复现。
一律的单位约定:利率与比率是小数(0.05 表示 5%),期限与时间跨度是年,
久期/凸性的返回值是年 / 年²(不是付息期数),带 _bp 后缀的才是基点。
from src.quantlib.fixedincome import (
bond_price, ytm_solve, macaulay_duration, modified_duration,
convexity, dv01, effective_duration,
)
face, coupon, ytm, n, freq = 100, 0.05, 0.04, 5, 1
price = bond_price(face, coupon, ytm, n, freq) # 104.4518
ytm_solve(price, face, coupon, n, freq) # 0.04(价格反解 YTM)
macaulay_duration(face, coupon, ytm, n, freq) # 4.5571 年
modified_duration(face, coupon, ytm, n, freq) # 4.3818 年
convexity(face, coupon, ytm, n, freq) # 24.4766 年²
dv01(face, coupon, ytm, n, freq, par_amount=1_000_000) # 457.69 元/bp参数要点
| 参数 | 说明 |
|---|---|
freq | 每年付息次数,1=年付、2=半年付。所有函数都接受,绝不写死 |
compounding | "discrete"(默认)或 "continuous"。连续复利下修正久期恒等于 Macaulay 久期 |
par_amount | dv01 的持仓面值,默认 100 万;对冲的市值按 par_amount * price / face 计 |
bracket | ytm_solve 的求根区间,默认 (-0.5, 10.0),覆盖所有可交易债券 |
含权债(可赎回债、MBS)的现金流会随利率移动,解析久期不适用,改用重新定价法:
d_eff = effective_duration(reprice=lambda y: my_oas_model(y), yield_level=0.04, bump=1e-4)reprice 必须自带赎回/早偿逻辑;effective_duration 只负责 (P_down - P_up) / (2·P₀·Δy)。
import numpy as np
from src.quantlib.fixedincome import fit_yield_curve, nelson_siegel, svensson
maturities = np.array([0.25, 0.5, 1, 2, 3, 5, 7, 10, 20, 30])
yields = np.array([0.019, 0.020, 0.022, 0.024, 0.025, 0.027, 0.028, 0.029, 0.033, 0.035])
fit = fit_yield_curve(maturities, yields, model="svensson")
fit.params # (beta0, beta1, beta2, beta3, lambda1, lambda2)
fit.rmse # 拟合残差(小数,与输入同单位)
fit(4.5) # 任意期限插值 -> 该点即期利率
fit([1, 5, 10]) # 也接受数组fit_yield_curve 返回一个 CurveFit 对象(不是 (params, func) 元组):它本身可调用,
同时带 model / params / rmse 三个只读字段。model 取 "nelson_siegel"(4 参数)
或 "svensson"(6 参数,双曲率因子)。
拟合方式是可分离最小二乘:给定衰减参数 λ 后 β 是线性的,用 OLS 精确求解, 只对 1~2 个 λ 做网格 + Nelder-Mead 搜索。这一点很要紧——对全部参数一起做单点起始的 L-BFGS-B(本 skill 早先模板的做法)连自己生成的曲线都还原不回来: 在 10 个期限的无噪 Nelson-Siegel 曲线上它停在 RMSE 6.4e-4(6.4bp), 而现在这个实现是 4.0e-14。
需要直接按参数取值(例如做因子分解、做情景模拟)时用底层函数:
nelson_siegel(tau=[1, 5, 10], beta0=0.045, beta1=-0.02, beta2=0.03, lambda1=2.5)
svensson(tau=5.0, beta0=0.05, beta1=-0.03, beta2=0.04, beta3=-0.02,
lambda1=1.2, lambda2=8.0)beta0 是水平因子(长端渐近利率),beta0 + beta1 是瞬时短端利率,
beta2 / beta3 是曲率因子,lambda* 是衰减速度(年)。传标量返回标量,传数组返回数组。
from src.quantlib.credit import altman_z_score
z = altman_z_score(
working_capital=200, # X1 分子:流动资产 - 流动负债
retained_earnings=300, # X2 分子:留存收益
ebit=150, # X3 分子:息税前利润
equity_value=900, # X4 分子:original 用股权市值,prime/double_prime 用账面净资产
total_liabilities=600, # X4 分母:全部负债的账面值
total_assets=1000, # X1/X2/X3/X5 的分母
revenue=1200, # X5 分子;double_prime 不需要,可省略
model="original", # original | prime | double_prime
)
z.z_score # 3.255
z.zone # "safe" | "grey" | "distress"
z.label_zh # "安全区(低违约风险)"
z.components # {"x1": 0.20, "x2": 0.30, "x3": 0.15, "x4": 1.50, "x5": 1.20}
z.safe_threshold # 2.99
z.distress_threshold # 1.81三个变体的系数与临界值在 ALTMAN_MODELS 里,与 §1.2 的表格一一对应:
model | 适用对象 | 系数 (X1..X5) | 安全 / 危险 |
|---|---|---|---|
original | 上市制造业(Altman 1968) | 1.2 / 1.4 / 3.3 / 0.6 / 1.0 | > 2.99 / < 1.81 |
prime(Z') | 私有企业,X4 改用账面净资产 | 0.717 / 0.847 / 3.107 / 0.420 / 0.998 | > 2.90 / < 1.23 |
double_prime(Z'') | 非制造业 / 新兴市场,去掉 X5 | 6.56 / 3.26 / 6.72 / 1.05 / — | > 2.60 / < 1.10 |
X4 的分母是「全部负债」,不是「有息负债」。 §1.2 的变量表写的是"总负债账面值", 参数名
total_liabilities与模型定义一致。用有息负债代入会系统性高估 Z 值。
同一份报表在三个变体下给出的分区可以不同(上例:original 安全区、prime 灰色区),
这正是重新标定的意义,不是矛盾。
from src.quantlib.credit import credit_spread_analysis, spread_term_structure
df = credit_spread_analysis(
bond_yields=bond_ytm_series, # pd.Series,索引=日期
risk_free_yields=cgb_ytm_series, # 必须与上面同一个索引
window=252, # 滚动窗口(交易日)
lookback_periods=21, # 慢速变化列的回溯期
signal_z=1.5, # 触发 rich/cheap 的 |z| 阈值
input_unit="percent", # percent | decimal | bp
)返回的 DataFrame 列固定为:spread_bp、rolling_mean_bp、rolling_std_bp、z_score、
historical_percentile、change_1p_bp、change_lookback_bp、signal。
signal 取 "rich"(利差偏低、偏贵)/ "neutral" / "cheap"(利差偏高、偏便宜)。
historical_percentile是全样本排名,带前视偏差,不能当回测信号用。 它把每一行 和它之后的行一起排序——同一天的分位数会随着新数据到来而改变(实测:同一行在 50 行 切片上是 0.02,在 100 行上变成 0.01)。这是原模板的行为,保留是为了不静默改变口径。z_score与signal走滚动窗口,是因果的,要做信号用这两个。
grid = spread_term_structure(
issuers={"AAA城投": {1: 0.025, 3: 0.028, 5: 0.032},
"AA城投": {1: 0.032, 3: 0.041, 5: 0.055}},
risk_free_curve={1: 0.020, 3: 0.022, 5: 0.025},
input_unit="decimal", # 注意默认值与上面那个函数不同
decimals=1,
)
# 行=发行人,列=1Y_spread_bp / 3Y_spread_bp / 5Y_spread_bp输入单位必须自己确认。 两个函数的历史默认值不一致:
credit_spread_analysis默认收益率是百分数(3.2表示 3.2%),spread_term_structure默认是小数(0.032)。 默认值保留了原模板的行为,但input_unit现在是显式参数——喂数据前先看清楚手里的序列是哪一种, 搞反就是 100 倍的利差。
from src.quantlib.credit import (
merton_model, merton_asset_solve, distance_to_default,
kmv_default_point, kmv_distance_to_default, edf_reference_band,
)
m = merton_model(
equity_value=100, # 股权市值
equity_vol=0.40, # 股权年化波动率
debt_face=100, # 债务面值(简化为单笔零息债)
risk_free=0.03, # 连续复利无风险利率
horizon=1.0, # 债务到期年限
asset_drift=None, # 距违约距离用的资产漂移;None = 用 risk_free(风险中性口径)
)
m.asset_value # 197.04 反推出的资产价值
m.asset_vol # 0.2030 反推出的资产波动率
m.distance_to_default # 3.3868 asset_drift=None 时等于 d2
m.default_probability # 0.000354 风险中性违约概率 N(-d2)
m.credit_spread_bp # 0.176 bp联立方程(§1.3 的两式)在 merton_asset_solve 里解,且是在对数空间求解的,
所以根不会跑到负资产或负波动率上;不收敛会直接抛 ValueError,不会静默返回垃圾解。
Merton 与 KMV 的 DD 是两个不同的量,不要混用:
# Merton:对数空间、带漂移与期限
distance_to_default(asset_value=200, asset_vol=0.25, default_point=100,
horizon=2.0, drift=0.06)
# KMV:线性缺口,无期限无漂移,违约点只含短债 + 部分长债
dp = kmv_default_point(short_term_debt=100, long_term_debt=200,
long_term_weight=0.5) # -> 200
kmv_distance_to_default(asset_value=1000, asset_vol=0.25, default_point=dp) # -> 3.2
edf_reference_band(3.2) # -> (0.001, 0.01),即 §8 表里的 0.1%–1% 档
edf_reference_band只是把 §8 那张"DD → EDF"经验表做成了查表函数。 真正的 KMV EDF 来自穆迪的专有违约数据库,这里的输出只能当量级校验, 绝不能当作已标定的违约概率报出去。
风险中性 vs 真实世界:asset_drift 只影响 distance_to_default,不影响 d2、
default_probability 和 credit_spread——后三者按定义就是风险中性的。想看真实世界口径,
传一个预期资产回报进去,然后配 edf_reference_band 读档,不要拿 N(-dd) 当 EDF 报。
| 维度 | 银行间市场(CFETS) | 交易所市场(上交所/深交所) |
|---|---|---|
| 监管机构 | 人民银行 | 证监会 |
| 主要参与者 | 银行、保险、基金、外资 | 券商、基金、个人投资者 |
| 交易方式 | 询价(OTC)+ 匿名点击 | 集中撮合 + 大宗交易 |
| 主要品种 | 国债、政金债、信用债、ABS | 企业债、公司债、可转债 |
| 规模占比 | ~90%(以交易量计) | ~10% |
| 结算方式 | T+0/T+1(DVP) | T+1 |
| 流动性 | 高(国债/政金债) | 高(可转债)/低(纯债) |
| 品种 | 发行主体 | 监管/注册 | 信用风险 |
|---|---|---|---|
| 国债(CGBs) | 财政部 | 无限制 | 无(主权信用) |
| 地方政府债 | 各省市政府 | 财政部审批 | 极低 |
| 政策性银行债(国开/农发/进出口) | 政策行 | 无限制 | 极低(准主权) |
| 同业存单(NCD) | 银行 | 央行 | 低(银行信用) |
| 超短期融资券(SCP)/ 短融(CP)/ 中票(MTN) | 非金融企业 | 交易商协会(NAFMII) | 中 |
| 企业债 | 企业 | 发改委 | 中高 |
| 公司债 | 上市公司 | 证监会 | 中高 |
| 城投债 | 地方融资平台 | 多元 | 中高(隐性政府背书) |
| ABS/ABN | SPV | NAFMII/证监会 | 取决于底层资产 |
一级市场分析(发行定价):
二级市场分析(持仓估值):
风险预警信号(红线):
净值化转型后的底层穿透分析:
流动性分析框架:
产品层面流动性 = f(底层资产流动性, 赎回条款, 摊余成本法 vs 市值法)底层信用评估步骤:
违约类型:
| 类型 | 特征 | 中国典型案例 |
|---|---|---|
| 流动性违约 | 资产健康但现金流断裂 | 部分中小房企 |
| 技术性违约 | 触发条款(交叉违约/加速到期) | 多见于弱资质主体 |
| 经营性违约 | 主业恶化导致还款能力下降 | 永煤、华晨(2020) |
| 欺诈性违约 | 财务造假/资产腾挪 | 康美药业、蓝盛博 |
违约前沿信号(Precursor Signals):
财务层面:
- 应收账款/总资产 异常增高(虚增收入)
- 货币资金余额高但受限比例高
- 商誉/无形资产占比持续增大
- 关联方交易占比异常
市场层面:
- 二级市场价格持续下跌(跌破90)
- 信用利差快速走阔(单周>50bp)
- 主承销商更换或不参与后续发行
- CDS报价(如有)快速上升
评级层面:
- 评级列入负面观察
- 多家评级机构下调
- 展望由稳定下调至负面事后分析框架(Post-Default Analysis):
中国市场回收率参考:
| 相关 Skill | 互补关系 |
|---|---|
convertible-bond | 可转债转股期权部分由 convertible-bond skill 处理,本 skill 负责纯债定价和信用风险 |
macro-analysis | 宏观利率环境和信用周期判断由 macro skill 提供输入 |
risk-management | 组合层面信用风险(VaR/CVaR)参考 risk-management skill |
equity-fundamental | 信用分析与股权估值共享财务报表分析框架,Altman Z-Score两侧均适用 |
YTM 近似公式:
YTM ≈ [C + (F-P)/n] / [(F+P)/2]
久期与价格变化:
ΔP ≈ -D_mod × P × Δy + 0.5 × CX × P × (Δy)²
DV01 = D_mod × P × 0.0001 × 持仓面值
信用利差 = 债券YTM - 同期限国债YTM
Z-Score 风险信号:
Z > 2.99 → 安全 1.81 < Z < 2.99 → 灰色 Z < 1.81 → 危险
违约距离 DD → EDF:
DD > 4: EDF < 0.1%
DD 2-4: EDF 0.1%-1%
DD 1-2: EDF 1%-5%
DD < 1: EDF > 5%| 数据类型 | 推荐来源 |
|---|---|
| 国债收益率曲线 | 中央结算公司(CCDC)、财政部官网 |
| 信用债行情 | Wind、DM数据 |
| 城投财务数据 | 发债主体年报、Wind |
| 评级报告 | 中诚信、联合资信、东方金诚官网 |
| 违约数据 | Wind、中国债券信息网(chinamoney.com.cn) |
| ABS数据 | CNABS(中国资产证券化分析网) |
© HKUDS, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in agent/src/skills/credit-analysis of HKUDS/Vibe-Trading.
Open the folder on GitHubat commit b1f6ce7
Credit and Fixed Income Analysis next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Credit and Fixed Income Analysis this skillHKUDS/Vibe-Trading | 35k | — | ~4.8k | Automated safety check: Pass | MIT | |
| Stock Deep Analysis Workflowwbh604/UZI-Skill | 7.1k | — | ~9.1k | Automated safety check: Notes | MIT | |
| Three-Statement Model Builderginlix-ai/LangAlpha | 1.8k | — | ~5.4k | Automated safety check: Pass | Apache-2.0 | |
| Money Financeiamzifei/show-me-the-money | 1k | — | ~2.2k | Automated safety check: Pass | Custom licence | |
| Financial Model Checkerginlix-ai/LangAlpha | 1.8k | — | ~4.2k | Automated safety check: Pass | Apache-2.0 | |
| DCF Model Builderginlix-ai/LangAlpha | 1.8k | — | ~7.7k | Automated safety check: Pass | Apache-2.0 |
wbh604/UZI-Skill
Runs a staged deep analysis of a single stock on China A-share, Hong Kong and US markets, ending in an HTML report with valuation models and investor-panel scores.
ginlix-ai/LangAlpha
Builds or repairs an integrated income statement, balance sheet and cash flow model in Excel with live formulas, supporting schedules, scenarios and a Checks sheet.
iamzifei/show-me-the-money
Financial tracking, revenue analytics, expense management, and pricing optimization.
ginlix-ai/LangAlpha
Audits an existing Excel financial model without editing it, checking structure, formulas, integrity identities and source tie-out, and ends in a prioritized issue log.
ginlix-ai/LangAlpha
Builds a live Excel DCF valuation workbook with free cash flow projections, WACC, terminal value, three scenarios, sensitivity grids and a reverse DCF.
helsome/folio
Financial statements, business segments, dividends, valuation multiples (PE/PB/PS), industry comparison, operating data, corporate actions, company and executive profiles, cross-stock comparison…
HKUDS/Vibe-Trading
Index of Eastmoney's free, no-token market data interfaces for China A-shares and Hong Kong stocks: fund flows, dragon-tiger lists, margin trading, reports and news.
HKUDS/Vibe-Trading
Retrieves public OKX cryptocurrency market data such as spot prices, candlesticks, funding rates and open interest through the OKX V5 REST API, with no authentication.
HKUDS/Vibe-Trading
Fetches U.S. SEC EDGAR data: resolves tickers to CIK numbers, lists recent 10-K, 10-Q and 8-K filings with document URLs, and pulls XBRL financial series.
HKUDS/Vibe-Trading
Predicts whether a mainland China A-share company risks an ST or *ST warning after its next annual report, using financial thresholds and Sina penalty records.
HKUDS/Vibe-Trading
Breaks a structural trend such as AI infrastructure into its physical supply chain and ranks lesser-known listed companies sitting on each bottleneck.
HKUDS/Vibe-Trading
Plans and drafts an eight-part, roughly 120k-word investigative series on one company, built around a strict fact-check pass rather than fast drafting.
Categories
Covers bond pricing, credit ratings, default risk models (Altman Z-score, Merton, KMV), spread analysis and rate risk for fixed income work, with a focus on China's bond market; Chinese text. The skill is meant to be the first stop for questions on bond pricing, yield to maturity, duration and convexity, issuer credit ratings, default probability, credit spreads, city investment (城投) bonds, ABS and MBS credit, interest rate risk such as DV01, and the structure of China's fixed income market. Its instructions are written in Chinese with English technical terms.
Credit and Fixed Income Analysis fits situations like: estimating the default risk of a bond issuer with the Altman Z-score or the Merton model; comparing S&P, Moody's and Chinese domestic ratings; analyzing credit spreads and interest rate risk for a bond portfolio; assessing ABS or MBS collateral with scorecard methods.
Run `npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a claude-code`. Or copy the skill folder (agent/src/skills/credit-analysis in HKUDS/Vibe-Trading) into .claude/skills/credit-analysis in your project. Claude Code loads it when a task matches its description.
Run `npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a codex`. Or copy the skill folder (agent/src/skills/credit-analysis in HKUDS/Vibe-Trading) into .agents/skills/credit-analysis in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add HKUDS/Vibe-Trading --skill credit-analysis -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/credit-analysis, .gemini/skills/credit-analysis, .github/skills/credit-analysis and .opencode/skills/credit-analysis in your project.
SKILL.md names no scripts, command-line tools or credentials: Credit and Fixed Income Analysis is instructions for the agent only.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Credit and Fixed Income Analysis is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 4.8k tokens (SKILL.md is roughly 19k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Credit and Fixed Income Analysis: Stock Deep Analysis Workflow (wbh604/UZI-Skill, 7.1k stars), Three-Statement Model Builder (ginlix-ai/LangAlpha, 1.8k stars), Money Finance (iamzifei/show-me-the-money, 1k stars) and Financial Model Checker (ginlix-ai/LangAlpha, 1.8k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
HKUDS (a GitHub organization) maintains it in HKUDS/Vibe-Trading, which has 35,097 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on October 9, 2026.
Source: HKUDS/Vibe-Trading on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.