Reweighted Price Relative Tracking for Portfolio Optimization

R

This is my implementation of the Reweighted Price Relative Tracking strategy documented in the research paper by Zhao-Rong Lai et al. Shout out to the “Paper-to-Profit” substack for calling my attention to it. The code is not meant to be deployed as-is but serves as an educational template for those interested in modern portfolio optimization techniques based on academic research.

Feel free to use this implementation as a foundation, customize the parameters, and adapt it to your specific needs.


General Architecture
The strategy implements the RPRT methodology from the 2018 IEEE paper by Zhao-Rong Lai et al. It dynamically rebalances a portfolio of ETFs based on their price relatives (today’s price divided by yesterday’s price). The algorithm uses a moving window approach to calculate simple moving averages of price relatives, then applies a reweighting mechanism to adjust portfolio allocations. All calculations are projected onto a probability simplex to ensure valid portfolio weights.

The Code
I’ve structured the code with clear sections and thorough comments to make it easy to understand and modify.

  1. Initialization and Parameter Setting
    The algorithm is initialized with optimized parameters for the “broad_etfs” variant: a 10-day lookback window, theta (mixing parameter) of 0.8, and epsilon (reversion threshold) of 5.0. The universe consists of seven broad market ETFs: SPY, QQQ, IWM, EFA, EEM, TLT, and SHV.
     
  2. Simplex Projection Function
    A key component is the simplex projection function that ensures all portfolio weights are valid (non-negative and sum to 1). This uses the Euclidean projection method from Duchi et al. (2008) and includes robust error handling for numerical stability.
     
  3. Scheduled Intraday Universe Selection w/indicators
    In each OnData event, the algorithm calculates price relatives (x_t) for all assets, defined as today’s closing price divided by yesterday’s closing price. These values feed into a rolling buffer to maintain history for the SMA calculation.
     
  4. Reweighted Price Relative Mechanism
    The core of the algorithm is the calculation of reweighted price relatives (phi_next). This involves a sophisticated update rule that mixes current price relatives with previous values using the theta parameter, providing stability while adapting to market movements.
     
  5. Portfolio Weight Calculation
    Using the reweighted price relatives, the algorithm determines a step size (lambda) based on the gap between predicted portfolio return and the epsilon threshold. It then calculates new unconstrained weights and projects them onto the simplex to ensure valid allocations.
  6. Position Management and Rebalancing
    Finally, the algorithm generates portfolio targets from the new weights and uses SetHoldings to rebalance the portfolio. The code includes comprehensive logging to track the predicted return, gap, step size, and target weights at each rebalancing point.
     


 

About the author

quantish
By quantish

quantish

Automate everything.