Skip to main content

quantportfolio

A simple toolkit for portfolio optimization (Sharpe ratio, efficient frontier).

Installation

pip install quantportfolio

Example

from quantportfolio import get_portfolio_returns, max_sharpe_ratio, portfolio_performance

# Define stock pool
tickers = ["NVDA", "AMZN", "META"]

# Download returns
df = get_portfolio_returns(tickers, start="2024-01-01")

# Compute annualized mean returns & covariance
returns = df.drop(columns=["Date"])
mean_returns = returns.mean() * 252
cov_matrix = returns.cov() * 252
rf = 0.036  # risk-free rate

# Optimize for max Sharpe Ratio
result = max_sharpe_ratio(mean_returns.values, cov_matrix.values, rf)
weights = result.x

# Evaluate performance
port_return, port_vol, sharpe = portfolio_performance(
    weights, mean_returns.values, cov_matrix.values, rf
)

print("Weights:", dict(zip(tickers, weights.round(4))))
print(f"Expected Annual Return: {port_return:.2%}")
print(f"Expected Volatility: {port_vol:.2%}")
print(f"Sharpe Ratio: {sharpe:.2f}")

License

MIT License - see the LICENSE file for details.

Release files for quantportfolio 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantportfolio 0.0.3
File Size Uploaded
quantportfolio-0.0.3.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quantportfolio 0.0.3
File Interpreter ABI Platform
quantportfolio-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / quantportfolio-0.0.3.tar.gz

Download URL quantportfolio-0.0.3.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6d1270a057444f11c8b474dd13cfbca4cc242a4ce164bf46542c160354419ce9
BLAKE2b-256 checksum
How to use checksums
53021a1e5ac459cc812d04b7f3f574dacdd264acc5264136bb7af7d7fe12b3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.5

Release files / quantportfolio-0.0.3-py3-none-any.whl

Download URL quantportfolio-0.0.3-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2769dc5351551a90942031e1c5f0066e31f86960a698dc1746d4bee0742f9201
BLAKE2b-256 checksum
How to use checksums
e5e8cfa38cfd15e05e1291d9300a8930498f1b798073451fddecd808dec75304
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page