compute_correlation_matrix

Summary: Computes the Pearson correlation matrix for a set of asset price series. Converts prices to daily log returns and computes pairwise correlations using compute_correlation.

pure
double[][]
compute_correlation_matrix
(
double[][] prices_IN
,
int lookback_IN = 0
)

Parameters

prices_IN double[][]

2D array of per-asset unit prices. prices_INi is the price series for asset i.

lookback_IN int

Number of timesteps to use for the correlation window. 0 means use full history.

Return Value

Type: double[][]

result: A 2D double array nAssetsnAssets where resultij is the Pearson correlation between the daily log returns of asset i and asset j.

Notes: - Prices are converted to log returns: rit = log(pit / pi[t-1]). - The matrix is symmetric; only the upper triangle is computed. - Diagonal elements are always 1.0. - If lookback_IN > 0, only the most recent lookback_IN timesteps are used. If lookback_IN <= 0 or >= total timesteps, full history is used. - Requires at least 2 timesteps per asset; otherwise returns an empty matrix. - Uses compute_correlation from this module for each pair. - A lookback of 252 (one trading year) is typical for portfolio correlation analysis.