agentleFS
davidromeodavidromeo/tradeblocks-skills/skills/risk/SKILL.md

risk

Skill3 starsChanged 47 days agoMITView on GitHub

Risk analysis for trading strategies including Kelly criterion calculations, tail risk metrics, Monte Carlo projections, stress testing, and drawdown attribution. Use when exploring position sizing, capital allocation, or understanding worst-case characteristics.

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 0 are common, 5 are distinctive, and 11 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ask: "What aspect of risk would you like to explore?"

    line 31
  2. Very specific:

    Call get_position_sizing with the user's capital base.

    line 37
  3. Very specific:

    Call stress_test to see how the portfolio performed during named historical stress scenarios.

    line 61
  4. Very specific:

    Call run_monte_carlo for probabilistic projections:

    line 84
  5. Very specific:

    Call drawdown_attribution to identify what caused the worst drawdown.

    line 102
  6. Very specific:

    Call get_tail_risk for extreme co-movement analysis (requires 2+ strategies).

    line 119
  7. Very specific:

    Call what_if_scaling to explore how allocation changes affect risk metrics.

    line 134
  8. Distinctive:

    Before/after portfolio metrics comparison

    line 143
  9. Very specific:

    Run get_position_sizing with capitalBase: 100000

    line 197
  10. Distinctive:

    Look at joint tail risk matrix for high values

    line 205
  11. Distinctive:

    Check effective factors (closer to 1 = more correlated risk)

    line 206
  12. Very specific:

    Run stress_test for historical named scenarios

    line 211
  13. Very specific:

    Run run_monte_carlo with worst-case injection for probabilistic projection

    line 212
  14. Very specific:

    Run drawdown_attribution to understand what drove the historical worst

    line 213
  15. Very specific:

    Run what_if_scaling with proposed weights

    line 218
  16. Distinctive:

    Check if the change improves risk-adjusted returns or just shifts risk

    line 220

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Risk Analysis

Explore risk characteristics and position sizing metrics for trading strategies.

Prerequisites

  • TradeBlocks MCP server running
  • Block with trade data (10+ trades minimum for meaningful metrics)

Process

Step 1: Understand User Goals

Risk analysis serves different purposes. Ask what the user wants to understand:

GoalPrimary ToolAlso Consider
"What does Kelly suggest?"get_position_sizingMonte Carlo for drawdown context
"What are worst-case scenarios?"run_monte_carlostress_test for named scenarios
"How did I do during COVID/bear markets?"stress_testDrawdown attribution
"What caused my biggest drawdown?"drawdown_attributionTail risk for future risk
"How correlated are my strategies?"get_tail_riskPosition sizing per strategy
"What if I change allocations?"what_if_scalingMarginal contribution

Ask: "What aspect of risk would you like to explore?"

Then use list_blocks to identify the target block.

Step 2: Position Sizing (Kelly Criterion)

Call get_position_sizing with the user's capital base.

Key parameters:

  • capitalBase: Starting capital (required)
  • kellyFraction: "full", "half" (default), or "quarter"
  • maxAllocationPct: Cap per strategy (default: 25%)
  • minTrades: Minimum trades for valid calculation (default: 10)
  • sortBy: Sort by "kelly", "winRate", "payoffRatio", "allocation", "name"
  • useMarginReturns: Use percentage returns based on margin (better for compounding strategies)

Tool returns:

  • Win rate and payoff ratio (inputs to Kelly formula)
  • Raw Kelly percentage (what the formula suggests)
  • Adjusted allocations at full/half/quarter Kelly
  • Per-strategy breakdown if multiple strategies exist
  • Warnings (e.g., "Portfolio Kelly exceeds 25%", "negative Kelly")

Important context for Kelly:

  • Full Kelly is mathematically optimal but assumes perfect knowledge of edge
  • Half Kelly is commonly used to account for estimation uncertainty
  • Negative Kelly indicates historical losses exceeded wins (Kelly formula doesn't apply)

Step 3: Stress Testing

Call stress_test to see how the portfolio performed during named historical stress scenarios.

Key parameters:

  • blockId: Block folder name
  • scenarios: Optional list of specific scenario names (omit for all built-in scenarios)
  • customScenarios: User-defined scenarios with custom date ranges
  • includeEmpty: Include scenarios with no trades (default: false)

Tool returns per scenario:

  • Scenario name and date range
  • Trade count, win rate, net P&L during that period
  • Profit factor and max drawdown

Present as a stress test table:

ScenarioDatesTradesWin RateNet P&LMax DD
..................

Key insight: If a strategy had zero trades during a stress period, it had no exposure — that's important context (either it didn't exist yet, or its filters kept it out).

Step 4: Monte Carlo Projections

Call run_monte_carlo for probabilistic projections:

Key parameters:

  • includeWorstCase: Enable worst-case injection (default: true)
  • worstCasePercentage: Percentage of worst-case trades (default: 5%)
  • worstCaseMode: "pool" (adds to resample pool) or "guarantee" (ensures worst appears)
  • resampleMethod: "trades" (default), "daily", or "percentage" (for compounding)
  • simulationLength: Number of trades/days to project forward
  • normalizeTo1Lot: Normalize for fair comparison across position sizes

Focus on:

  • 5th percentile outcome (valueAtRisk.p5)
  • Probability of profit
  • Mean and median max drawdown
  • Distribution of terminal equity

Step 5: Drawdown Attribution

Call drawdown_attribution to identify what caused the worst drawdown.

Key parameters:

  • blockId: Block folder name
  • strategy: Optional filter
  • topN: Number of top contributors (default: 5)

Tool returns:

  • Drawdown period (peak date to trough date)
  • Peak and trough equity values
  • Per-strategy P&L attribution during the drawdown
  • Percentage contribution to total loss

This answers "which strategies caused the most pain" during the worst period.

Step 6: Tail Risk (Multi-Strategy)

Call get_tail_risk for extreme co-movement analysis (requires 2+ strategies).

Key parameters:

  • tailThreshold: Percentile for "tail" events (default: 0.1 = worst 10%)
  • varianceThreshold: For effective factors calculation (default: 0.8)
  • normalization: "raw", "margin", or "notional"

Tool returns:

  • Joint tail risk matrix (do strategies fail together?)
  • Effective factors (how many independent risk sources exist)
  • Risk level: LOW (<0.3), MODERATE (0.3-0.5), HIGH (>0.5)
  • Copula correlation (statistical dependency structure)

Step 7: What-If Scaling

Call what_if_scaling to explore how allocation changes affect risk metrics.

Key parameters:

  • blockId: Block folder name
  • strategyWeights: Weight per strategy (e.g., {"StrategyA": 0.5, "StrategyB": 1.5})
  • strategies: Multi-strategy mode with per-strategy block source and scale factor
  • showUncapped: Also show results without maxContractsPerTrade ceiling

Tool returns:

  • Before/after portfolio metrics comparison
  • Per-strategy breakdown at new weights
  • Profile-aware: respects contract ceilings from profiles

Common questions this answers:

  • "What if I removed this underperforming strategy?"
  • "What if I doubled my best performer?"
  • "What if I halved everything during high VIX?"

Step 8: Present Findings

Synthesize findings into what the data reveals:

Position Sizing Metrics:

  • Win rate: [value]% | Payoff ratio: [value]
  • Kelly formula suggests: [value]% (based on historical data)
  • At half Kelly: [dollar amount] of [capital base]
  • [Any warnings from the tool]

Stress Test Results:

  • [Worst scenario]: [P&L and drawdown during that period]
  • [Best scenario]: [how the strategy held up]
  • Scenarios with no exposure: [list]

Monte Carlo Projections:

  • 5th percentile return: [value]
  • Probability of profit: [value]%
  • Mean max drawdown: [value]%

Drawdown Attribution:

  • Worst drawdown: [peak] to [trough] ([magnitude])
  • Primary contributor: [strategy] at [percentage] of total loss

Tail Risk (if applicable):

  • Average joint tail risk: [value] ([LOW/MODERATE/HIGH])
  • Effective factors: [value] of [strategy count]
  • [Note any high-risk pairs]

What stands out:

  • [Highlight notable findings]
  • [Surface any warnings from the tools]
  • [Note relationships between metrics]

Present these as insights from the historical data, letting the user decide what fits their situation.

Interpretation References

  • references/kelly-guide.md - Kelly criterion explained
  • references/tail-risk.md - Understanding fat tails

Common Scenarios

"I have $100,000 - what does Kelly suggest?"

  1. Run get_position_sizing with capitalBase: 100000
  2. Review the Kelly percentages and warnings
  3. Surface both raw Kelly and half-Kelly figures
  4. Note that Kelly assumes independent trades and known edge

"Do my strategies fail together?"

  1. Run get_tail_risk
  2. Look at joint tail risk matrix for high values
  3. Check effective factors (closer to 1 = more correlated risk)
  4. High correlation means drawdowns may compound

"What's the worst realistic outcome?"

  1. Run stress_test for historical named scenarios
  2. Run run_monte_carlo with worst-case injection for probabilistic projection
  3. Run drawdown_attribution to understand what drove the historical worst
  4. Combine: stress tests show what happened, Monte Carlo shows what might happen

"Should I change my allocations?"

  1. Run what_if_scaling with proposed weights
  2. Compare before/after Sharpe, drawdown, net P&L
  3. Check if the change improves risk-adjusted returns or just shifts risk

Related Skills

After risk analysis:

  • /tradeblocks:health-check - Full metrics overview
  • /tradeblocks:portfolio - Correlation and diversification analysis
  • /tradeblocks:wfa - Test parameter robustness

Notes

  • Kelly assumes independent trades; real trades may be correlated
  • Historical volatility may underestimate future extremes
  • Monte Carlo resamples history - it can't predict unknown risks
  • Stress tests only cover known historical scenarios
  • Negative Kelly means the formula doesn't apply (no positive edge in historical data)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.