Skip to content

Repository files navigation

MarkoWizard

A modern Python library for Markowitz portfolio optimization and analysis.

PyPI Python 3.10+ License: MIT

📖 Full documentation

Previously known as Diversificador. The original portfolio-analysis web app built with Dash is no longer maintained, but it is preserved on the dash-deprecated branch for reference.

Features

  • Markowitz Mean-Variance Optimization — Compute the efficient frontier using scipy.optimize
  • Capital Allocation Line — Mix risky portfolios with risk-free assets
  • Visualization — Plotly-based charts for efficient frontier, allocation pie, CAL, correlation heatmaps, and price timelines
  • Data Fetching — Built-in helpers for downloading market data via yfinance
  • Web Application — FastAPI backend with a dark-themed interactive frontend

Installation

pip install markowizard

That's everything the library needs: optimization (scipy), market-data fetching (yfinance), and visualization (plotly). No optional extras.

Quick Start (Library)

from markowizard import MarkowitzOptimizer, CapitalAllocator
from markowizard.data import fetch_prices, compute_monthly_returns
from markowizard.visualization import efficiency_frontier_plot

# Fetch prices and compute monthly returns (decimal form, e.g. 0.01 = 1%)...
prices = fetch_prices(["AAPL", "MSFT", "GOOGL", "SPY"], period="5y")
returns = compute_monthly_returns(prices)
# ...or bring your own returns DataFrame (assets as columns).

# Optimize
optimizer = MarkowitzOptimizer(returns)
portfolios = optimizer.optimize()

# Compute Sharpe ratios (provide monthly risk-free rate)
risk_free_rate = 0.005  # 0.5% per month
portfolios = optimizer.compute_sharpe(risk_free_rate)

# Plot the efficient frontier
fig = efficiency_frontier_plot(portfolios, highlight_portfolio=50)
fig.show()

# Best portfolio (maximum Sharpe ratio)
best = optimizer.max_sharpe_portfolio()
print(best)

# Capital allocation line
allocator = CapitalAllocator(best, risk_free_rate)
cal_points = allocator.capital_allocation_line(steps=21)

Web Application

An interactive web UI (FastAPI + a dark-themed frontend) lives in backend/ and frontend/. It is not part of the PyPI package — run it from the container image or a clone.

Using Docker

docker run -p 8000:8000 ghcr.io/outliersanalytics/markowizard:latest

From a clone

git clone https://github.com/OutliersAnalytics/MarkoWizard
cd MarkoWizard
uv run --with-requirements backend/requirements.txt uvicorn backend.main:app --port 8000

Open http://localhost:8000 — the app auto-submits with default tickers on load.

It exposes a single endpoint, POST /api/analyze; see the Web Application docs for the request/response shape.

API Reference

Full reference for every public class and function — MarkowitzOptimizer, CapitalAllocator, the visualization chart functions, and the data fetch helpers — lives in the documentation site.

Development

See CONTRIBUTING.md for setup instructions and contribution guidelines.

License

MIT

About

Python toolkit for Markowitz portfolio optimization. Efficient frontier, capital allocation line, and an interactive FastAPI web app.

Topics

Resources

Contributing

Stars

26 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages