Portfolio Rotation MCP Server

Portfolio Rotation MCP Server

MCP server for portfolio rotation analysis. Score holdings and candidates across 5 dimensions, identify optimal swaps, validate with risk checks and backtests.

Category
访问服务器

README

Portfolio Rotation MCP Server

PyPI Python

MCP server for portfolio rotation analysis. Score holdings and candidates across 5 dimensions, identify optimal swaps, validate with risk checks and backtests.

Works with any MCP client: Claude Desktop, ChatGPT, Gemini, LangChain, Cursor, Windsurf, VS Code, Ollama clients, and more.

What It Does

You give it a portfolio and candidate tickers. It returns:

ROTATION SCORECARD (GARP Style)
Ticker | Thesis | Valuation | Momentum | Catalyst | Technical | Composite | Action
META   |   75   |    80     |    78    |    85    |    74     |   78.4    | Strong Buy
AVGO   |   70   |    72     |    75    |    70    |    80     |   73.1    | Buy
AAPL   |   70   |    65     |    62    |    60    |    68     |   65.5    | Hold
MSFT   |   65   |    60     |    58    |    55    |    62     |   60.2    | Hold
JPM    |   50   |    55     |    45    |    40    |    42     |   47.4    | Watch

SWAP RECOMMENDATIONS
Sell JPM (47.4) → Buy META (78.4) | Delta: +31.0 | Strong Swap
Sell JPM (47.4) → Buy AVGO (73.1) | Delta: +25.7 | Strong Swap

RISK FLAGS
⚠️ Technology sector: 35% (>30% limit)

BACKTEST (2y)
Strategy: +42.3% | Benchmark (SPY): +28.1% | Sharpe: 1.24 | Max Drawdown: -14.2%

Quick Start

# Install from PyPI
pip install portfolio-rotation-mcp

# Or run directly (no install needed)
uvx portfolio-rotation-mcp

# Set API key (optional -- falls back to yfinance without it)
export FINANCIAL_DATASETS_API_KEY=your-key

Prerequisites

  • Python >= 3.10
  • Optional: financial-datasets.ai API key for premium data (without it, prices come from yfinance and financial statements are unavailable)

11 Tools

Tool Description
fetch_prices Historical OHLCV prices (API + yfinance fallback)
fetch_financials Income/balance/cashflow statements
fetch_ff_factors Fama-French 5-factor + momentum data
score_tickers 5-dimension scoring (auto + manual)
analyze_risk Concentration, correlation, volatility
compare_swaps Pairwise swap recommendations (delta >= 15)
run_backtest Historical strategy simulation
stress_test Scenario replay, Monte Carlo, factor decomposition
compute_attribution Trade attribution and swap alpha
run_pipeline Full 6-stage rotation analysis
get_skill Retrieve domain knowledge (scoring rules, swap logic, risk thresholds)

Platform Setup

Claude Desktop

Add to your config file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/claude/claude_desktop_config.json
{
  "mcpServers": {
    "portfolio-rotation": {
      "command": "uvx",
      "args": ["portfolio-rotation-mcp"],
      "env": {
        "FINANCIAL_DATASETS_API_KEY": "your-key"
      }
    }
  }
}

Then in Claude Desktop, just say:

My portfolio is AAPL 20%, MSFT 15%, JPM 10%. Evaluate META and AVGO as swap candidates.

Claude will automatically call the MCP tools.

Claude Code (CLI)

claude mcp add portfolio-rotation -- uvx portfolio-rotation-mcp

Cursor / Windsurf / VS Code

Add to your MCP settings (.cursor/mcp.json, .windsurf/mcp.json, or VS Code MCP config):

{
  "mcpServers": {
    "portfolio-rotation": {
      "command": "uvx",
      "args": ["portfolio-rotation-mcp"],
      "env": {
        "FINANCIAL_DATASETS_API_KEY": "your-key"
      }
    }
  }
}

LangChain (any model: DeepSeek, GPT, Llama, etc.)

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI

# Use any model -- DeepSeek, GPT, Llama, etc.
llm = ChatOpenAI(
    model="deepseek-chat",  # or "gpt-4o", etc.
    base_url="https://api.deepseek.com/v1",
    api_key="sk-...",
)

async with MultiServerMCPClient({
    "portfolio-rotation": {
        "command": "uvx",
        "args": ["portfolio-rotation-mcp"],
        "env": {"FINANCIAL_DATASETS_API_KEY": "your-key"},
    }
}) as client:
    tools = client.get_tools()
    # Create agent with tools and invoke

OpenAI Agents SDK

from agents import Agent
from agents.mcp import MCPServerStdio

async with MCPServerStdio(
    command="uvx",
    args=["portfolio-rotation-mcp"],
) as server:
    tools = await server.list_tools()
    agent = Agent(name="Rotation Analyst", tools=tools)

Ollama + Continue / LibreChat

Configure in the MCP settings of your Ollama frontend:

{
  "command": "uvx",
  "args": ["portfolio-rotation-mcp"],
  "env": {
    "FINANCIAL_DATASETS_API_KEY": "your-key"
  }
}

Usage Examples

Quick: Full Pipeline (one tool call)

Ask your AI agent:

Analyze my portfolio: AAPL 20% (Technology), MSFT 15% (Technology), JPM 10% (Financials). Candidates: META, AVGO. Use GARP style.

The agent will call run_pipeline which runs all 6 stages automatically: data fetch -> scoring -> risk check -> swap comparison -> backtest -> report.

Targeted: Score Specific Tickers

Score AAPL, META, and AVGO. My thesis score for META is 80 and catalyst is 85.

The agent will call fetch_prices, then score_tickers with your manual overrides.

Deep Dive: Stress Test

Stress test my portfolio under a 2008-style crash scenario. Include Monte Carlo simulation.

The agent will call fetch_prices, fetch_ff_factors, then stress_test.

Post-Trade: Attribution

I sold INTC and bought NVDA on Jan 15 at $120. How did that swap perform?

The agent will call fetch_prices, then compute_attribution to measure swap alpha.

Development

# Clone and install in development mode
git clone git@github.com:mothanaprime/Rebalance-MCP.git
cd Rebalance-MCP
pip install -e .

# Run the server
portfolio-rotation-mcp

# Test with MCP inspector
mcp dev src/portfolio_rotation/server.py

Scoring Framework

5 dimensions, 0-100 each, weighted by investment style:

Dimension GARP Weight Auto?
Thesis Integrity 25% Manual (via overrides)
Valuation Attractiveness 25% Auto (needs financials)
Fundamental Momentum 20% Auto (from prices)
Catalyst Proximity 15% Manual (via overrides)
Technical Trend 15% Auto (MA/RSI/relative strength)

Swap threshold: Buy Score - Hold Score >= 15

Style presets: garp (default), value, growth, momentum, event_driven -- each has different dimension weights.

See docs/scoring-framework.md for full details.

Agent Prompt

See docs/agent-prompt.md for a model-agnostic system prompt you can use to configure any AI agent for rotation analysis.

Environment Variables

Variable Required Default Description
FINANCIAL_DATASETS_API_KEY No -- API key for financial-datasets.ai. Without it, prices fall back to yfinance and financials are unavailable.
PORTFOLIO_ROTATION_SOURCE No auto Data source: auto (API first, yfinance fallback), api, financial-datasets, or yfinance. Can be overridden per-call.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选