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.
-
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.
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())
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
pip install universal-portfolios
Set up .venv, install dependencies and run tests with:
make test
Creator: Marigold
Thank you for your contributions!
Alexander Myltsev | angonyfox | booxter | dexhunter | DrPaprikaa | paulorodriguesxv | stergnator | Xander Dunn
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.