risk-metrics-calculation
Calculate portfolio risk metrics including VaR, CVaR, Sharpe, Sortino, and drawdown analysis. Use when measuring portfolio risk, implementing risk limits, or building risk monitoring systems.
Profile →npx skills add majiayu000/claude-skill-registry --skill risk-metrics-calculation-tringo0108-z-command --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Calculates a wide set of portfolio risk metrics, including VaR (historical, parametric, Cornish-Fisher), CVaR, drawdown analyses (max and duration), and risk-adjusted ratios like Sharpe, Sortino, Calmar, and Omega. It provides both asset-level and portfolio-level tooling, plus rolling and stress-testing capabilities to monitor risk over time and under historical scenarios.
How it works
- Pattern 1: Core Risk Metrics defines a RiskMetrics class that takes a series of returns and computes:
- Volatility (annualized option) and downside_deviation
- Beta against market_returns
- VaR variants: var_historical, var_parametric, var_cornish_fisher
- CVaR via cvar
- Drawdowns analysis (drawdowns, max_drawdown, avg_drawdown, drawdown_duration)
- Risk-adjusted returns: sharpe_ratio, sortino_ratio, calmar_ratio, omega_ratio
- Information and summary outputs
- Pattern 2: Portfolio Risk adds PortfolioRisk class for portfolio-level metrics, including:
- portfolio_return, portfolio_volatility
- marginal_risk_contribution and component_risk
- risk_parity_weights (optimization-based)
- correlation_matrix, diversification_ratio, tracking_error, conditional_correlation
- Pattern 3: Rolling Risk Metrics provides RollingRiskMetrics to compute rolling_volatility, rolling_sharpe, rolling_var, rolling_max_drawdown, rolling_beta, and volatility_regime classifications over a moving window.
- Pattern 4: Stress Testing introduces StressTester with historical_stress_test to evaluate a portfolio against crisis periods using predefined scenarios and crisis data, returning total_return, max_drawdown, worst_day, and volatility for the crisis window.
When to use it
- When measuring portfolio risk
- When implementing risk limits
- When building risk dashboards
- When calculating risk-adjusted returns
- When setting position sizes
- For regulatory reporting
What it can touch
- Uses Python code with numpy, pandas, scipy.stats, and optional scipy.optimize for risk_parity_weights.
- Methods access and operate on returns data (Series or DataFrame) and optional market or benchmark series; no external systems are invoked.
Caveats
- Licensing is MIT; ensure compatibility with your project license.
- Some calculations assume normality for certain VaR variants unless using Cornish-Fisher; results may differ under non-normal distributions.
- Risk_parity_weights uses an optimizer with bounds and equality constraints; convergence depends on data and initial conditions.
- Rolling and stress-test results depend on window size and historical data quality.
# Risk Metrics Calculation Comprehensive risk measurement toolkit for portfolio management, including Value at Risk, Expected Shortfall, and drawdown analysis. ## When to Use This Skill - Measuring portfolio risk - Implementing risk limits - Building risk dashboards - Calculating risk-adjusted returns - Setting position sizes - Regulatory reporting ## Core Concepts ### 1. Risk Metric Categories | Category | Metrics | Use Case | |----------|---------|----------| | **Volatility** | Std Dev, Beta | General risk | | **Tail Risk** | VaR, CVaR | Extreme losses | | **Drawdown** | Max DD, Calmar | Capital preservation | | **Risk-Adjusted** | Sharpe, Sortino | Performance | ### 2. Time Horizons ``` Intraday: Minute/hourly VaR for day traders Daily: Standard risk reporting Weekly: Rebalancing decisions Monthly: Performance attribution Annual: Strategic allocation ``` ## Implementation ### Pattern 1: Core Risk Metrics ```python import numpy as np import pandas as pd from scipy import stats from typing import Dict, Optional, Tuple class RiskMetrics: """Core risk metric calculations.""" def __init__(self, returns: pd.Series, rf_rate: float = 0.02): """ Args: returns: Series of periodic returns
- When to Use This Skill
- Core Concepts
- 1. Risk Metric Categories
- 2. Time Horizons
- Implementation
- Pattern 1: Core Risk Metrics
- Pattern 2: Portfolio Risk
- Pattern 3: Rolling Risk Metrics
- Pattern 4: Stress Testing
- Quick Reference
- Best Practices
- Do's
- Don'ts
- Resources
What does the risk-metrics-calculation skill do?
Calculate portfolio risk metrics including VaR, CVaR, Sharpe, Sortino, and drawdown analysis. Use when measuring portfolio risk, implementing risk limits, or building risk monitoring systems.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill risk-metrics-calculation-tringo0108-z-command --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.