I'm trying to find an efficient way to select $k$ from $n$ risky assets that are the least correlated with each other. I know that I can perform a brute-force search of all $k$-sized combinations of the $n$ assets but this doesn't scale as $n$ grows so I'm wondering if there's an optimization for this problem.
For example, you have the following candidate 10 assets SHW, GOOG, AMZN, WMT, XOM, JNJ, UPS, AMT, AAPL, and NEE. What python, matlab, or R code (you pick) would you run to collect the daily returns for each asset and find the subset of 5 assets that minimizes the square root of the sum of the squares of the entries of the correlation matrix of those 5 assets' returns.
I think this is a binary integer programming problem (or maybe convex optimization since we're searching for a minimum?), please correct the following formulation if it's wrong.
Given
- a returns matrix $R$ where $\left(r_{ij}\right) \in \mathbb{R}^{m \times n}$ is the return for the $i$-th day and the $j$-th asset and
- the correlation matrix $C = \text{corr}\left( R \right)$ where $\left(c_{ij}\right) \in \mathbb{R}^{n \times n}$ is the correlation coefficient between the $i$-th and $j$-th assets
We want to find $\vec{x} \in \left\{0,1\right\}^n $ s.t.
- $\sum \limits_i^n x_i = k$ and
- $\vec{x}$ minimizes $\sqrt{\sum \limits_{i,j}^n {c'}_{ij}^{2}}$, where $\left({c'}_{ij}\right) \in \mathbb{R}^{n \times n}$ is the entry from the modified correlation matrix $C'$ for assets selected by $\vec{x}$, given by $C'= \left(\vec{x} \otimes \vec{x}\right) \odot C$.
That is to say, $C'$ is $C$ with the rows and columns of the rejected assets "zeroed-out", given by the outer product of $\vec{x}$ with itself (to get a matrix $X$ with $x_{i,j} \in \left\{0,1\right\} = 0$ when $\vec{x}_i = 0$ and $x_{i,j} = 1$ when $\vec{x}_i = 1$) Hadamard multiplied by $C$. Finally I chose the square root of the sum of the squares of the entries of $C'$ but I think any distance metric would do (like the average of the absolute values of the entries).
Thanks.