# QREP API - Compare Securities (QuantStats)

Open MCP + REST API that compares up to 6 securities against a benchmark and returns 81 QuantStats metrics per symbol - CAGR, Sharpe, Sortino, Max Drawdown, volatility and more. Powered by the original QuantStats library by Ran Aroussi (also the creator of yfinance). Built for AI agents first: the compare / MCP endpoint needs no key, and every page here has a Copy-as-Markdown button so you can hand it straight to your agent.

Kind: REST / HTTP API, MCP Server (AI agents), Analytics API
Base URL: https://qrep-api.tigzig.com
Docs: https://qrep-api.tigzig.com/docs  ·  OpenAPI: https://qrep-api.tigzig.com/openapi.json
Full page: https://www.tigzig.com/apis/qrep

## Overview

QREP compares up to 6 securities against a benchmark (default SPY) and returns 81 QuantStats metrics per symbol - CAGR, Sharpe, Sortino, Max Drawdown, volatility and more. Powered by the original QuantStats library by Ran Aroussi. Same engine behind the QREP app (https://qrep.tigzig.com).

AI agents: the compare tool is open (no auth) at https://qrep-api.tigzig.com/mcp/compare and via the MCP server below. Listed in the RFC 9727 catalog at https://api.tigzig.com/.well-known/api-catalog ; OpenAPI 3.1 at https://qrep-api.tigzig.com/openapi.json .

Two access shapes over the same backend:
- MCP (open): the compare tool at /mcp/compare + the MCP transports need no key. For AI agents.
- REST + Swagger: the /qpulse/* endpoints (analysis, compare, portfolio, HTML report + CSV) are API-key protected for heavier report generation.

Two QuantStats versions exist: this is the newer one on the original ranaroussi/quantstats. The older QRep Portfolio Profiling server runs the QuantStats-Lumi fork.

## MCP Server (for AI agents)

Connect an AI agent directly and let it compare securities. No auth. Three transports:
- https://qrep-api.tigzig.com/v1/mcp/http - Streamable HTTP (recommended; MCP 2025-03-26).
- https://qrep-api.tigzig.com/v1/mcp/sse - SSE (legacy fallback).
- https://qrep-api.tigzig.com/mcp - original SSE endpoint (back-compat).

Tool: mcp_compare_securities - compare up to 6 symbols vs a benchmark, 81 QuantStats metrics each.
Params: symbols "AAPL,MSFT,GOOG" (max 6), benchmark "SPY" (default), start_date/end_date (YYYY-MM-DD), risk_free_rate (decimal, optional).

Example prompt: "Compare AAPL, MSFT and GOOG against SPY from 2020-01-01 to 2025-12-31."
Add to Claude.ai: Settings -> Connectors -> Add custom connector -> paste the Streamable HTTP URL (fall back to SSE) -> approve. Same URLs work for Cursor, n8n, any MCP client.

## How it works

- FastAPI backend + fastapi-mcp (exposes FastAPI endpoints as MCP tools).
- MCP compare endpoint is a GET at /mcp/compare - no API key.
- Metrics via the original ranaroussi/quantstats library; prices from Yahoo Finance via yfinance (stocks, ETFs, metals, crypto).
- Rate limited per IP with concurrency controls; deployed on Coolify (Hetzner) behind Cloudflare.

## Build your own (open source)

Clone and run your own:
1. Clone https://github.com/amararun/qrep-backend-fastapi
2. pip install -r requirements.txt
3. Set env vars (.env.example): QPULSE_API_KEY for /qpulse/*, BASE_URL, RATE_LIMIT.
4. uvicorn main:app --host 0.0.0.0 --port 8000 - MCP at http://localhost:8000/mcp

Self-hosting a public MCP server is your responsibility for security - a public endpoint needs edge rate limiting, abuse detection, secret hygiene. Full checklist: https://www.tigzig.com/security

## Rate limits

Per IP: Compare / MCP 20 req/min per IP (100/min global). The heavier /qpulse/* report endpoints have their own limits and require an API key. On the limit you get a 429; back off and retry.

## API Endpoints (REST / HTTP)

Base URL: `https://qrep-api.tigzig.com`

### GET /mcp/compare
Mcp Compare
Params:
  - `symbols` (query, required): Comma-separated Yahoo Finance ticker symbols, max 6 (e.g. AAPL,MSFT,GOOG)
  - `benchmark` (query): Benchmark symbol. Can be any valid Yahoo Finance ticker.
  - `start_date` (query, required): Start date YYYY-MM-DD. Should be at least 6 months before end_date for meaningful analysis.
  - `end_date` (query, required): End date YYYY-MM-DD. Must not be in the future.
  - `risk_free_rate` (query): Risk-free rate as decimal (e.g. 0.045 for 4.5%). Used in Sharpe, Sortino, Treynor, and other risk-adjusted calculations.
Example: curl "https://qrep-api.tigzig.com/mcp/compare"
### POST /qpulse/analyze
Qpulse Analyze
Params:
  - `X-API-Key` (header): 
Example: curl "https://qrep-api.tigzig.com/qpulse/analyze"
### GET /qpulse/analyze
Qpulse Analyze Get
Params:
  - `symbol` (query, required): Stock symbol
  - `benchmark` (query): Benchmark symbol
  - `start_date` (query, required): Start date (YYYY-MM-DD)
  - `end_date` (query, required): End date (YYYY-MM-DD)
  - `risk_free_rate` (query): Risk-free rate as decimal
  - `X-API-Key` (header): 
Example: curl "https://qrep-api.tigzig.com/qpulse/analyze"
### POST /qpulse/compare
Qpulse Compare
Params:
  - `X-API-Key` (header): 
Example: curl "https://qrep-api.tigzig.com/qpulse/compare"
### POST /qpulse/compare/export
Export Comparison
Params:
  - `X-API-Key` (header): 
Example: curl "https://qrep-api.tigzig.com/qpulse/compare/export"
### POST /qpulse/portfolio
Portfolio Compare
Params:
  - `X-API-Key` (header): 
Example: curl "https://qrep-api.tigzig.com/qpulse/portfolio"
