CoolFace
Apppublic

ResearchEngineering/financial_analyst

sourceHugging Faceupdated 8mo agoView on Hugging Face
1likes
App README

๐Ÿ“Š Portfolio Volatility Analyzer

Analyze your investment portfolio risk using Modern Portfolio Theory with OCR, interactive visualizations, and beautiful mathematical formulas.

Features

  • โ€”๐Ÿ“ธ OCR Portfolio Parsing: Upload screenshots of your portfolio and automatically extract tickers and amounts
  • โ€”โœ๏ธ Editable JSON: Correct OCR errors with an intuitive JSON editor
  • โ€”๐Ÿ“ˆ Historical Data: Automatically fetch 1 year of price data from Yahoo Finance
  • โ€”๐Ÿงฎ Full Calculations:
  • โ€”Portfolio weights
  • โ€”Log returns
  • โ€”Covariance matrix
  • โ€”Portfolio variance and volatility
  • โ€”๐Ÿ“ Beautiful LaTeX Formulas: See every calculation step with symbolic and numerical formulas
  • โ€”๐Ÿ“Š Detailed Variance Expansion: Step-by-step breakdown showing how each asset contributes to portfolio risk
  • โ€”๐ŸŽš๏ธ Interactive Rebalancing: Adjust portfolio amounts with sliders and see volatility update in real-time

How to Use

  1. 1.Upload Portfolio Screenshot: Take a screenshot of your portfolio (must show ticker symbols and dollar amounts)
  2. 2.Edit Portfolio JSON: Review and correct any OCR errors in the JSON editor
  3. 3.Validate Portfolio: Click "Validate Portfolio" to start analysis
  4. 4.View Results: See historical data, covariance matrix, and detailed formulas
  5. 5.Rebalance: Use interactive sliders to adjust positions and see impact on volatility

Technical Details

Formula Highlights

Portfolio Variance:

ฯƒยฒ_p = w^T ร— ฮฃ ร— w

Where:

  • โ€”w = vector of portfolio weights
  • โ€”ฮฃ = covariance matrix (annualized)

Portfolio Volatility:

ฯƒ_p = โˆš(ฯƒยฒ_p)

Architecture

  • โ€”Frontend: Streamlit
  • โ€”OCR: Tesseract (pytesseract)
  • โ€”Financial Data: yfinance (Yahoo Finance)
  • โ€”Math: NumPy, Pandas, SymPy
  • โ€”Deployment: Docker on Hugging Face Spaces

Local Development

Prerequisites

  • โ€”Python 3.11+
  • โ€”Tesseract OCR installed

Setup

bash
# Install dependencies
pip install -r requirements.txt

# Run the app
streamlit run app.py

Docker Build

bash
# Build
docker build -t portfolio-analyzer .

# Run
docker run -p 7860:7860 portfolio-analyzer

Example Portfolio

Test the app with this JSON:

json
{
  "AAPL": 5000,
  "GOOGL": 3000,
  "MSFT": 2000
}

Notes

  • โ€”Uses 252 trading days for annualization
  • โ€”Calculates log returns: ln(Pt / P{t-1})
  • โ€”Smart truncation for portfolios with 4+ tickers
  • โ€”1-hour cache for historical data to reduce API calls

Built With

  • โ€”Modern Portfolio Theory
  • โ€”LaTeX mathematical notation
  • โ€”Real-time financial data

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference