Skip to main content

Collection of algorithms for online portfolio selection

Project description

Universal Portfolios

PyPi Version PyPi License PyPi Downloads

Open PRs Contributors Repo size

The purpose of this Python package is to put together different Online Portfolio Selection (OLPS) algorithms and provide unified tools for their analysis.

In short, the purpose of OLPS is to choose portfolio weights in every period to maximize its final wealth. Examples of such portfolios could be the Markowitz portfolio or the Universal portfolio. There is currently an active research in the area of online portfolios and even though the results are mostly theoretical, algorithms for practical use start to appear.

Several state-of-the-art algorithms are implemented, based on my understanding of the available literature. Contributions or corrections are more than welcomed.

Outline of this package

  • examples contains two Python Notebooks:

    • Online Portfolios : explains the basic use of the library. Script sequence, various options, method arguments, and a strategy template to get you started.
    • Modern Portfolio Theory : goes deeper into the OLPS principle and the tools developped in this library to approach it.
  • universal.data contains various datasets to help you in your journey

  • universal.algos hosts the implementations of various OLPS algorithms from the litterature :

Benchmarks Follow the winner Follow the loser Pattern matching Other
BAH Universal Portfolios Anticorr BNN Markovitz
CRP Exponential Gradient PAMR CORN Kelly
BCRP OLMAR Best so far
DCRP RMR ONS
CWMR MPT
WMAMR
RPRT
  • universal.algo provides a general class inherited by all the individual algos' subclasses. Algo computes the weights at every timestep.

  • universal.result computes the portfolio wealth from the weights and various metrics on the strategy's performance.

Quick Start

from universal import tools
from universal.algos import CRP

if __name__ == '__main__':
  # Run CRP on a computed-generated portfolio of 3 stocks and plot the results
  tools.quickrun(CRP())

Additional Resources

If you do not know what online portfolio is, look at Ernest Chan blog, CASTrader or a recent survey by Bin Li and Steven C. H. Hoi.

Paul Perry followed up on this and made a comparison of all algorithms on more recent ETF datasets. The original authors of some of the algorithms recently published their own implementation on GitHub - Online Portfolio Selection Toolbox in MATLAB.

If you are more into R or just looking for a good resource about Universal Portfolios, check out blog and package logopt by Marc Delvaux.

Note : If you don't want to install the package locally, you can run both notebooks with Binder - modern-portfolio-theory.ipynb Binder or On-line portfolios.ipynb Binder

Installation

Only Python 3 is supported

pip install universal-portfolios

Development

poetry is used to manage the dependencies. Run poetry install to install a virtual environment and then poetry shell to launch it.

Exporting dependencies to the requirements.txt file is needed for mybinder.org. It is done via

poetry export --without-hashes -f requirements.txt > requirements.txt

Formatting

We use pre-commit hook to automatically format code and check for linting errors before each commit. If the checks fail you need to resolve the errors and amend the change set.

To setup the pre-commit hooks you need to install it first and then enter the project root directory and invoke the command (only once!):

pre-commit install

Running Tests

poetry run python -m pytest --capture=no --ff -x tests/

Contributors

Creator : Marigold

Thank you for your contributions!

Alexander Myltsev | angonyfox | booxter | dexhunter | DrPaprikaa | paulorodriguesxv | stergnator | Xander Dunn

Disclaimer

This software is for educational purposes only and is far from any production environment. Do not risk money which you are afraid to lose. Use the software at your own risk. The authors assume no responsibility for your trading results.

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

universal-portfolios-0.4.10.tar.gz (5.2 MB view details)

Uploaded Source

Built Distribution

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

universal_portfolios-0.4.10-py3-none-any.whl (5.2 MB view details)

Uploaded Python 3

File details

Details for the file universal-portfolios-0.4.10.tar.gz.

File metadata

  • Download URL: universal-portfolios-0.4.10.tar.gz
  • Upload date:
  • Size: 5.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.13 Darwin/21.4.0

File hashes

Hashes for universal-portfolios-0.4.10.tar.gz
Algorithm Hash digest
SHA256 f1ba550f9817f2462d475166eaea016f9dc4f5f9dc8160dcaa23c9a235dc7440
MD5 628d60ceab9d83db23644ee6c61520f7
BLAKE2b-256 894c7e9e01a8aee175a5cb9ee915db9c9715623d63a6ce908c7cd3685099ef1d

See more details on using hashes here.

File details

Details for the file universal_portfolios-0.4.10-py3-none-any.whl.

File metadata

File hashes

Hashes for universal_portfolios-0.4.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ea7026f2c60a886211f2845c9e027ea46f09b3a1a7a58cf136601540e24833fd
MD5 8c4f7d6c6a4a9d5cbc99421b3e5e8687
BLAKE2b-256 0e3d807d9af0676754be799f02b057e6049c018a3d72588976f7ff74d99ed04a

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