compute_correlation_matrix
Computes Spearman correlation matrix from historical data and returns its nearest valid positive-semidefinite form. Use this to generate correlation inputs for copula models in Excel.
Instructions
ModelRisk: Compute the rank-order (Spearman) correlation matrix of a data range via VoseCorrMatrix, and its nearest valid (positive-semidefinite) form via VoseValidCorrmat. Use this to turn historical data into the correlation matrix you feed to create_copula for correlated inputs. Variables are columns by default (set data_in_rows=True if each row is a variable). Read-only: runs on a transient scratch sheet that is always deleted.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sheet | Yes | Sheet holding the data. | |
| workbook | Yes | Workbook file name. | |
| data_range | Yes | A1-style range of the data, e.g. 'A1:D200'. | |
| data_in_rows | No | True if each variable is a row. Default: columns. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| matrix | Yes | Spearman rank-order correlation matrix (VoseCorrMatrix). | |
| is_valid | Yes | True if the matrix is already a valid (PSD) correlation matrix. | |
| data_range | Yes | ||
| variable_count | Yes | ||
| nearest_valid_matrix | No | Nearest valid matrix (VoseValidCorrmat) — null when already valid. |