🔗 Live Demo: https://portfolio-analyzer-rl.streamlit.app
A Python-based command-line tool for analyzing investment portfolios using live market data.
The tool computes portfolio allocation, unrealized profit/loss, benchmark performance, and risk-adjusted returns.
This project was built to explore how financial advisors and portfolio managers evaluate performance relative to the market.
- Ingests portfolio holdings from a CSV file
- Pulls live and historical market prices using Yahoo Finance
- Computes:
- Market value per holding
- Portfolio allocation percentages
- Cost basis and unrealized profit/loss
- Compares portfolio performance against a market benchmark (e.g., S&P 500 via SPY or VOO)
- Calculates risk-adjusted performance using the Sharpe ratio
- Fully configurable via command-line flags
- Python
- pandas
- yfinance
- argparse (CLI interface)
Holdings are provided via a CSV file with the following columns:
ticker,shares,avg_cost AAPL,5,150 MSFT,2,310 VOO,1,410
Run the analyzer from the project root:
python src/analyze.py
Common CLI Options:
python src/analyze.py --sort pl
python src/analyze.py --top 3
python src/analyze.py --benchmark SPY --period 1y
python src/analyze.py --risk_free 0.02
Available Flags:
• --file : Path to holdings CSV
• --sort : Sort output by allocation, unrealized P/L, or ticker
• --top : Show only the top N holdings
• --benchmark : Benchmark ticker (default: VOO)
• --period : Lookback period (e.g., 6mo, 1y, 2y)
• --risk_free : Annual risk-free rate (default: 0.0)
Sample Output:
Portfolio return (1y): +11.77%
SPY return (1y): +17.38%
Relative performance: -5.61%
Portfolio Sharpe (1y): 0.55
SPY Sharpe (1y): 0.82
ASSUMPTIONS AND LIMITATIONS:
• Portfolio returns are calculated as a weighted average of individual holding returns using current allocation weights
• Sharpe ratio is computed using daily returns and annualized
• This tool does not account for transaction timing, dividends, or taxes
These assumptions are appropriate for quick performance analysis but are not a full backtesting system.
This project includes both:
- a CLI tool (engineer-friendly, scriptable), and
- a web dashboard (demo-friendly, visually polished).
The dashboard also supports a CLI flags input box, so you can paste flags like:
benchmark SPY --period 2y --risk_free 0.02 --sort pl --top 5
Streamlit Caching (Stability Feature)
To reduce repeated calls to Yahoo Finance (yfinance) and improve reliability (especially when deployed), the dashboard caches analysis results for 15 minutes using Streamlit caching: • prevents rate-limit issues • speeds up refreshes and UI changes • improves stability for public users
Run Locally
- Setup environment:
python3 -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Run the CLI
Recommended way (package mode):
python -m src.analyze --file data/holdings.csv --benchmark SPY --period 1y --risk_free 0.02 Examples: python -m src.analyze --sort pl python -m src.analyze --top 5 python -m src.analyze --benchmark SPY --period 2y --risk_free 0.02
- Run the Dashboard:
streamlit run app.py
This project was created to better understand how wealth management platforms evaluate portfolio performance, benchmark comparisons, and risk-adjusted returns in real-world financial contexts.