risk-analysis
यह क्या करती है
यह स्किल मापती है कि खराब बाज़ार में पोर्टफ़ोलियो कितना नुकसान उठा सकता है। यह उन निवेशकों और विश्लेषकों के लिए है जिन्हें गिरावट के जोखिम पर साफ़ आँकड़े चाहिए।
कब इस्तेमाल करें
- ✓जब आप जानना चाहें कि खराब दिन या खराब महीने में पोर्टफ़ोलियो कितना गिर सकता है।
- ✓जब आपको किसी रणनीति में अब तक आई सबसे बड़ी चोटी-से-गर्त गिरावट देखनी हो।
- ✓जब आप पोर्टफ़ोलियो को बीते संकटों या सिमुलेट किए बाज़ार पथों पर परखना चाहें।
Skill का लिंक
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/risk-analysis/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे मौजूदा पोर्टफ़ोलियो से खराब दिन में मैं कितना खो सकता हूँ, और सबसे बड़ी गिरावट कितनी थी?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह बीते रिटर्न से वैल्यू एट रिस्क, एक्सपेक्टेड शॉर्टफ़ॉल और अधिकतम ड्रॉडाउन जैसे माप निकालती है। व्यापक परिणाम दिखाने के लिए यह कई संभावित कीमत पथों का सिमुलेशन भी कर सकती है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे 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
अक्सर पूछे जाने वाले सवाल
VaR का क्या मतलब है?
Value at Risk चुने गए विश्वास स्तर पर वह नुकसान का अनुमान है, जिससे ज़्यादातर मामलों में आगे नहीं जाना चाहिए।
नुकसान धनात्मक संख्या में क्यों दिखाए जाते हैं?
स्किल सभी मापों के लिए एक नियम रखती है: नुकसान एक धनात्मक संख्या है, ताकि नतीजों की तुलना आसान हो।
क्या यह बीते संकट का टेस्ट कर सकती है?
हाँ। यह ऐतिहासिक परिदृश्य तनाव परीक्षण करती है, जो पोर्टफ़ोलियो पर बीते बाज़ार झटकों को दोबारा चलाता है।
जानकारी
लेखक का मूल विवरण
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
लोकप्रियता
- GitHub स्टार
- 37k
- रैंकिंग में स्थान
- #7550
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
vibe-trading
37kयह आपके एजेंट को वित्त शोध का पूरा टूलकिट देती है, जिसमें बैकटेस्ट, फ़ैक्टर एनालिसिस, ऑप्शन प्राइसिंग और कई बाज़ारों का डेटा शामिल है।
adr-hshare
37kयह आपके एजेंट को दिखाती है कि कई बाज़ारों में लिस्टेड एक चीनी कंपनी के भाव की तुलना कैसे करें, जैसे अमेरिकी ADR और हॉन्गकॉन्ग शेयर।
akshare
37kयह आपके एजेंट को चीनी और वैश्विक शेयरों, फ़्यूचर्स, फ़ॉरेक्स और आर्थिक संकेतकों का मुफ़्त बाज़ार डेटा लेने देती है, बिना API key के।
alpha-zoo
37kयह आपके एजेंट को बने-बनाए स्टॉक फ़ैक्टरों की लाइब्रेरी देखने और चुने हुए बाज़ार पर उनके पूरे समूह के रिटर्न की भविष्यवाणी की क्षमता जाँचने देती है।
मिलती-जुलती skills
gitcrawl
394kयह आपके एजेंट को GitHub issues और pull requests के सेव आर्काइव में खोजने, मिलते-जुलते मामलों को समूह में रखने और लाइव स्थिति जांचने देती है।
slacrawl
394kयह आपके एजेंट को स्थानीय Slack आर्काइव में संदेश खोजने और गिनने, उसकी ताज़गी जांचने और ज़रूरत पड़ने पर उसे ताज़ा करने देती है।
goplaces
394kयह आपके एजेंट को Google Places से जगहें खोजने, उनका विवरण और समीक्षाएं पाने, और जगह के नाम हल करने में मदद करती है, स्क्रिप्ट के लिए JSON आउटपुट के साथ।