risk-analysis
Was er macht
Dieser Skill misst, wie viel ein Portfolio in schlechten Märkten verlieren könnte. Er ist für Anleger und Analysten gedacht, die klare Zahlen zum Abwärtsrisiko wollen.
Wann du ihn nutzt
- ✓Wenn du wissen willst, wie viel ein Portfolio an einem schlechten Tag oder in einem schlechten Monat verlieren könnte.
- ✓Wenn du den schlimmsten Rückgang von Hoch zu Tief sehen willst, den eine Strategie erlebt hat.
- ✓Wenn du ein Portfolio gegen vergangene Krisen oder simulierte Marktpfade testen willst.
Link zum Skill
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/risk-analysis/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Wie viel könnte ich mit meinem aktuellen Portfolio an einem schlechten Tag verlieren, und wie groß war der schlimmste Drawdown?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Skill berechnet Kennzahlen wie Value at Risk, Expected Shortfall und maximalen Drawdown aus vergangenen Renditen. Außerdem kann er viele mögliche Kursverläufe simulieren, um eine breitere Spanne von Ergebnissen zu zeigen.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
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
Häufige Fragen
Was bedeutet VaR?
Value at Risk ist eine Schätzung des Verlusts, der bei einem gewählten Konfidenzniveau in den meisten Fällen nicht überschritten werden sollte.
Warum werden Verluste als positive Zahlen angezeigt?
Der Skill nutzt eine Regel für alle Kennzahlen: Ein Verlust ist eine positive Zahl, damit die Ergebnisse leicht zu vergleichen sind.
Kann er eine Krise der Vergangenheit testen?
Ja. Er unterstützt historische Szenario-Stresstests, die vergangene Marktschocks auf ein Portfolio anwenden.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 37k
- Platz im Ranking
- #7550
- Lizenz
- MIT
- Aktualisiert
- 1.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
vibe-trading
37kGibt deinem Agenten ein vollständiges Werkzeugset für Finanzrecherche, mit Backtests, Faktoranalysen, Optionspreisen und Marktdaten aus vielen Märkten.
adr-hshare
37kZeigt deinem Agenten, wie er den Preis eines chinesischen Unternehmens vergleicht, das an mehreren Börsen notiert ist, etwa einer US-ADR und einer Hongkong-Aktie.
akshare
37kLässt deinen Agenten kostenlose Marktdaten für chinesische und globale Aktien, Futures, Devisen und Wirtschaftsindikatoren abrufen, ganz ohne API-Schlüssel.
alpha-zoo
37kLässt deinen Agenten in einer Bibliothek fertiger Aktienfaktoren stöbern und testen, wie gut eine ganze Gruppe davon die Renditen auf einem gewählten Markt vorhersagt.
Ähnliche Skills
gitcrawl
394kLässt deinen Agenten ein gespeichertes Archiv von GitHub-Issues und Pull Requests durchsuchen, Duplikate gruppieren und ihren aktuellen Status auf GitHub prüfen.
slacrawl
394kLässt deinen Agenten Nachrichten in einem lokalen Slack-Archiv durchsuchen und zählen, dessen Aktualität prüfen und es bei Bedarf auffrischen.
goplaces
394kHilft deinem Agenten, mit Google Places nach Orten zu suchen, Details und Bewertungen abzurufen und Ortsnamen aufzulösen, mit JSON-Ausgabe für Skripte.