Token导航 LogoToken导航TokenDH.com
待分类只读github未标认证来源可访问许可证需确认审计通过

historical-risk历史风险

Agent Skill

historical-risk 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,811

周安装

77

GitHub Stars

58

下载量

634
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:historical-risk(历史风险)
来源仓库:https://github.com/joellewis/finance_skills
仓库路径:skills/historical-risk
安装命令:
npx skills add https://github.com/joellewis/finance_skills --skill historical-risk
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/joellewis/finance_skills --skill historical-risk

简介

historical-risk 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合围绕项目状态进行整理。

  • 适用于代码变更追踪、协作事项管理和仓库状态分析等场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用该技能。
  • 安装前需确认权限范围、维护状态,避免触发联网或命令执行操作。
  • 建议结合原始 README 核验具体用法和功能边界。

SKILL.md

Historical Risk Analysis

Purpose

Quantify how risky an investment or portfolio has been using historical return and price data. This skill covers volatility estimation (close-to-close, Parkinson, Yang-Zhang), drawdown analysis, historical Value-at-Risk, downside deviation, tracking error, and semi-variance. All measures are backward-looking and computed from observed data.

Layer

1a — Realized Risk & Performance

Direction

Retrospective

When to Use

  • Understanding how risky an investment has been over a past period
  • Computing historical (realized) volatility using various estimators
  • Measuring drawdowns: maximum drawdown, drawdown duration, and recovery time
  • Calculating historical VaR (non-parametric, directly from the return distribution)
  • Computing downside deviation or semi-variance for asymmetric risk assessment
  • Measuring tracking error of a portfolio relative to a benchmark

Core Concepts

Close-to-Close Volatility

The simplest and most common volatility estimator. Compute the standard deviation of log returns and annualize.

sigma_annual = sigma_daily * sqrt(N)

where N = number of trading periods per year (typically 252 for daily, 52 for weekly, 12 for monthly).

Log returns are preferred: r_t = ln(P_t / P_{t-1}).

Parkinson (High-Low) Estimator

Uses intraday high and low prices to capture intraday volatility that close-to-close misses. More efficient than close-to-close when the true process is continuous.

sigma^2_Park = (1 / (4 * n * ln(2))) * sum( ln(H_i / L_i)^2 )

This estimator is roughly 5x more efficient than close-to-close for a diffusion process, but is biased downward when there are jumps or when the range is discretized.

Yang-Zhang Estimator

Combines overnight (close-to-open), open-to-close, and Rogers-Satchell components. It is unbiased for processes with both drift and opening jumps.

sigma^2_YZ = sigma^2_overnight + k * sigma^2_open-to-close + (1 - k) * sigma^2_RS

where k is chosen to minimize estimator variance, and sigma^2_RS is the Rogers-Satchell estimator that uses all four OHLC prices within each period.

Drawdown Analysis

Drawdown at time t measures the decline from the running peak:

DD_t = (Peak_t - Value_t) / Peak_t

where Peak_t = max(Value_s) for all s <= t.

  • Maximum Drawdown (MDD): MDD = max(DD_t) over the evaluation period.
  • Drawdown Duration: The number of periods from a peak until a new peak is reached.
  • Recovery Time: The number of periods from the trough back to the prior peak level.

Historical VaR

The non-parametric (empirical) Value-at-Risk is simply the alpha-percentile of the historical return distribution. No distributional assumptions are made.

VaR_alpha = -Percentile(R, alpha)

For example, 95% VaR uses the 5th percentile of returns. The negative sign is a convention so that VaR is expressed as a positive loss number.

Downside Deviation

Measures dispersion of returns below a Minimum Acceptable Return (MAR):

sigma_d = sqrt( (1/n) * sum( min(R_i - MAR, 0)^2 ) )

Common choices for MAR: 0%, the risk-free rate, or the mean return.

Tracking Error

Standard deviation of the difference between portfolio and benchmark returns, annualized:

TE = std(R_p - R_b) * sqrt(N)

This measures how consistently the portfolio tracks (or deviates from) its benchmark.

Semi-Variance

Variance computed using only returns below the mean (or below a threshold):

SV = (1/n) * sum( min(R_i - mean(R), 0)^2 )

Semi-variance isolates downside risk and is the foundation for the Sortino ratio (see performance-metrics).

Key Formulas

FormulaExpressionUse Case
Annualized Volatilitysigma_ann = sigma_period * sqrt(N)Convert period vol to annual vol
Log Returnr_t = ln(P_t / P_{t-1})Compute continuously compounded returns
Parkinson Variancesigma^2 = (1 / (4n ln2)) * sum(ln(H/L)^2)Volatility from high-low data
DrawdownDD_t = (Peak_t - Value_t) / Peak_tMeasure peak-to-trough decline
Max DrawdownMDD = max(DD_t)Worst historical decline
Historical VaR (95%)5th percentile of return seriesNon-parametric loss estimate
Downside Deviationsigma_d = sqrt((1/n) * sum(min(R_i - MAR, 0)^2))Asymmetric risk below MAR
Tracking ErrorTE = std(R_p - R_b) * sqrt(N)Portfolio vs benchmark deviation
Semi-Variance(1/n) * sum(min(R_i - mean(R), 0)^2)Below-mean variance

Worked Examples

Example 1: Annualized Volatility from Daily Returns

Given: A stock has daily log returns with a sample standard deviation of 1.2%. Assume 252 trading days per year.

Calculate: Annualized volatility.

Solution:

sigma_annual = 0.012 * sqrt(252)
             = 0.012 * 15.875
             = 0.1905
             ~ 19.05%

The stock's annualized volatility is approximately 19%.

Example 2: Maximum Drawdown from a Price Series

Given: A fund's NAV follows this path over six months: $120, $135, $150, $130, $105, $125.

Calculate: Maximum drawdown and identify the peak and trough.

Solution:

Running peaks: $120, $135, $150, $150, $150, $150.

Drawdowns at each point:

  • $120: (120-120)/120 = 0%
  • $135: (135-135)/135 = 0%
  • $150: (150-150)/150 = 0%
  • $130: (150-130)/150 = 13.3%
  • $105: (150-105)/150 = 30.0%
  • $125: (150-125)/150 = 16.7%

Maximum Drawdown = 30.0%, occurring from the peak of $150 to the trough of $105. As of the last observation ($125), the drawdown has not yet fully recovered.

Example 3: Historical VaR

Given: 500 daily returns sorted from worst to best. The 25th-worst return is -2.8% and the 26th-worst is -2.6%.

Calculate: 95% 1-day historical VaR.

Solution:

The 5th percentile corresponds to the 25th observation out of 500 (500 * 0.05 = 25).

VaR_95% = -(-2.8%) = 2.8%

Interpretation: On 95% of days, the loss is expected not to exceed 2.8% based on the historical distribution.

Common Pitfalls

  • Not annualizing volatility correctly: Volatility scales with the square root of time (multiply by sqrt(N)), not linearly. Multiplying daily vol by 252 instead of sqrt(252) produces wildly inflated numbers.
  • Using calendar days vs trading days inconsistently: Use 252 trading days (not 365 calendar days) for equity markets when annualizing. Bond markets and some international markets may differ.
  • Survivorship bias in historical data: Data sets that exclude delisted or failed securities understate realized risk.
  • Lookback period sensitivity: A 1-year lookback captures different risk regimes than a 5-year lookback. Always state the lookback window and consider whether it spans relevant market conditions.
  • Confusing VaR confidence level direction: 95% VaR corresponds to the 5th percentile of returns (the loss tail). The "95%" refers to the confidence level, not the percentile of gains.
  • Log returns vs simple returns: For volatility estimation, log returns are preferred because they are additive across time. For reporting cumulative performance, simple returns are more intuitive.

Cross-References

  • performance-metrics (wealth-management plugin, Layer 1a): Uses volatility, downside deviation, tracking error, and max drawdown as denominators in risk-adjusted ratios (Sharpe, Sortino, Information Ratio, Calmar).
  • forward-risk (wealth-management plugin, Layer 1b): Historical VaR and historical volatility serve as inputs to forward-looking VaR models and stress tests.
  • volatility-modeling (wealth-management plugin, Layer 1b): EWMA and GARCH models extend the simple historical volatility estimators covered here into forecasting frameworks.

Reference Implementation

See scripts/historical_risk.py for computational helpers.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.87%
按下载量换算234

Claude

30.06%
按下载量换算191

Cursor

19.39%
按下载量换算123

Gemini CLI

9.79%
按下载量换算62

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills