Chuyển đến nội dung
Skillpedia
Phân tích và bảng tính37k · #7550

risk-analysis

Skill này làm gì

Skill này đo lường một danh mục có thể thua lỗ bao nhiêu trong thị trường xấu. Skill dành cho nhà đầu tư và nhà phân tích cần con số rõ ràng về rủi ro giảm giá.

Khi nào nên dùng

  • ✓Khi bạn muốn biết một danh mục có thể thua lỗ bao nhiêu trong một ngày xấu hoặc một tháng xấu.
  • ✓Khi bạn cần xem mức sụt giảm đỉnh đến đáy tệ nhất mà một chiến lược từng trải qua.
  • ✓Khi bạn muốn kiểm tra danh mục với các cuộc khủng hoảng trong quá khứ hoặc các đường đi giá mô phỏng.

Liên kết skill

https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/risk-analysis/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/risk-analysis/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Với danh mục hiện tại, tôi có thể thua lỗ bao nhiêu trong một ngày xấu, và mức sụt giảm tệ nhất là bao nhiêu?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill tính các chỉ số như giá trị rủi ro (VaR), tổn thất kỳ vọng và mức sụt giảm tối đa từ lợi nhuận quá khứ. Nó cũng có thể mô phỏng nhiều đường đi giá khả dĩ để thể hiện một dải kết quả rộng hơn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Risk Measurement and Stress Testing

Overview

Systematic risk-measurement methodology covering VaR/CVaR calculation, Monte Carlo simulation, stress-test design, and tail-risk analysis. It provides risk evaluation for backtest results and risk-control constraints for asset allocation.

The measures below are implemented once, with tests, in src/quantlib/risk.py. Call them; do not retype the formulas, because a hand-retyped VaR is where the sign convention silently flips.

from src.quantlib.risk import (
    historical_var, parametric_var, historical_cvar,
    max_drawdown_analysis, monte_carlo_gbm, analyze_mc_results, fit_gpd_tail,
)

Sign convention

A loss is a positive number, uniformly, across every function in the module:

Value Reads as
historical_var(...) == 0.028 a 2.8% loss
historical_cvar(...) == 0.042 a 4.2% average loss in the tail
max_drawdown_analysis(...)["max_drawdown"] == 0.325 a 32.5% peak-to-trough decline
analyze_mc_results(...)["var"] == 0.224 a 22.4% loss

Quantities that are returns rather than losses keep their natural sign and are named *_return (mean_return, worst_5pct_return, best_5pct_return), so a bad outcome there is negative. Report VaR to the user with the sign the user expects, but never re-derive it — flip it at the presentation layer only.

cvar >= var holds by construction whenever both come from the same sample at the same confidence level. If you ever compute a CVaR below its VaR, the tail mask is wrong.

This is not cvar >= var >= 0. The magnitudes are never clipped, so a sample whose tail contains no actual loss reports a negative loss — a gain. That is deliberate and informative; do not assert non-negativity on a VaR and do not clip it, or you destroy the distinction between "small loss" and "no loss at all".

Risk Measurement Methods

1. VaR (Value at Risk)

Definition: the maximum expected loss over a given horizon at a specified confidence level.

Three Calculation Methods

Method Formula / Steps Advantages Disadvantages
Historical simulation Sort historical returns and take the quantile No distribution assumption Depends on historical samples
Parametric (normal) VaR = μ - z_α × σ Easy to compute Assumes a normal distribution
Monte Carlo Simulate N paths and take the quantile Flexible Computationally intensive

Historical Simulation

Reads the loss straight off the sorted sample, so it inherits whatever fat tails the history actually had. horizon scales by the square-root-of-time rule, which is only valid under i.i.d. returns.

historical_var(returns, confidence=0.95)              # 1-day 95% VaR
historical_var(returns, confidence=0.99, horizon=10)  # 10-day 99% VaR

The quantile is a non-interpolating lower order statistic: element ceil((1 - confidence) * n) - 1 of the ascending-sorted returns, negated. The result is therefore always a return that was actually observed, never a blend of two neighbours.

Parametric (normal)

parametric_var(returns, confidence=0.95)

Fits mu and the sample sigma (ddof=1) and returns -(mu + z*sigma) with z = norm.ppf(1 - confidence). Needs at least 2 observations.

Do not assume the parametric figure is the lower one. The direction of the gap depends on the confidence level. A fat tail inflates the fitted sigma, which pushes the normal quantile outward at moderate confidence, where the empirical quantile is still sitting in the well-behaved body. Measured over 300 t(4) samples of 750 daily returns:

Confidence Parametric reads above historical
90% 100% of samples
95% 92.7%
97.5% 40.3%
99% 5.3%

So the familiar "parametric understates risk" result only appears at 99% and deeper. At the 95% default it is normally the higher of the two, and that is not a sign your code is wrong. Quote both at 99% when the point is to expose the tail.

2. CVaR / ES (Conditional VaR / Expected Shortfall)

Definition: the average loss beyond the VaR threshold, more conservative than VaR.

historical_cvar(returns, confidence=0.95)
historical_cvar(returns, confidence=0.99, horizon=10)

Averages the VaR order statistic together with everything worse than it (inclusive), which is the standard expected shortfall and is what makes cvar >= var structu

Câu hỏi thường gặp

VaR nghĩa là gì?

Giá trị rủi ro (Value at Risk) là ước tính mức thua lỗ không nên vượt quá trong đa số trường hợp, ở một mức tin cậy đã chọn.

Tại sao các khoản lỗ được hiển thị là số dương?

Skill dùng một quy tắc chung cho mọi chỉ số: khoản lỗ là số dương, nên kết quả dễ so sánh.

Skill có kiểm tra một cuộc khủng hoảng trong quá khứ không?

Có. Nó hỗ trợ kiểm tra căng thẳng theo kịch bản lịch sử, tức là tái hiện các cú sốc thị trường trước đây lên danh mục.

Chi tiết

Mô tả gốc của tác giả

Risk measurement and stress testing — VaR/CVaR/max drawdown calculation, Monte Carlo simulation, extreme-value tail-risk analysis, and historical scenario stress testing.

repo: HKUDS/Vibe-Trading

Độ phổ biến

Sao GitHub
37k
Vị trí xếp hạng
#7550
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự