Skip to main content

A toolkit for portfolio optimization

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quantportfolio-0.0.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quantportfolio-0.0.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file quantportfolio-0.0.3.tar.gz.

File metadata

  • Download URL: quantportfolio-0.0.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for quantportfolio-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6d1270a057444f11c8b474dd13cfbca4cc242a4ce164bf46542c160354419ce9
MD5 5ba453070ef274925b054094d9e983c0
BLAKE2b-256 53021a1e5ac459cc812d04b7f3f574dacdd264acc5264136bb7af7d7fe12b3e8

See more details on using hashes here.

File details

Details for the file quantportfolio-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: quantportfolio-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for quantportfolio-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2769dc5351551a90942031e1c5f0066e31f86960a698dc1746d4bee0742f9201
MD5 2a60985672281cbc42866ab3ee82761a
BLAKE2b-256 e5e8cfa38cfd15e05e1291d9300a8930498f1b798073451fddecd808dec75304

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page