Assessor de Rebalanceamento de Portfólio MCP
Keshetti-Nikhil/portfolio-rebalancing-advisor-mcp-server
Rebalanceamento de portfólio otimizado para impostos com benchmarks de 400 cenários
Ver no GitHubServidor MCP em Python que fornece ferramentas de rebalanceamento de portfólio com análise comparativa de 400 cenários de mercado, mostrando que estratégias conscientes de impostos superam o rebalanceamento calendário em riqueza líquida após impostos. Integra simulações determinísticas offline com métricas de risco e impacto fiscal.
Instalação
npx convez-ai Keshetti-Nikhil/portfolio-rebalancing-advisor-mcp-server1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.
Métricas
Casos de uso
- Análise comparativa de estratégias de rebalanceamento (calendário, threshold, tax-aware)
- Estimativa de impacto fiscal em operações de portfólio antes da execução
- Decisões de política de rebalanceamento baseadas em riqueza líquida, não tracking error
- Monitoramento de drift de ativos e detecção de violação de bandas de tolerância
Veredito

MCP bem construído que desafia sabedoria convencional com evidência quantitativa: rebalanceamento calendário (mais apertado) prejudica riqueza líquida por custo de impostos, enquanto estratégias conscientes de impostos com bandas ganham em Sharpe ajustado. Altamente relevante para assessores financeiros e construtores de sistemas de investimento que usem Claude.
README
A tradução para o português deste README ainda está na fila.
portfolio-rebalancing-advisor-mcp-server
A Model Context Protocol server, in Python, that gives an LLM five portfolio rebalancing tools, plus a multi-period market benchmark that scores four rebalancing strategies on the metric that actually matters to an investor: after-tax terminal wealth. 400 market scenarios x 120 monthly periods x 6 assets. Deterministic, offline, JSON-RPC over stdio.
The challenge
The textbook advice is "rebalance to your target so you do not drift". But every rebalance sells appreciated assets, which realises capital gains, which are taxed, which permanently leaves the portfolio. So the strategy that tracks the target most tightly, calendar rebalancing, is also the one that bleeds the most tax. The question this bench answers is whether tight tracking is worth its tax cost, and the answer is no.
Use case
Use it to reason about rebalancing policy and as a worked MCP server: the tools let an LLM inspect drift, propose trades under a chosen policy, and estimate the tax impact before recommending an action.
MCP tools
| Tool | Description |
|---|---|
get_portfolio | Holdings, target weights, and cost basis |
compute_drift | Per-asset deviation from target and band breach |
propose_rebalance | Trades to rebalance under a chosen strategy |
tax_impact | Estimated realised-gains tax of a full rebalance |
risk_metrics | Concentration (max weight, Herfindahl, effective assets) |
Headline result
400 scenarios · 120 months · 6 assets · 4% band · 20% gains tax · 10 bps cost.
| Strategy | Net wealth | Tracking error | Annual turnover | Tax drag | Net Sharpe | Max weight |
|---|---|---|---|---|---|---|
| no_rebalance | 2.196 | 0.160 | 0.000 | 0.000 | 0.895 | 0.388 |
| calendar | 1.890 | 0.020 | 0.222 | 0.142 | 0.878 | 0.197 |
| threshold | 1.978 | 0.040 | 0.071 | 0.083 | 0.930 | 0.223 |
| tax_aware | 2.010 | 0.047 | 0.044 | 0.066 | 0.942 | 0.225 |
- Calendar rebalancing minimises tracking error (0.020) and is the worst for after-tax wealth (1.890). Its 0.142 tax drag, the highest of any strategy, costs more than the tracking precision is worth. Tight tracking is not the goal.
- No-rebalance has the highest raw wealth (2.196) but at a real cost: it lets the high-return asset balloon to 0.39, nearly double its 0.167 target weight, which is concentration risk an investor did not choose.
- Tax-aware banding wins on a risk-adjusted, after-tax basis (Sharpe 0.942, net wealth 2.010) by rebalancing only to the edge of the tolerance band, which cuts turnover and the gains it realises roughly in half versus calendar.
- The ranking flips depending on the metric: calendar wins tracking error, no-rebalance wins raw wealth, tax-aware wins Sharpe. Choosing the strategy means choosing the metric, and tracking error is the wrong one.
Run it as an MCP server
make install
make serve # or: uv run pra-mcp
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"portfolio-rebalancing-advisor": {
"command": "uv",
"args": ["--project", "/abs/path/to/portfolio-rebalancing-advisor-mcp-server", "run", "pra-mcp"]
}
}
}
Smoke test:
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | uv run pra-mcp
Chart gallery
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
Test pyramid
/\ end-to-end + strategy orderings (test_runner)
/ \
/----\ MCP protocol: init/list/call/errors (test_mcp)
/ \
/--------\ market generation + portfolio sim (test_market, test_portfolio)
/__________\ 16 tests total
Quickstart
make test # 16 tests
make bench-fast # 100 scenarios
make bench # full 400-scenario run
What is in the repo
src/pra/
data/market.py deterministic multi-asset return simulator (the fixture)
models/portfolio.py simulation with realised-gain taxes + transaction costs
bench/ + runner.py net wealth, tracking error, turnover, tax drag, Sharpe
mcp/server.py JSON-RPC MCP protocol
mcp/tools.py the five advisor tools
viz/charts.py six charts incl. wealth-vs-tracking-error trade-off
cli/main.py `pra info | bench | serve`
References
- Anthropic (2024). Model Context Protocol Specification.
- Markowitz, H. (1952). Portfolio Selection. Journal of Finance.
- Jaconetti, C., Kinniry, F. & Zilbering, Y. (2010). Best Practices for Portfolio Rebalancing. Vanguard.
- Arnott, R. & Lovell, R. (1993). Rebalancing: Why? When? How Often? Journal of Investing.
- Daryanani, G. (2008). Opportunistic Rebalancing. Journal of Financial Planning.
License
MIT.





