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.

Metadata

Release files for universal-portfolios 0.4.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for universal-portfolios 0.4.17
File Size Uploaded
universal_portfolios-0.4.17.tar.gz 8.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for universal-portfolios 0.4.17
File Interpreter ABI Platform
universal_portfolios-0.4.17-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 MB

Release files / universal_portfolios-0.4.17.tar.gz

Download URL universal_portfolios-0.4.17.tar.gz
Size 8.7 MB
Tags Source
SHA-256 checksum
How to use checksums
27e5e443dc46b0e3e99035e1c34974d1b4439553ec4fe8cbf11b6dd6c346f212
BLAKE2b-256 checksum
How to use checksums
eb511249e9d7c28f7027730ddb04644046f2a02df88b3a3954687775b8074054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release files / universal_portfolios-0.4.17-py3-none-any.whl

Download URL universal_portfolios-0.4.17-py3-none-any.whl
Size 5.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5da294f188c08a911815f5e406907563fbdf0319890da47aaf4134473845ac67
BLAKE2b-256 checksum
How to use checksums
1f270a44f03c855d9a1672d8b9de5d185954377b4890c74a6aa81b1c15adfd30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.17 This release

2 release files

0.4.16

2 release files

0.4.15

2 release files

0.4.14

2 release files

0.4.13

2 release files

0.4.12

2 release files

0.4.11

2 release files

0.4.10

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page