Reweighted Price Relative Tracking (RPRT)
Relevant source files
The following files were used as context for generating this wiki page:
Reweighted Price Relative Tracking (RPRT) is an Online Portfolio Selection (OLPS) algorithm implemented within the universal-portfolios library. It belongs to the "Follow the Loser" category of strategies, which typically leverage mean reversion principles to optimize portfolio weights over time. The primary objective of RPRT is to maximize final wealth by choosing optimal portfolio weights in every trading period based on predicted price relatives.
The RPRT implementation inherits from the base Algo class, providing a standardized interface for execution and evaluation against historical datasets. It utilizes a reweighted price relative mechanism to adjust weights, ensuring the portfolio remains responsive to market fluctuations while projecting weights onto a simplex to maintain valid distribution constraints.
Sources: README.md:32-55, universal/algos/rprt.py:10-18
Architecture and Core Logic
RPRT is implemented as the RPRT class in universal/algos/rprt.py. It extends the Algo base class, which defines the lifecycle of an OLPS algorithm: initialization, weight calculation per step, and final result generation.
Process Flow
The algorithm follows a specific sequence during each trading step:
- Prediction: It predicts the next price relative using a simple moving average over a specified lookback window.
- Reweighting: It calculates a "reweighted price relative" ($\phi$) using a combination of the last price relative and a decaying factor ($\theta$).
- Update: It updates the portfolio weights using a learning rate ($\lambda$) derived from the difference between the predicted relative and its mean.
- Simplex Projection: The resulting weights are projected onto a simplex to ensure they sum to 1 and are non-negative.
Implementation Details
Class Configuration
The RPRT algorithm is configured via three primary hyperparameters defined in the __init__ method.
| Parameter | Type | Default | Description |
|---|---|---|---|
window | int | 5 | The lookback window for price relative prediction. Must be $\ge 3$. |
eps | float | 50 | The epsilon threshold used in the weight update calculation. |
theta | float | 0.8 | The decay factor used to compute the reweighted price relative. |
| Sources: universal/algos/rprt.py:23-40 |
Key Methods
predict(hist): Calculates the predicted price relative as the mean of the history divided by the most recent price relative.- Source:
universal/algos/rprt.py:68-70
- Source:
update(b, phi_pred, D_pred): Performs the core weight adjustment. It calculates $\lambda$ (lambda) to determine the step size of the update based on the L2 norm of the difference between the predicted relative and its mean.- Source:
universal/algos/rprt.py:72-97
- Source:
init_step(X): Initializes the persistentphistate using the first two price points in the provided history.- Source:
universal/algos/rprt.py:41-43
- Source:
Data Handling and Processing
RPRT uses "raw" price types, meaning it expects absolute prices which are then converted to relatives internally. The Algo base class handles this conversion via the _convert_prices utility.
Performance Evaluation
Results from RPRT are returned as an AlgoResult object. This class provides various metrics and visualization tools to assess the strategy's performance.
Available Metrics
The system calculates standard financial metrics based on the weights generated by RPRT:
- Sharpe Ratio: Annualized risk-adjusted return.
- Max Drawdown: The largest peak-to-trough decline.
- Turnover: Frequency of rebalancing, derived from
to_rebalanceintools.py. - Profit Factor: Ratio of gross gains to gross losses.
Sources: universal/result.py:108-250, universal/tools.py:724-736
Summary Table Generation
The summary() method provides a text-based overview of RPRT's performance.
| Metric | Derivation |
|---|---|
| Annualized Return | (r.mean() - 1) * freq() |
| Winning Days | (r_log > 0).sum() / all_trades |
| Longest Drawdown | Calculated from the cumulative equity curve. |
| Annual Turnover | D.abs().sum().sum() / (len(D) / freq()) |
| Sources: universal/result.py:284-310 |
Summary
The Reweighted Price Relative Tracking (RPRT) algorithm provides an automated system for portfolio optimization within the OLPS framework. By utilizing a window-based prediction model and a reweighted updating mechanism, it seeks to exploit mean-reverting price behaviors. The implementation is robustly integrated into the universal-portfolios ecosystem, benefiting from centralized data conversion, parallel execution capabilities, and comprehensive result analysis tools.
Sources: universal/algos/rprt.py:10-18, universal/algo.py:114-148