Package: universal-portfolios
Universal PortfoliosThe 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 tochoose portfolio weights in every period to maximize its final wealth. Examples of such portfolios could be theMarkowitz portfolioor theUniversal 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 packageexamplescontains 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 developped in this library to approach it.universal.datacontains various datasets to help you in your journeyuniversal.algoshosts the implementations of various OLPS algorithms from the litterature :BenchmarksFollow the winnerFollow the loserPattern matchingOtherBAHUniversal PortfoliosAnticorrBNNMarkovitzCRPExponential GradientPAMRCORNKellyBCRPOLMARBest so farDCRPRMRONSCWMRMPTWMAMRRPRTuniversal.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 Startfromuniversalimporttoolsfromuniversal.algosimportCRPif__name__=='__main__':# Run CRP on a computed-generated portfolio of 3 stocks and plot the resultstools.quickrun(CRP())Additional ResourcesIf you do not know what online portfolio is, look atErnest Chan blog,CASTraderor a recentsurvey by Bin Li and Steven C. H. Hoi.Paul Perry followed up on this and made acomparison of all algorithmson more recent ETF datasets. The original authors of some of the algorithms recently published their own implementation on GitHub -Online Portfolio Selection Toolboxin MATLAB.If you are more into R or just looking for a good resource about Universal Portfolios, check out blog and packagelogoptby Marc Delvaux.Note : If you don't want to install the package locally, you can run both notebooks with Binder -modern-portfolio-theory.ipynborOn-line portfolios.ipynbInstallationOnly Python 3 is supportedpip install universal-portfoliosDevelopmentpoetryis used to manage the dependencies. Runpoetry installto install a virtual environment and thenpoetry shellto launch it.Exporting dependencies to therequirements.txtfile is needed for mybinder.org. It is done viapoetry export --without-hashes -f requirements.txt > requirements.txtFormattingWe 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 toinstall it firstand then enter the project root directory and invoke the command (only once!):pre-commit installRunning Testspoetry run python -m pytest --capture=no --ff -x tests/ContributorsCreator :MarigoldThank you for your contributions!Alexander Myltsev|angonyfox|booxter|dexhunter|DrPaprikaa|paulorodriguesxv|stergnator|Xander DunnDisclaimerThis 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.