Risk Parity Portfolio
- Utilità
- Better Trader Every Day
- Versione: 1.30
- Aggiornato: 22 agosto 2025
- Attivazioni: 5
The RPP script computes the optimum weights of a portfolio of symbols (stocks, forex pairs, indices, etc.) using the Risk Parity Algorithm.
You can read the theory of the Risk Parity algorithm in this Wikipedia page.
Inputs:
1) Symbols in the portfolio.
2) Time frame you are interested in.
3) Number of past bars to compute the correlations.
4) Print the covariance matrix (true/false)
5) Print the correlation matrix (true/false)
Output: Optimum weights for each symbol in the portfolio. These are printed in the Experts tab.
These weights are such that they account for the level of volatility (measured by standard deviation of returns) and the historic correlation between symbols.
Suppose you have US$ 1000 to invest in 3 symbols. You run this script (RPP) and get three optimum weights: W1,W2,W3. In order to have risk parity in your portfolio, you should bet W1*1000, W2*1000, and W3*1000 in the first, second and third symbol, respectively.
Also in the Experts tab output is the covariance matrix normalized by the first diagonal entry in the matrix.
The diagonal entries are a measure of the relative volatility of a symbol with respect to the first symbol. For instance, in the screenshot below, since all diagonal entries are less than 1, it means that XAUUSD (the first entry) has the highest volatility among these symbols, and USDCAD being the least volatile of the set, with 0.092 in the diagonal (9.2% of the XAUUSD volatility).
The off-diagonal entries are a measure of the correlation between symbol's returns, but a better option is to read the off-diagonal entries of the correlation matrix. For instance, in the screenshot below, the highest off-diagonal value in the correlation matrix is -0.727 between USDCAD and AUDUSD, which means that these two symbols have a high correlation (greater than 0.7 in absolute value) and it is negative; when USDCAD goes up, AUDUSD goes down (statistically speaking), and vice-versa. As a second example, the lowest off-diagonal value in the correlation matrix is +0.001 between EURUSD and XAUUSD, which means that they move quite independently (uncorrelated).
Be aware: the covariance and correlation matrices are key in the calculation of optimal weights. These matrices depend on the input time frame and the number of historic bars. These two parameters should be in accordance with your strategy. For instance, if you are a swing trader that hold positions for days, use daily or higher time frames. If you are a day trader that hold positions for minutes, use minutes or hours time frames.
Other approaches to select optimum portfolio weights include the Portfolio Efficiency Front (Pareto Front) which is implemented in PEF.
