Skip to main content

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.

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.17.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.17-py3-none-any.whl (5.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: universal_portfolios-0.4.17.tar.gz
  • Upload date:
  • Size: 8.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for universal_portfolios-0.4.17.tar.gz
Algorithm Hash digest
SHA256 27e5e443dc46b0e3e99035e1c34974d1b4439553ec4fe8cbf11b6dd6c346f212
MD5 fb6c91f8e1573187447f3f7be28b8f57
BLAKE2b-256 eb511249e9d7c28f7027730ddb04644046f2a02df88b3a3954687775b8074054

See more details on using hashes here.

Provenance

The following attestation bundles were made for universal_portfolios-0.4.17.tar.gz:

Publisher: publish.yml on Marigold/universal-portfolios

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for universal_portfolios-0.4.17-py3-none-any.whl
Algorithm Hash digest
SHA256 5da294f188c08a911815f5e406907563fbdf0319890da47aaf4134473845ac67
MD5 51fc5237e942a3d625749c5ac0a66177
BLAKE2b-256 1f270a44f03c855d9a1672d8b9de5d185954377b4890c74a6aa81b1c15adfd30

See more details on using hashes here.

Provenance

The following attestation bundles were made for universal_portfolios-0.4.17-py3-none-any.whl:

Publisher: publish.yml on Marigold/universal-portfolios

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.4.17 This release

2 files

0.4.16

2 files

0.4.15

2 files

0.4.14

2 files

0.4.13

2 files

0.4.12

2 files

0.4.11

2 files

0.4.10

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3.0

1 file

0.2.0

1 file

0.1.2

1 file

0.1.1

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page