Installation & Setup
Relevant source files
The following files were used as context for generating this wiki page:
The universal-portfolios library is a Python-based toolbox designed for Online Portfolio Selection (OLPS). The installation process primarily involves setting up a Python 3 environment and managing dependencies through specialized tools like Poetry or standard package managers like Pip. This setup allows developers to leverage various algorithms for choosing portfolio weights to maximize final wealth.
Sources: README.md:1-20
Environment Requirements
The project exclusively supports Python 3, specifically requiring version 3.8 or higher. Dependency management is structured to support both end-user installation via PyPI and developer-focused environments using virtual environments.
Sources: README.md:104-106, pyproject.toml:14
Core Dependencies
The system relies on several scientific computing and data analysis libraries:
| Dependency | Minimum Version | Purpose |
|---|---|---|
scipy | >= 1.8.1 | Numerical optimization and statistics |
pandas | >= 1.1.1 | Data manipulation and time-series handling |
scikit-learn | >= 1.1.1 | Covariance estimation and machine learning |
matplotlib | >= 3.3.1 | Strategy performance visualization |
cvxopt | N/A (in requirements) | Convex optimization for MPT and Kelly algos |
Sources: pyproject.toml:14-30, requirements.txt:1-34
Installation Procedures
Standard Installation
For general use, the package can be installed directly from PyPI:
pip install universal-portfolios
Sources: README.md:108-110
Development Setup
Developers contributing to the repository use Poetry for dependency resolution and virtual environment management.
The diagram shows the sequential steps required to set up a local development environment.
Sources: README.md:112-120
Formatting and Hooks
The project uses pre-commit hooks to maintain code quality. Developers must install the hooks to ensure code is automatically formatted and linted before commits.
- Tool: Ruff (configured for a line length of 88)
- Command:
pre-commit install
Sources: README.md:123-132, pyproject.toml:44-47
Verification and Testing
Once installed, the setup can be verified by running the test suite using Pytest through the Poetry environment.
poetry run python -m pytest --capture=no --ff -x tests/
Sources: README.md:135-137
Quick Start Verification
A successful installation can be quickly verified using the tools.quickrun function, which executes a default algorithm (CRP) on a generated dataset.
from universal import tools
from universal.algos import CRP
if __name__ == '__main__':
# Run CRP on a computed-generated portfolio of 3 stocks
tools.quickrun(CRP())
Sources: README.md:79-85, universal/tools.py:72-78
Project Architecture Overview
The installation prepares a multi-module architecture where the Algo base class coordinates with various components.
The diagram illustrates the relationship between the core Algo class, the tools module for execution, and the resulting AlgoResult for analysis.
Sources: universal/algo.py:16-30, universal/tools.py:72-75, universal/result.py:32-40
Conclusion
Setting up universal-portfolios requires a Python 3.8+ environment. While standard users can install via Pip, developers should utilize Poetry to manage the extensive dependency list (including scipy, pandas, and cvxopt) and configure pre-commit hooks to ensure compliance with the project's formatting standards.
Sources: README.md:104-132, pyproject.toml:1-47