agentleFS
qunyou-agentqunyou-agent/finance-skills/skills/trading/portfolio-risk/SKILL.md

portfolio-risk

Skill4 starsChanged 4 months agoMITView on GitHub

Analyzes portfolio risk and performance metrics. Computes Value at Risk (VaR), Sharpe ratio, Sortino ratio, beta, correlation matrices, drawdown analysis, and position sizing recommendations. Trigger when the user requests risk analysis, portfolio optimization, or performance attribution.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Portfolio Risk

Analyzes portfolio risk and recommends position sizing and diversification.

Real Code Reference

  • tradinglearn/backtest/backtester.py — Backtester._calculate_performance() computes Sharpe, max drawdown, win rate, total return, CAGR
  • tradinglearn/utils/parameter_optimizer.py — plot_optimization_results() heatmaps: return, Sharpe, drawdown, win rate
  • tradinglearn/pytdx2/backtest.py — BacktestEngine tracks per-trade P&L for risk analysis

Risk Metrics

  • VaR: historical simulation, parametric, Monte Carlo
  • CVaR (Expected Shortfall): average loss beyond VaR
  • Maximum Drawdown: peak-to-trough with recovery duration
  • Volatility: annualized std of returns

Performance Metrics

  • Sharpe Ratio: (R - Rf) / sigma
  • Sortino Ratio: downside-only volatility
  • Calmar Ratio: annual return / max drawdown
  • Information Ratio: active return / tracking error

Portfolio Analysis

  • Correlation matrix between holdings
  • Beta to market benchmark
  • Position concentration (Herfindahl index)
  • Risk parity weights

Usage

from backtest.backtester import Backtester

bt = Backtester(initial_capital=100000.0)
bt.run_backtest(data, MyStrategy, params)
perf = bt.get_performance()
# {'total_return': 0.15, 'annual_return': 0.12, 'sharpe_ratio': 1.2,
#  'max_drawdown': -0.08, 'win_rate': 0.55, 'total_trades': 42}
portfolio = bt.get_portfolio()
# DataFrame with: portfolio_value, position, cash, returns

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.