# QRep - Security Analytics Reports

Portfolio analytics dashboard powered by QuantStats. Compare up to 6 securities side by side with 23 metric blocks, 70+ KPIs, interactive technical analysis charts, and exportable HTML/PDF reports.

## Links
- App: https://qrep.tigzig.com
- Docs: https://tigzig.com/app-documentation/qrep.html
- GitHub (Frontend): https://github.com/amararun/qrep-security-analytics
- GitHub (Backend): https://github.com/amararun/qrep-backend-fastapi

## Tags
portfolio-analysis, quantstats, technical-analysis, react

## Architecture

```
React Frontend (Vercel) → Vercel Serverless Proxies → FastAPI Backend (Coolify/Hetzner)
├── qpulse-proxy: Analytics requests (compare, analyze, portfolio, export, search)
├── yf-proxy: Yahoo Finance price data for charts
└── yf-search: Yahoo Finance symbol search
```

- Frontend: React 18 + TypeScript + Vite + Tailwind CSS, deployed on Vercel
- Backend: Python FastAPI + QuantStats 0.0.81 + yfinance, deployed on Coolify (Docker on Hetzner)
- Rate limiting via Upstash Redis
- API keys injected server-side, never exposed to browser

## What It Does

### Multi-Security Compare Dashboard
Enter up to 6 symbols (stocks, ETFs, crypto, commodities) with a benchmark and date range. Get a full dashboard with 23 metric blocks organized into categories:

**Returns & Performance** - CAGR, Cumulative Return, MTD, YTD, 3M/6M/1Y/3Y/5Y/10Y returns, best/worst year. Color-coded bar charts for visual comparison.

**Performance Ratios** - Sharpe, Sortino, Calmar, Omega, Payoff, Profit Factor. Tabbed chart views for ratio pairs.

**Drawdowns & Risk** - Max Drawdown, Annualized Volatility, VaR, CVaR, Average Drawdown, Longest Drawdown Days, Skew, Kurtosis. Time-series drawdown chart.

**Trading Statistics** - Win Days/Month/Year %, Best/Worst Day/Month, Average Up/Down Month, Max Consecutive Wins/Losses.

**Benchmark Comparison** - Alpha, Beta, R-Squared, Information Ratio, Treynor Ratio.

**Recovery & Tail Risk** - Recovery Factor, Ulcer Index, Serenity Index, Tail Ratio, Common Sense Ratio, Outlier Win/Loss Ratio, Risk of Ruin, Kelly Criterion.

**Advanced Ratios** - Probabilistic Sharpe, Smart Sharpe, Smart Sortino, Gain/Pain Ratio, CPC Index, Correlation.

### Price Charts & Technical Indicators
Each security gets an interactive chart with 10 configurable technical overlays:
- EMA (12, 26, 50), SMA (50, 200), Bollinger Bands
- MACD (12, 26, 9), RSI (14), ROC (12), TRIX (15), Historical Volatility (20)
- All indicators validated against Python implementations with exact numerical match

### Tearsheet Page
Single-security deep dive generating a full QuantStats HTML report with 90+ KPIs and 10+ charts including cumulative returns, drawdowns, monthly returns heatmap, distribution plots, rolling statistics.

### Export
- HTML Report (full dashboard as image in HTML)
- PDF Report (single-page PDF)
- Prices CSV (adjusted close for all securities)
- Metrics CSV (all computed metrics, transposed)

## Advanced Settings
- Risk-Free Rate (for Sharpe, Sortino, Treynor)
- Omega Threshold (minimum acceptable return)
- VaR/CVaR Confidence (90%, 95%, 99%)
- Tail Ratio Cutoff (percentile)

## Data Flow
1. User enters symbols and date range
2. Frontend sends request to Vercel serverless proxy
3. Proxy authenticates with backend API key, forwards to FastAPI
4. Backend fetches prices from Yahoo Finance via yfinance
5. QuantStats computes all metrics from daily returns
6. Results return through proxy to frontend
7. Frontend renders dashboard blocks and charts
8. Technical indicators computed client-side from price data

## Tech Stack
- Frontend: React 18, TypeScript, Vite, Tailwind CSS, Radix UI, Recharts, Lucide Icons
- Export: html2canvas, jsPDF
- API Proxy: Vercel Serverless Functions (Node.js)
- Rate Limiting: Upstash Redis
- Backend: Python FastAPI, QuantStats 0.0.81, yfinance
- Frontend Hosting: Vercel
- Backend Hosting: Coolify (Docker on Hetzner)
- DNS & CDN: Cloudflare

## Setup
No local setup needed - visit https://qrep.tigzig.com to use.

For development:
- Frontend: `npm install && npm run dev` (port 3300)
- Backend: Python FastAPI with QuantStats 0.0.81
- Repos: amararun/qrep-security-analytics (frontend), amararun/qrep-backend-fastapi (backend)
