Collection of algorithms for online portfolio selection
The purpose of this Python package is to put 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 its final wealth. Examples of such portfolios could be the Markowitz portfolio or the Universal portfolio. There is currently an active research in the area of online portfolios and even though the results are mostly theoretical, algorithms for practical use start to appear.
Several state-of-the-art algorithms are implemented, based on my understanding of the available literature. Contributions or corrections are more than welcomed.
Outline of this package
examplescontains two Python Notebooks:
universal.datacontains various datasets to help you in your journey
universal.algoshosts the implementations of various OLPS algorithms from the litterature :
|Benchmarks||Follow the winner||Follow the loser||Pattern matching||Other|
|BCRP||OLMAR||Best so far|
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.
from universal import tools from universal.algos import CRP if __name__ == '__main__': # Run CRP on a computed-generated portfolio of 3 stocks and plot the results tools.quickrun(CRP())
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 blog and package logopt by Marc Delvaux.
Only Python 3 is supported
pip install universal-portfolios
poetry is used to manage the dependencies. Run
poetry install to install a virtual environment and then
poetry shell to launch it.
Exporting dependencies to the
requirements.txt file is needed for mybinder.org. It is done via
poetry export --without-hashes -f requirements.txt > requirements.txt
We use pre-commit hook to automatically format code and check for linting errors before each commit. If the checks fail you need to resolve the errors and amend the change set.
To setup the pre-commit hooks you need to install it first and then enter the project root directory and invoke the command (only once!):
poetry run python -m pytest --capture=no --ff -x tests/
Creator : Marigold
Thank you for your contributions!
This software is for educational purposes only and is far from any production environment. Do not risk money which you are afraid to lose. Use the software at your own risk. The authors assume no responsibility for your trading results.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size universal_portfolios-0.4.7-py3-none-any.whl (5.2 MB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size universal-portfolios-0.4.7.tar.gz (5.2 MB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for universal_portfolios-0.4.7-py3-none-any.whl
Hashes for universal-portfolios-0.4.7.tar.gz