Skip to content
Back to skills

Risk

ASecurity

Decomposes the volatility of a portfolio into the contribution of each position and, with a factor model, of each factor and of specific risk. Use when asked where the risk in a portfolio comes from, which positions or factors drive volatility, what the portfolio's factor exposures are, or which trades would reduce risk most efficiently.

  • 20 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 6, 2026
ai-agentspythonbashapi

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned November 6, 2026

npx -y skills add ruujOnChain/HedgeFund-Skills --skill risk --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Risk?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Risk
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ruujonchain-risk/badge)](https://www.skillsdirectory.com/skills/ruujonchain-risk)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: risk
description: Decomposes the volatility of a portfolio into the contribution of each position and, with a factor model, of each factor and of specific risk. Use when asked where the risk in a portfolio comes from, which positions or factors drive volatility, what the portfolio's factor exposures are, or which trades would reduce risk most efficiently.
license: MIT
compatibility: Requires Python 3.9 or later with numpy and pandas.
metadata:
  owner: research
  version: "1.0"
---

# Factor risk decomposition

Answers one question: where does the risk in this portfolio come from? Every number comes from `scripts/decompose.py`. Never compute volatility or contributions yourself.

## Inputs

- `weights.csv` with columns `asset, weight`. Weights are fractions of capital; shorts are negative.
- One source of risk, in this order of preference:
  1. Factor model: `exposures.csv` (asset rows, factor columns), `factor_cov.csv` (factor by factor), `specific_var.csv` (columns `asset, specific_var`).
  2. Full covariance: `cov.csv` (asset by asset).
  3. Historical returns: `returns.csv` (date column, then one column of simple returns per asset). Use only when no model is available, and say so in the answer.
- Every input must be known as of the analysis date. Do not mix a covariance estimated today with weights from another day without saying so.
- State the units. Covariances are annual unless `--periods-per-year` says otherwise. Returns mode assumes daily data (252).

If the user has not provided weights or a risk source, ask for them. Never invent covariances or exposures.

## Procedure

1. Confirm the analysis date, the weights file, and which risk source is available.
2. Run the decomposition:
   ```bash
   python scripts/decompose.py --weights weights.csv \
     --exposures exposures.csv --factor-cov factor_cov.csv --specific-var specific_var.csv
   ```
   Alternatives: `--cov cov.csv`, or `--returns returns.csv` (add `--periods-per-year 52` for weekly data).
3. Read the JSON. If `passed` is false, report which check failed and stop.
4. Report the total volatility, the largest position contributions, and, in factor mode, the factor and specific split.

## Checks

The script verifies, and the agent reports when any fails:
- The covariance is positive semidefinite.
- Position contributions sum exactly to total volatility.
- In factor mode, factor plus specific contributions sum exactly to total volatility.

## Output

JSON with `results.total_volatility`, `results.positions` (weight, marginal risk, contribution, share), and in factor mode `results.factors`, `results.factor_total`, `results.specific_total`, plus `checks` and `passed`. Shares sum to one; a negative share means the position hedges the rest of the book.

## Explaining the result

- Lead with total volatility and the share explained by the top three positions.
- Contribution equals weight times marginal risk. A position with high marginal risk is where a small trade changes total risk most; a negative marginal risk means adding to that position lowers total risk.
- In factor mode, say how much risk is systematic versus specific, and name the factor with the largest share.
- Volatility is a forecast from the supplied model, not an observed outcome. Name the model or estimation window used.

For the mathematics and conventions, see [references/methodology.md](references/methodology.md).

Files in this skill

  • SKILL.md3.3 KB
  • references/methodology.md1.7 KB
  • scripts/decompose.py8.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.