risk_parity
Calculate portfolio weights using Inverse Volatility to achieve balanced risk allocation across assets.
Instructions
Calculates weights based on Inverse Volatility (Naive Risk Parity).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tickers | Yes |
Implementation Reference
- tools/portfolio_optimizer.py:120-134 (handler)The core handler function for the 'risk_parity' tool. Computes naive risk parity weights using inverse volatility from 1 year of daily returns data fetched via yfinance.def risk_parity(tickers: List[str]) -> str: """ Calculates weights based on Inverse Volatility (Naive Risk Parity). """ data = yf.download(tickers, period="1y", progress=False)['Close'] returns = data.pct_change().dropna() volatility = returns.std() inv_vol = 1 / volatility weights = inv_vol / inv_vol.sum() w_dict = weights.to_dict() w_dict = {k: float(f"{v:.4f}") for k, v in w_dict.items()} return f"Risk Parity Weights: {w_dict}"
- server.py:395-398 (registration)Registers the risk_parity tool in the main MCP server (FastMCP) under the 'Portfolio Optimization' category using the register_tools helper.register_tools( [mean_variance_optimize, risk_parity], "Portfolio Optimization" )
- app.py:292-292 (registration)Includes the risk_parity tool in the tools_map dictionary used for organizing and exposing tools in the Gradio UI toolbox (with mcp_server=True)."Portfolio Opt": [mean_variance_optimize, risk_parity],