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:

  • Basic installation (classical optimization only):

    pip install portfawn
    
  • With quantum optimization support:

    pip install portfawn"[quantum]"
    

This modular installation ensures you only install what you need!

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.1.tar.gz (31.3 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.1-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: portfawn-0.0.1.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for portfawn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 468c72fa3fc0a3cc0589fb6003fa7fe806c44a9a6d24ae0d3982bc6c6d1fbb6f
MD5 1ab73203e079c17d5695e8a42c3699e8
BLAKE2b-256 f5ec1ab0cb4cb24e9d6f6bf972b97f3d268e73c18e223b89bd3de1336b776969

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for PortFawn-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c3824e89697ab806cdf76fd061693d73aa499d5b5ac6dc6b7c5f15f22176f85
MD5 f213e534bf9ae8dfa4a6b36d8de43b5e
BLAKE2b-256 3d738b4121d36487cf3916698ff1d3caa6ccaf37bbbf17298d8d1c77510c2cd5

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