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:
- Must be a pandas DataFrame.
- Column indices must be ticker symbols.
- Row indices must be pandas Timestamps in ascending order.
- 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
- Add support for all endpoints.
- Add support for constraints for each portfolio optimization methodology.
- 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
Built Distribution
File details
Details for the file portoptpy-0.1.4.tar.gz
.
File metadata
- Download URL: portoptpy-0.1.4.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e717f714d12a366168169b5a09656c1684e4b01a4d29c9e547f9ce5d7e382a4 |
|
MD5 | d5e821a3ff7543982e349e14f1d3fe61 |
|
BLAKE2b-256 | 24a18d185b6bf0fb271fc88bf3e45d1d0f70e181b48b58d00c4ad5133deaa8ef |
File details
Details for the file portoptpy-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: portoptpy-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f959e667c9afc8de3dbb8af1e81b0801b38d80251277383605d4810f3e62b3b |
|
MD5 | a209a1ee768d5de842f27161127d38b6 |
|
BLAKE2b-256 | fd02eb92c4aabfd7f44b0feaed43dfa3d0d10ac14701be45c05068b3d93fc0b7 |