来源信息
- 仓库
- brycewang-stanford/Auto-Empirical-Research-Skills
- 最近来源活动
- 2026年4月3日 02:07
- 检测到的 SKILL.md 语言
- 英语
- 星标
- 3,291
- 分支
- 432
安装方式
默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。
检查来源文件
决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。
菜单
默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。
决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills --skill risk-modeling-guide命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Route empirical-research requests through the Auto-Empirical Research Skills catalog when this whole repository is installed as one skill in Codex, CodeBuddy, Claude Code, or another IDE. Use to choose and load the right vendored AERS skill for causal inference, econometrics, replication, data acquisition, manuscript writing, peer review and referee responses, citation checking, de-AIGC editing, or full empirical-paper workflows without reading the entire repository at once.
中英双语学术降 AIGC / bilingual academic de-AIGC skill. Removes AI-generated writing signatures from empirical papers in economics, management, and the social sciences — in both English and Chinese. Covers Turnitin AI, GPTZero, Originality.ai on the English side and 知网 AMLC, 万方, 维普 on the Chinese side. Uses a six-step loop (intake → audit → claim-evidence check → differentiated rewrite → five-dimension self-score → cold-reader recheck) with two pattern libraries (22 English + 17 Chinese patterns), section-by-section strategies for empirical papers, and hard protections that keep every number, coefficient, and citation intact.
Use when a research task needs reproducible Kaggle discovery, metadata inspection, bounded public-data downloads, competition or kernel discovery, model discovery, or an explicitly approved Kaggle write/delete operation through the official CLI.
基于 SOC 职业分类
正在显示 SKILL.md
| name | risk-modeling-guide |
| description | Financial risk modeling including VaR, stress testing, and credit risk |
| metadata | {"openclaw":{"emoji":"📉","category":"domains","subcategory":"finance","keywords":["risk-modeling","var","stress-testing","credit-risk","monte-carlo","basel"],"source":"wentor"}} |
A skill for quantitative financial risk modeling, covering Value at Risk, Expected Shortfall, credit risk, stress testing, and Monte Carlo simulation methods. Essential for financial engineering research and regulatory risk analysis.
| Method | Description | Pros | Cons |
|---|---|---|---|
| Historical simulation | Replay past returns | No distributional assumption | Assumes past repeats |
| Variance-covariance | Assume normal returns | Fast, analytical | Underestimates tail risk |
| Monte Carlo simulation | Simulate from fitted model | Flexible distributions | Computationally expensive |
| Filtered historical simulation | GARCH + historical innovations | Captures volatility clustering | More complex |
import numpy as np
import pandas as pd
from scipy.stats import norm, t as t_dist
def historical_var(returns: np.ndarray, confidence: float = 0.99,
horizon_days: int = 1) -> dict:
"""
Compute Value at Risk using historical simulation.
returns: array of daily log returns
confidence: confidence level (e.g., 0.99 for 99% VaR)
horizon_days: risk horizon in days
"""
# Scale returns to horizon
if horizon_days > 1:
# Rolling sum for overlapping returns
scaled_returns = pd.Series(returns).rolling(horizon_days).sum().dropna().values
else:
scaled_returns = returns
alpha = 1 - confidence
var = -np.percentile(scaled_returns, alpha * 100)
es = -np.mean(scaled_returns[scaled_returns <= -var])
return {
"VaR": round(var, 6),
"Expected_Shortfall": round(es, 6),
"confidence": confidence,
"horizon_days": horizon_days,
"n_observations": len(scaled_returns),
}
def parametric_var(returns: np.ndarray, confidence: float = 0.99,
distribution: str = "normal") -> dict:
"""
Parametric VaR assuming normal or Student-t distribution.
"""
mu = np.mean(returns)
sigma = np.std(returns, ddof=1)
if distribution == "normal":
z = norm.ppf(1 - confidence)
var = -(mu + sigma * z)
# Analytical ES for normal
es = -mu + sigma * norm.pdf(norm.ppf(1 - confidence)) / (1 - confidence)
elif distribution == "student-t":
# Fit Student-t
df, loc, scale = t_dist.fit(returns)
z = t_dist.ppf(1 - confidence, df)
var = -(loc + scale * z)
# ES for Student-t
t_pdf = t_dist.pdf(t_dist.ppf(1 - confidence, df), df)
es = -loc + scale * (t_pdf / (1 - confidence)) * ((df + z**2) / (df - 1))
else:
raise ValueError(f"Unknown distribution: {distribution}")
return {
"VaR": round(var, 6),
"Expected_Shortfall": round(es, 6),
"distribution": distribution,
"mean": round(mu, 6),
"std": round(sigma, 6),
}
def monte_carlo_var(returns: np.ndarray, n_simulations: int = 100000,
confidence: float = 0.99,
horizon_days: int = 10) -> dict:
"""
Monte Carlo VaR using GBM (Geometric Brownian Motion).
"""
mu = np.mean(returns)
sigma = np.std(returns, ddof=1)
# Simulate daily returns for the horizon
rng = np.random.default_rng(42)
simulated = rng.normal(
mu * horizon_days,
sigma * np.sqrt(horizon_days),
size=n_simulations,
)
alpha = 1 - confidence
var = -np.percentile(simulated, alpha * 100)
es = -np.mean(simulated[simulated <= -var])
return {
"VaR": round(var, 6),
"Expected_Shortfall": round(es, 6),
"n_simulations": n_simulations,
"confidence": confidence,
"horizon_days": horizon_days,
}
from sklearn.linear_model import LogisticRegression
def build_pd_model(features: pd.DataFrame,
default_flag: pd.Series) -> dict:
"""
Build a Probability of Default (PD) model using logistic regression.
Common features: debt-to-income, credit utilization, payment history,
employment length, loan amount.
"""
model = LogisticRegression(max_iter=1000, class_weight="balanced")
model.fit(features, default_flag)
# Coefficient interpretation
coef_df = pd.DataFrame({
"feature": features.columns,
"coefficient": model.coef_[0],
"odds_ratio": np.exp(model.coef_[0]),
}).sort_values("coefficient", ascending=False)
# Model discrimination
from sklearn.metrics import roc_auc_score
pred_proba = model.predict_proba(features)[:, 1]
auc = roc_auc_score(default_flag, pred_proba)
return {
"auc": round(auc, 4),
"coefficients": coef_df.to_dict("records"),
"intercept": round(model.intercept_[0], 4),
}
def compute_expected_loss(pd_score: float, lgd: float,
ead: float) -> dict:
"""
Compute Expected Loss = PD x LGD x EAD.
pd_score: probability of default (0-1)
lgd: loss given default (0-1, fraction of exposure lost)
ead: exposure at default (dollar amount)
"""
el = pd_score * lgd * ead
return {
"PD": pd_score,
"LGD": lgd,
"EAD": ead,
"Expected_Loss": round(el, 2),
"Unexpected_Loss_99": round(el * 2.33 * np.sqrt(pd_score * (1 - pd_score)), 2),
}
def run_stress_test(portfolio_returns: pd.DataFrame,
scenarios: dict[str, dict]) -> pd.DataFrame:
"""
Apply macroeconomic stress scenarios to a portfolio.
scenarios: {name: {factor: shock_value}} where factors are
macroeconomic variables (interest_rate, gdp_growth, unemployment, etc.)
"""
# Factor sensitivities (betas from regression)
# In practice, estimated via historical regression
factor_betas = {
"interest_rate": -0.15, # portfolio loses 15bp per 1% rate increase
"gdp_growth": 0.08, # gains 8bp per 1% GDP growth
"unemployment": -0.12, # loses 12bp per 1% unemployment increase
"equity_market": 0.45, # 45bp per 1% equity market move
"credit_spread": -0.25, # loses 25bp per 1% spread widening
}
results = []
for name, shocks in scenarios.items():
portfolio_impact = 0
for factor, shock in shocks.items():
beta = factor_betas.get(factor, 0)
portfolio_impact += beta * shock
results.append({
"scenario": name,
"portfolio_impact_pct": round(portfolio_impact * 100, 2),
"shocks": shocks,
})
return pd.DataFrame(results)
# Example scenarios
scenarios = {
"Mild Recession": {
: -, : -,
: , : -,
: ,
},
: {
: -, : -,
: , : -,
: ,
},
: {
: , : -,
: , : -,
: ,
},
}
| Risk Type | Measurement | Capital Charge |
|---|---|---|
| Market risk | FRTB (Fundamental Review of the Trading Book) | ES at 97.5%, stressed calibration |
| Credit risk | SA or IRB approach | PD, LGD, EAD based risk weights |
| Operational risk | Basic Indicator / Standardized | Business indicator x ILM |
| Liquidity risk | LCR and NSFR ratios | High-quality liquid assets buffer |