Skip to content

About

Multi-module Python portfolio optimization engine implementing GMV and Max Sharpe optimization (SLSQP), a rolling-window backtester with look-ahead bias protection, and Plotly visualizations for the efficient frontier and equity curves. Includes a full pytest suite with CI/CD coverage enforcement.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

60 Commits

Folders and files

Repository files navigation

Portfolio Optimizer 📈

Mean-variance portfolio optimization toolkit with a Streamlit dashboard. This project allows users to download stock data, estimate risk and return, compute optimal portfolio weights, backtest strategies, and analyze performance.

Build Status Version License Stars Forks

Table of Contents 📚

Features ✨

  • Interactive Streamlit Dashboard: A user-friendly web interface for portfolio optimization tasks.
  • Stock Data Ingestion: Downloads and cleans historical stock data using Yahoo Finance.
  • Mean-Variance Optimization: Computes optimal portfolio weights based on expected returns and covariance matrices.
  • Performance Metrics: Calculates key risk and return metrics like Sharpe ratio and maximum drawdown.
  • Backtesting: Simulates historical portfolio performance under various strategies.
  • Efficient Frontier Visualization: Plots the optimal risk-return tradeoff curve.
  • Unit Tested: Comprehensive unit tests for core modules.
  • CI/CD Integration: GitHub Actions for linting and testing.

Tech Stack 💻

  • Languages: Python
  • Frameworks/Libraries: Streamlit, Pandas, NumPy, SciPy, Plotly, yfinance, PyArrow, Ruff, Pytest

Architecture 🏗️

portfolio-optimization/
├── .github/workflows/   # CI/CD (tests + lint)
├── data/                # Local Parquet storage
├── src/
│   ├── __init__.py      # Initializes the src package
│   ├── ingestion.py     # Fetch and clean raw stock data
│   ├── math_engine.py   # Returns and covariance matrices
│   ├── optimizer.py     # Optimal portfolio weights
│   ├── backtester.py    # Historical performance simulation
│   ├── analytics.py     # Sharpe ratio, max drawdown
│   ├── mock_data.py     # Generates synthetic price data for testing
│   ├── tickers.py       # Manages the list of available tickers for the UI
│   └── visualization.py # Creates interactive plots (e.g., Efficient Frontier)
├── tests/               # Unit tests
├── app.py               # Streamlit dashboard
└── pyproject.toml       # Project metadata and dependencies

Data Flow 🌊

  1. Ingestion — Download or load price data into data/ as Parquet.
  2. Math Engine — Compute daily returns and a covariance matrix.
  3. Optimizer — Solve for maximum-Sharpe (or other) weights via scipy.
  4. Backtester — Simulate portfolio value under fixed weights.
  5. Analytics — Report Sharpe ratio and maximum drawdown.

Installation 🛠️

  1. Clone the repository:
   git clone https://github.com/stikey1/portfolio-optimization.git
   cd portfolio-optimization
  1. Create and activate a virtual environment:
   python -m venv .venv
   source .venv/bin/activate   # Windows: .venv\Scripts\activate
  1. Install dependencies:
   pip install .
  • For development (including testing and linting):
     pip install ".[dev]"

Usage 🚀

  1. Launch the dashboard:
   streamlit run app.py
  1. Select tickers using the sidebar multiselect or text input.
  2. Set parameters — lookback window (in years) and risk-free rate.
  3. Run optimization by clicking "Run Optimization."
  4. Analyze results in the Efficient Frontier plot and Backtest comparison against benchmarks like the Equal-Weight portfolio.

Running Tests

pytest tests/ -v

Contributing 🤝

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add some feature').
  5. Push to the branch (git push origin feature/your-feature-name).
  6. Open a Pull Request.

Please ensure all tests pass and follow the code style guidelines (enforced by Ruff).

License 📄

This project is licensed under the MIT License - see the LICENSE file for details.

Links 🔗


© 2026 [portfolio optimizer]. All rights reserved. | Fork me on GitHub ⭐ | Like this project? Give it a star! 👍 | Report issues 🐞

About

Multi-module Python portfolio optimization engine implementing GMV and Max Sharpe optimization (SLSQP), a rolling-window backtester with look-ahead bias protection, and Plotly visualizations for the efficient frontier and equity curves. Includes a full pytest suite with CI/CD coverage enforcement.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages