Skip to main content

Portfolio Optimization

Project description

Portfawn: Optimizing Financial Portfolios with Classical and Quantum Techniques

Portfawn is an advanced library for constructing and optimizing financial portfolios using state-of-the-art classical and quantum optimization methods. Designed for flexibility, it allows you to fine-tune portfolio construction with customizable objectives, adaptable risk models, and cutting-edge optimization techniques—all through a single, streamlined package.

Why Choose Portfawn?

  • Optimize Your Way: Achieve your portfolio goals with customizable optimization objectives:
    • Classical Objectives: Minimum variance, maximum Sharpe ratio, target returns, and more.
    • Quantum Objectives: Innovative quantum optimization for complex problems.
  • Flexibility: Configure every aspect—risk models, constraints, backend systems, and more.
  • Single-Command Installation: Install the package with tailored dependencies for quantum or classical setups using optional tags.
  • Seamless Backtesting: Validate your strategies with automated workflows.
  • User-Friendly API: Designed to simplify complex financial engineering tasks.

Key Features

Advanced Portfolio Optimization

  1. Classical Optimization Objectives:

    • Minimum Variance Portfolio (MVP): Minimize portfolio risk.
    • Maximum Return Portfolio (MRP): Maximize portfolio return.
    • Maximum Sharpe Ratio Portfolio (MSRP): Maximize returns per unit risk.
    • Customizable Parameters: Define constraints, target returns, risk-free rates, and optimization precision.
  2. Quantum Optimization Objectives:

    • Binary Mean-Optimal Portfolio (BMOP): Solve portfolio problems using quantum annealing.
    • Backend flexibility:
      • Simulated annealing via neal.
      • Quantum processing units (QPUs) via D-Wave.

Unified Interface

Portfawn provides a unified API for both classical and quantum optimization, making it easy to switch between methods with minimal code changes.

Installation

You can install Portfawn and its dependencies in a single command:

pip install portfawn

Getting Started

This example demonstrates how to use Portfawn to optimize portfolios with classical and quantum objectives, run backtests, and visualize results.

1. Import Libraries

import dafin
import matplotlib.pyplot as plt

from portfawn import (
    BackTest,
    EquallyWeightedPortfolio,
    MeanVariancePortfolio,
    RandomPortfolio,
    OptimizationModel,
)

2. Define Assets and Load Data

# Define assets and date range
asset_list = ["SPY", "GLD", "BND"]
date_start = "2010-01-01"
date_end = "2022-12-30"

# Load returns data
returns_data = dafin.ReturnsData(asset_list).get_returns(date_start, date_end)

3. Create and Configure Portfolios

portfolio_list = [
    RandomPortfolio(),
    EquallyWeightedPortfolio(),
    MeanVariancePortfolio(name="Minimum Variance Portfolio", optimization_model=OptimizationModel(objective="MVP")),
    MeanVariancePortfolio(name="Maximum Return Portfolio", optimization_model=OptimizationModel(objective="MRP")),
    MeanVariancePortfolio(name="Maximum Sharpe Ratio Portfolio", optimization_model=OptimizationModel(objective="MSRP")),
    MeanVariancePortfolio(name="Binary Multi-Objective Portfolio", optimization_model=OptimizationModel(objective="BMOP")),
]

4. Run Backtesting

backtest = BackTest(
    portfolio_list=portfolio_list,
    asset_list=asset_list,
    date_start=date_start,
    date_end=date_end,
    fitting_days=22,
    evaluation_days=5,
    n_jobs=2,
)
backtest.run()

5. Visualize and Save Results

fig, ax = backtest.plot_cum_returns()
plt.savefig("plot_cum_returns.png")
Description
fig, ax = backtest.plot_dist_returns()
plt.savefig("plot_dist_returns.png")
Description
fig, ax = backtest.plot_corr()
plt.savefig("plot_corr.png")
Description
fig, ax = backtest.plot_cov()
plt.savefig("plot_cov.png")
Description

Demo

Check out the demos in demo/.

License

This project is licensed under the MIT License.

Support

Need help or have feedback? Get in touch:

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

portfawn-0.0.3.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

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

PortFawn-0.0.3-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: portfawn-0.0.3.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for portfawn-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5b8c7c6fa47f79027a96fd3e1ee071e7c86be5ec26f417ef02861ba2597226d7
MD5 f9fc8c6a796c2280ab48fb91becbc70e
BLAKE2b-256 8dcc634fd45fdf0a1b453e0076f8a4f6c5ce9078149fb5c1aa30b61d9be0e8ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PortFawn-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for PortFawn-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 109e8bd88bd9b3a5e0674706bb911f6886ef74c5a2f74ad4572db6d96a5d6f47
MD5 585b907261eab9737d7b40f56dd7ab10
BLAKE2b-256 39bd155fc6a243474a9fc4303c725bb350b725cc31ea9df2259bbb929b3bab87

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