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 bring 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 final wealth. Examples of such portfolios include the Markowitz portfolio or the Universal portfolio. There is currently active research in the area of online portfolios, and even though the results are mostly theoretical, algorithms for practical use are starting to appear.

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

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 developed 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 literature:

Benchmarks Follow the winner Follow the loser Pattern matching Other
BAH Universal Portfolios Anticorr BNN Markowitz
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 computer-generated portfolio of 3 stocks and plot the results
  tools.quickrun(CRP())

Additional Resources

If you do not know what an online portfolio is, look at Ernest Chan's 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 the 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

pip install universal-portfolios

Development

Set up .venv, install dependencies and run tests with:

make test

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 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.16.tar.gz (8.7 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.16-py3-none-any.whl (5.2 MB view details)

Uploaded Python 3

File details

Details for the file universal_portfolios-0.4.16.tar.gz.

File metadata

  • Download URL: universal_portfolios-0.4.16.tar.gz
  • Upload date:
  • Size: 8.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for universal_portfolios-0.4.16.tar.gz
Algorithm Hash digest
SHA256 a161c3d18f4eb2b158aa558c64077fc917b84721420391e2575961d7dfac0928
MD5 886e1ce1fc728cc5358b1c189960ee38
BLAKE2b-256 a5d001f76f6ae8a75fcca480c8a8530cea3c549c613ddacc7ba552080f144301

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for universal_portfolios-0.4.16-py3-none-any.whl
Algorithm Hash digest
SHA256 898e24e2ff83edeb176ae3498a98728dfaa848891f4e66618a4eae450286554a
MD5 314a5f64aae19b4990dce4b6a5910180
BLAKE2b-256 94414487da996a6d4d618fb92c15073df89694de3d461e0b618c8e0ee02eec69

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