Collection of algorithms for online portfolio selection
Project description
Universal Portfolios
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
-
examplescontains 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.datacontains various datasets to help you in your journey. -
universal.algoshosts 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.algoprovides a general class inherited by all the individual algos' subclasses. Algo computes the weights at every timestep. -
universal.resultcomputes 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 or On-line portfolios.ipynb
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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file universal_portfolios-0.4.15.tar.gz.
File metadata
- Download URL: universal_portfolios-0.4.15.tar.gz
- Upload date:
- Size: 14.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0efd18e81c567ce3cd887c658009cd9f7d8c22f0eab76c6896c8e4aa535dcd0d
|
|
| MD5 |
b389b4a116797766e92436ba104b045c
|
|
| BLAKE2b-256 |
ad3ccafd23b8c5921a80585e9e3306857b8cec6b657a9c365af059cdd5225b30
|
File details
Details for the file universal_portfolios-0.4.15-py3-none-any.whl.
File metadata
- Download URL: universal_portfolios-0.4.15-py3-none-any.whl
- Upload date:
- Size: 5.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fee9f905596c967159fc7988c63b9938b72d42ca6cdc4794da2965b76ac5ff75
|
|
| MD5 |
5fd268c2e83813aaad426ef0c7e9b586
|
|
| BLAKE2b-256 |
00784fc79a8f7e9e4d881688d30ca2e56127d8f06b8a75afcab3638796cc6f3d
|