analyze_var
Calculate Value-at-Risk and Expected Shortfall for crypto and multi-asset portfolios using real-time volatility data from CoinGecko to assess potential losses at 95% and 99% confidence levels.
Instructions
Value-at-Risk (VaR) and CVaR (Expected Shortfall) at 95% and 99% confidence. Uses real volatility auto-fetched from CoinGecko for known crypto tickers. Returns daily and annualised VaR/CVaR, worst-case dollar loss on $1M AUM, and interpretation. Payment: $0.02 USDC on Tempo chain.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| holdings | Yes | ||
| profile | No | Risk profile — affects rebalance targets and scoring. Default: balanced. | |
| benchmarkReturn | No | Annual benchmark return for Sharpe calculation, e.g. 0.08 = 8%. Default: 0.08. | |
| riskFreeRate | No | Annual risk-free rate for Sortino and VaR excess return, e.g. 0.05 = 5%. Default: 0.05. | |
| rebalanceMethod | No | Portfolio construction method for rebalance recommendations. Default: profile. | |
| marketIndicators | No | Optional macro indicators — improves market regime detection confidence to HIGH when 3+ provided. |
Implementation Reference
- src/analyze/var-cvar.ts:93-112 (handler)The handler function for the `analyze_var` tool, which computes Value at Risk (VaR) and Conditional Value at Risk (CVaR) for a given portfolio.
export function analyzeVaR(portfolio: Portfolio): VaRResult { const { annualMean, annualVol } = portfolioStats(portfolio) // z-scores for 95% and 99% confidence (one-tailed) const Z_95 = 1.6449 const Z_99 = 2.3263 const confidence95 = computeBand(annualMean, annualVol, Z_95, 0.95) const confidence99 = computeBand(annualMean, annualVol, Z_99, 0.99) // Dollar impact on a $1,000,000 AUM position const worstCaseDollarLoss1M = Math.max(0, Math.round(confidence99.annualCVaR * 1_000_000)) return { confidence95, confidence99, worstCaseDollarLoss1M, interpretation: buildInterpretation(confidence95, confidence99, portfolio.profile), } } - src/index.ts:563-570 (registration)Registration of the /analyze/var tool endpoint.
app.post('/analyze/var', validate, charge('0.01'), async (c) => { try { return c.json(withMeta(c, analyzeVaR(c.get('portfolio')))) } catch (err) { console.error(err) return internalError(c) } })