# How to get the weights for a beta neutral portfolio?

Given a ranking of 100 long stocks and 100 short stocks. Looking at these 200 betas: How can I find the optimal weights to get a beta = 0 long/short portfolio?

• Optimal in what sense? Jul 29 at 16:07
• There are many ways. An EW (or MW) portfolio of all the long stocks has a certain Beta, a similar portfolio of all the shorts has another Beta. Knowing these two betas you can combine the two portfolios such that they have overall beta of zero (you leverage one of the portfolios and deleverage the other). This is just the simplest way to do it. Jul 29 at 17:34
• @BobJansen agree that's an underlying problem. How to optimize this? In the best case scenario I could leverage my ranking in each leg and keep as many stocks as possible. Any idea? Jul 29 at 19:46
• Thanks @noob2 sounds really easy that way! You say there is many ways. Any thoughts on what other technics I could use? Jul 29 at 19:47
• If you are using optimization then you can just add one linear constraint to make the portfolio beta = 0. (see answer below). Jul 30 at 17:19

The author did not define what optimal means, therefore I assume here that we want to find portfolio that has $$\beta=0$$ and has minimum variance $$\sigma^2_{\pi}$$ for the expected return $$\mu_{\pi}$$. This is an extension to Markowitz portfolio and we can find efficient frontier i.e. the set of portfolios that has the lowest risk for a given level of expected return. The algorithm below is not constrained to finding 100 long stocks and 100 shorts stocks, rather it finds optimal weights that minimize the variance no matter how many long and shorts positions it produces. By reading comments I assume that this would be sufficient.

We are in an economy with $$n$$ different assets. Each asset $$i$$ is characterized by its expected return $$\mu_i$$ and variance $$\sigma^2_i$$. Assets $$i$$ and $$j$$ are correlated with correlation $$\rho_{i,j}$$. The proportion invested in asset $$i$$ is $$w_i$$.

Asset's $$i$$ return is given by: $$\mu_i=\alpha_i+\beta_i r_m+\epsilon_i$$ where $$\alpha$$ is asset's alpha and $$\beta$$ is assets beta and $$r_m$$ is market return.

The vector of asset expected return

$$\mu=[\mu_1,...,\mu_n]'$$

The weight vector

$$w=[w_1,...,w_n]'$$

The Betas vector: $$\beta=[\beta_1,...,\beta_n]'$$

Covariance matrix $$\Sigma$$ is given as: $$\begin{bmatrix} \sigma_1^2 & \rho_{1,2}\sigma_1 \sigma_2 & \cdots & \rho_{1,n}\sigma_1 \sigma_n\\ \vdots & \vdots & \ddots & \cdots \\ \rho_{1,n}\sigma_1 \sigma_n & \cdots & \cdots & \sigma_n^2\\ \end{bmatrix}$$

Therefore the portfolio return is given by: $$\mu_{\pi}=\mu'w$$ Portfolio variance: $$\sigma^2_{\pi}=w'\Sigma w$$

The portfolio selection problem is defined as a minimization of risk subject to a return constraint. Our objective function is the portfolio variance and we will minimize it with respect to the portfolio weights. Therefore we want to minimize: $$min_w \frac{1}{2} \sigma^2_{\pi}=\frac{1}{2} w'\Sigma w$$ with 3 constraints: $$\mu'w=m$$ i.e. the portfolio return must be equal to a prespecified level $$m$$. $$\mathbf 1'w=1$$ i.e. the portfolio weights have to sum to 1. $$\beta' w=0$$ i.e. the portfolio beta has to be 0.

This problem is an optimization with equality constraints. We can solve it using the method of Lagrange. We form the Lagrange function with three Lagrange multipliers $$\lambda$$, $$\gamma$$, $$\theta$$: $$L(w,\lambda, \gamma, \theta)=\frac{1}{2} w'\Sigma w + \lambda (m-w'\mu) + \gamma (1-w'\mathbf 1) + \theta (-w'\beta)$$

Next, we solve for the first order condition by taking the derivative with respect to the vector w: $$\frac{\partial L}{\partial w} = \Sigma w - \lambda \mu - \gamma \mathbf 1 - \theta \beta = 0$$ Checking the second order condition, the Hessian of the objective function is equal to the covariance matrix $$\Sigma$$, which is positive definite. Therefore, we have reached the optimal weight vector $$w^*$$: $$w^*=\Sigma^{-1} (\lambda \mu + \gamma \mathbf 1 + \theta \beta)$$

To solve for $$\lambda$$, $$\gamma$$, $$\theta$$ we have to substitute $$w^*$$ to three constraints equations:

$$\mu' \Sigma^{-1} (\lambda \mu + \gamma \mathbf 1 + \theta \beta)=m$$ $$1' \Sigma^{-1} (\lambda \mu + \gamma \mathbf 1 + \theta \beta)=1$$ $$\beta' \Sigma^{-1} (\lambda \mu + \gamma \mathbf 1 + \theta \beta)=0$$

This yields: $$\lambda \mu' \Sigma^{-1} \mu + \gamma \mu' \Sigma^{-1} \mathbf 1 + \theta \mu' \Sigma^{-1} \beta=m$$ $$\lambda \mathbf 1' \Sigma^{-1} \mu + \gamma \mathbf 1' \Sigma^{-1} \mathbf 1 + \theta \mathbf 1' \Sigma^{-1} \beta=1$$ $$\lambda \beta' \Sigma^{-1} \mu + \gamma \beta' \Sigma^{-1} \mathbf 1 + \theta \beta' \Sigma^{-1} \beta=0$$

For our convenience let's define the following scalars: $$A=1' \Sigma^{-1} 1$$ $$B=\mu' \Sigma^{-1} 1=1'\Sigma^{-1} \mu$$ $$C=\mu' \Sigma^{-1} \mu$$ $$D=\beta' \Sigma^{-1} 1 = 1' \Sigma^{-1} \beta$$ $$E=\beta' \Sigma^{-1} \beta$$ $$F=\beta' \Sigma^{-1} \mu = \mu' \Sigma^{-1} \beta$$

Therefore rewriting our system of equations in terms of A, B, C... we get: $$\lambda C + \gamma B + \theta F = m$$ $$\lambda B + \gamma A + \theta D = 1$$ $$\lambda F + \gamma D + \theta E = 1$$

Putting it in the matrix form we get:

$$\begin{bmatrix} C & B & F\\ B & A & D \\ F & D & E\\ \end{bmatrix} * \begin{bmatrix} \lambda \\ \gamma \\ \theta \\ \end{bmatrix} = \begin{bmatrix} m \\ 1 \\ 0 \\ \end{bmatrix}$$

Therefore the solution is: $$\begin{bmatrix} \lambda \\ \gamma \\ \theta \\ \end{bmatrix} = \begin{bmatrix} C & C & F\\ B & A & D \\ F & D & E\\ \end{bmatrix}^{-1} * \begin{bmatrix} m \\ 1 \\ 0 \\ \end{bmatrix}$$

Putting $$\lambda$$, $$\gamma$$, $$\theta$$ into our equation of vector $$w^*$$ we get the weights: $$w^*=\Sigma^{-1} (\lambda \mu + \gamma \mathbf 1 + \theta \beta)$$

How to produce efficient frontier curve? Calculate portfolio expected returns and standard deviation for different levels $$m$$ and plot the result. I have implemented it to check if that works and I got standard efficient frontier curve: