Portfolio Risk Matrix
Portfolio Risk Matrix is an indicator drawn in its own pane.
several marketsstatistics and matrices
indicator "Portfolio Risk Matrix"pane: newmarkets: EURUSD, GBPUSD, USDJPYinput lookback = 100eur = returns(close_of(EURUSD))gbp = returns(close_of(GBPUSD))jpy = returns(close_of(USDJPY))cov = covariance_matrix([eur, gbp, jpy], lookback)weights = matrix(3, 1, fill: 0.3333)portfolio_variance = multiply(multiply(transpose(weights), cov), weights)eur_gbp_corr = correlation(eur, gbp, lookback)eur_jpy_corr = correlation(eur, jpy, lookback)plot eur_gbp_corr as eur_gbp, color: blueplot eur_jpy_corr as eur_jpy, color: orangehline 0, style: dotted, color: graycells rows: [["Pair", "Correlation"], ["EUR/GBP", "{eur_gbp_corr:0.00}"], ["EUR/JPY", "{eur_jpy_corr:0.00}"]], columns: 2| Pair | Correlation |
| EUR/GBP | -0.00 |
| EUR/JPY | -0.00 |
Sample data. Not a result. The real AlgoBarsX engine ran this exact script on made-up bars, and this replays what it drew and did. It shows no profit or loss, and it says nothing about how the script would do in a real market.
Replay of this script on 150 sample bars: 2 lines drawn.
Portfolio Risk Matrix is an indicator drawn in its own pane.
You can change one input: lookback (default 100).
It calculates eur as the returns of the close of EURUSD, gbp as the returns of the close of GBPUSD, jpy as the returns of the close of USDJPY, cov as the covariance matrix (series eur, gbp and jpy, length lookback), weights as the matrix (rows 3, columns 1, fill 0.3333), portfolio_variance as the multiply (a the multiply (a the transpose (m weights), b cov), b weights), eur_gbp_corr as the correlation (a eur, b gbp, length lookback) and eur_jpy_corr as the correlation (a eur, b jpy, length lookback).
On the chart, it plots eur_gbp_corr as eur_gbp, plots eur_jpy_corr as eur_jpy, draws a horizontal line at 0 and draws a cells.