metadata
title: Portfolio Volatility Analyzer
emoji: ๐
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
short_description: Portfolio risk analysis with OCR and LaTeX formulas
๐ 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
- Upload Portfolio Screenshot: Take a screenshot of your portfolio (must show ticker symbols and dollar amounts)
- Edit Portfolio JSON: Review and correct any OCR errors in the JSON editor
- Validate Portfolio: Click "Validate Portfolio" to start analysis
- View Results: See historical data, covariance matrix, and detailed formulas
- 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
# Install dependencies
pip install -r requirements.txt
# Run the app
streamlit run app.py
Docker Build
# Build
docker build -t portfolio-analyzer .
# Run
docker run -p 7860:7860 portfolio-analyzer
Example Portfolio
Test the app with this JSON:
{
"AAPL": 5000,
"GOOGL": 3000,
"MSFT": 2000
}
Notes
- Uses 252 trading days for annualization
- Calculates log returns: ln(P_t / 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