Skip to main content

A Python library for interfacing with the Portfolio Optimizer API: https://docs.portfoliooptimizer.io/

Project description

portoptpy

About

A Python library for interfacing with and conducting backtests using the Portfolio Optimizer API: https://docs.portfoliooptimizer.io/. All portfolio optimization methodologies require the historical returns of the portfolio's constiutent assets. By default, the library will obtain daily returns data from Yahoo finance for performing optimizations. Users can utilize their own returns data as long as it is passed in with the proper format:

  1. Must be a pandas DataFrame.
  2. Column indices must be ticker symbols.
  3. Row indices must be pandas Timestamps in ascending order.
  4. Cell values must be the returns of each asset with the type float64.

For backtesting, the library utilizes asyncio and aiohttp to make concurrent calls to the Portfolio Optimizer API which significantly improves the speed of conducting backtests.

Installation

pip install portoptpy

Authentication

An API key is not required to use the Portfolio Optimizer API, however, authenticated users get full access to all endpoints more favorable API limits. Using this library for backtesting purposes will likely require an API key which can be obtained here: https://www.buymeacoffee.com/portfolioopt

Usage

from portoptpy import PortfolioOptimizer

po = PortfolioOptimizer(api_key = 'YOUR_API_KEY')

Performing a single minimum variance portfolio optimization using a 63 day lookback period for calculating the covaraince matrix:

portfolio = po.construct_minimum_variance_portfolio(symbols = ['SPY','TLT','GLD','BTC-USD'], lookback = 63)

Backtesting an equal risk contributions portfolio using an exponentially weighted covariance matrix with decay factor of 0.95:

backtest = await po.backtest_equal_risk_contributions_portfolio(symbols = ['SPY','TLT','GLD','BTC-USD'],
                                                                    lookback = 63,
                                                                    covariance_type = 'exponential',
                                                                    decay_factor = 0.95)

backtest[['portfolio_equity_curve','benchmark_equity_curve']].plot()

Roadmap

  1. Add support for all endpoints.
  2. Add support for constraints for each portfolio optimization methodology.
  3. Add support for backtesting dynamic portfolios (i.e. Multi-Asset Momentum strategies).

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

portoptpy-0.1.7.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

portoptpy-0.1.7-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file portoptpy-0.1.7.tar.gz.

File metadata

  • Download URL: portoptpy-0.1.7.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for portoptpy-0.1.7.tar.gz
Algorithm Hash digest
SHA256 db9dcb905cdf7ba0d7831ca93db6d1388a7b026d0bc76276ebefd1ef5433e8c1
MD5 939ac57388c71382f4f16c4557d420e3
BLAKE2b-256 e9322136ab8f3e1571ccbe5ab7827d1e1f0b89a4dcec86c4589e74a30cb18ff9

See more details on using hashes here.

File details

Details for the file portoptpy-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: portoptpy-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for portoptpy-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fbc89c54d6160580ffdeeded79c6e4cf3156193f04d8391706c05605fcc02b6f
MD5 7aa4afb9a274c6a3913cab9ef5b18571
BLAKE2b-256 2725496a1327d0813d2d704db1eda34ff41f5df35be3b7678357666e17c85cb6

See more details on using hashes here.

Supported by

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