risk-metrics-calculation

Calculate financial risk metrics for assets and portfolios using Python.

38.6k|4.1k|Updated Jul 24, 2025
One-click install
npx skills add https://github.com/wshobson/agents --skill risk-metrics-calculation-wshobson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: risk-metrics-calculation
Source: https://github.com/wshobson/agents/tree/main/plugins/quantitative-trading/skills/risk-metrics-calculation
Command: npx skills add https://github.com/wshobson/agents --skill risk-metrics-calculation-wshobson

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, pandas, scipy, scipy.optimize, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides a comprehensive toolkit for measuring and analyzing various dimensions of financial portfolio risk, enabling better decision-making and risk management.

Core Features & Use Cases

  • Risk Metric Calculation: Compute key metrics like VaR, CVaR, Sharpe Ratio, Sortino Ratio, and drawdown analysis.
  • Portfolio Risk Analysis: Assess portfolio-level risk, including marginal risk contribution and diversification.
  • Rolling Analysis & Stress Testing: Analyze risk over time with rolling windows and simulate performance during historical or hypothetical crises.
  • Use Case: A portfolio manager needs to understand the potential downside of their holdings. They can use this Skill to calculate the 95% VaR, maximum drawdown, and simulate the portfolio's performance during the 2008 financial crisis.

Quick Start

Calculate the 95% historical Value at Risk and the maximum drawdown for the provided daily returns series.

Frequently Asked Questions about risk-metrics-calculation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I calculate Value at Risk and Conditional Value at Risk for a portfolio in Python?

You can calculate Value at Risk (VaR) and Conditional Value at Risk (CVaR) by feeding a daily returns series into this Skill, which leverages NumPy and SciPy to compute historical downside risk metrics for individual assets and portfolios.

What is the best way to perform stress testing and simulate portfolio performance during historical financial crises?

The best way to perform stress testing is to apply historical or hypothetical crisis scenarios directly to your returns data. This Skill simulates portfolio performance during events like the 2008 financial crisis to evaluate downside vulnerability.

How do I compute rolling window Sharpe and Sortino ratios for asset volatility analysis?

To compute rolling window Sharpe and Sortino ratios, this Skill applies moving time windows across your returns series using Pandas, calculating risk-adjusted performance metrics dynamically over time to track changing asset volatility.

Can I calculate risk parity weights and marginal risk contributions using pandas and scipy?

Yes, you can calculate risk parity weights and marginal risk contributions. This Skill uses scipy.optimize to determine asset allocations, ensuring each component contributes equally to the overall portfolio volatility.

Does this portfolio risk analysis approach support maximum drawdown analysis and beta calculation?

Yes, this portfolio risk analysis approach supports maximum drawdown analysis and beta calculation. It computes drawdown metrics to identify peak-to-trough declines and calculates beta to measure asset sensitivity against market benchmarks.