# MCP Server: QRep Portfolio Profiling (QuantStats)

FastAPI + MCP server for portfolio performance analysis using quantstats-lumi (Lumiwealth's fork with bug fixes). Generates comprehensive HTML reports with risk-return metrics, rolling statistics, and benchmark comparison.

## Links
- App: https://rbicc.net/mcp-server-quantstats
- Docs: https://tigzig.com/app-documentation/mcp-server-quantstats.html
- GitHub: https://github.com/amararun/shared-quantstats
- Live API: https://quantstats.hosting.tigzig.com
- MCP Endpoint: https://quantstats.hosting.tigzig.com/mcp
- API Docs: https://quantstats.hosting.tigzig.com/docs

## Tags
mcp-servers, portfolio-analysis, quantstats, fastapi

## Architecture

```
Web UI / API Client / MCP Client → FastAPI Server → Yahoo Finance (yfinance)
                                                  → quantstats-lumi (analysis)
                                                  → HTML Report Generation
```

Uses quantstats-lumi, the Lumiwealth fork of QuantStats with important bug fixes and API compatibility.

### API Endpoints
- `GET /analyze` - Portfolio analysis (params: symbols, benchmark, start_date, end_date, risk_free_rate)
- `POST /mcp` - MCP endpoint for AI/LLM clients
- `GET /` - Web interface (Flask frontend)

### Response
Returns URL to generated HTML report with: Sharpe/Sortino ratios, max drawdown, VaR, rolling statistics, correlations, return distributions, benchmark comparison.

### Date Processing
- Yahoo Finance downloads adjusted close prices
- Returns calculated via pct_change().dropna() (loses first day)
- QuantStats aligns dates, skipping initial zero returns
- Expect 1-2 day shift from input dates (normal behavior)
- Uses 365 days/year for annualization (not 252 trading days)

### Environment Variables
```
IS_LOCAL_DEVELOPMENT=1
BASE_URL_FOR_REPORTS=https://your-domain.com/
```

### Dependencies
FastAPI, fastapi-mcp, quantstats-lumi, yfinance, pandas, numpy, matplotlib, Jinja2, httpx

## Setup

```bash
git clone https://github.com/amararun/shared-quantstats.git
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000
```

## Example

```
GET /analyze?symbols=AAPL&benchmark=^GSPC&start_date=2023-01-01&end_date=2024-01-01&risk_free_rate=5.0
```
