Can someone check my proof? I think there is something not quite right. I have found limited resources online for this as well so I think it might benefit others to get this on the internet.
Assume there are $K$ time-series factors with $T$ return observations each and $N$ stocks. Our model states that the return on each stock in the model is a linear combination of the return on the factors, e.g. in vector random variable form $R_i = \beta_i F + \epsilon_i$. The return variance of a portfolio with weights $w$ is given by $\text{Var}(w^\prime R) = w \beta \text{Var}(F) \beta^\prime w + w^\prime \text{Var}(\epsilon)$.
Definitions:
- $w$ ($N \times 1$) portfolio weights
- $\beta$ ($K \times N$) factor loading matrix
- $\Omega = \beta^\prime \text{Var}(F) \beta$ ($N\times N$) factor risk matrix
- $e = \text{Var}(\epsilon)$ ($N \times 1$) stock specific variance
- $\lambda$ ($1\times 1$) Lagrange multiplier
- $\vec 1$ ($N\times 1$)
The optimization problem after adding the Lagrange multiplier for the weights sum to one constraint is:
$$ w^* = \text{argmin}_w \left[ w^\prime \Omega w + w^\prime e - \lambda(w^\prime \vec 1 - 1)\right] $$
The first order conditions are
$$ 2w^\prime \Omega + e^\prime - \lambda \vec 1^\prime = 0 $$ $$ w^\prime \vec 1 = 1 $$
Solving the first equation for $w^\prime$ in terms of $\lambda$ yields
$$w^\prime = \frac{1}{2}\left( \lambda \vec 1^\prime - e^\prime \right) \Omega^{-1}$$
Substituting this into the second FOC the result is
$$ 1 = \left( \frac{1}{2}\left( \lambda \vec 1^\prime - e^\prime \right) \Omega^{-1} \right) \vec 1\\ \implies 2 = \lambda \vec 1^\prime \Omega^{-1} \vec 1 - e^\prime \Omega^{-1} \vec 1 \\ \implies \lambda = \frac{2 + e^\prime \Omega^{-1} \vec 1}{\vec 1^\prime \Omega^{-1} \vec 1 } $$
Substituting the Lagrangian back into the first FOC yields the result
$$ w^{*\prime} = \frac{1}{2}\left[ \left(\frac{2 + e^\prime \Omega^{-1} \vec 1}{\vec 1^\prime \Omega^{-1} \vec 1 }\right)\vec 1^\prime - e^\prime \right] \Omega^{-1} $$
I am not sure if it can be written any more simply than that but when I coded this into a PCA statistical factor model I was getting weights that do not sum to one as the constraint suggests.
Result
Ultimately, I do not think there was really an issue with any of the math that was done originally but a reformulation of the problem really did help thanks to @John. For completeness, the final proof is below.
Definitions:
- $w$ ($N \times 1$) portfolio weights
- $\beta$ ($K \times N$) factor loading matrix
- $\Omega = \beta^\prime \text{Var}(F) \beta$ ($N\times N$) factor risk matrix
- $e = \text{Var}(\epsilon)$ ($N \times N$) diagonal matrix of stock specific variance
- $\lambda$ ($1\times 1$) Lagrange multiplier
- $\vec 1$ ($N\times 1$)
- $\Sigma \equiv \Omega + e$
Under this formulation, portfolio variance is given by
$$\text{Var}(w^\prime R) = w^\prime \beta \text{Var}(F) \beta^\prime w + w^\prime \text{Var}(\epsilon) w\\ = w^\prime \Omega w + w^\prime e w\\ = w^\prime \Sigma w$$
The optimization problem after adding the Lagrange multiplier for the weights sum to one constraint is:
$$ w^* = \text{argmin}_w \left[ w^\prime \Sigma w - \lambda(w^\prime \vec 1 - 1)\right] $$
The first order conditions are
$$ 2w^\prime \Sigma - \lambda \vec 1^\prime = 0 $$ $$ w^\prime \vec 1 = 1 $$
Solving the first equation for $w^\prime$ in terms of $\lambda$ yields
$$w^\prime = \frac{1}{2}\lambda \vec 1^\prime \Sigma^{-1}$$
Substituting this into the second FOC the result is
$$ 1 = \frac{1}{2} \lambda \vec 1^\prime \Sigma^{-1} \vec 1^\prime \implies \lambda = \frac{2}{\vec 1^\prime \Sigma^{-1} \vec 1} $$
Substituting the Lagrangian back into the first FOC yields the result
$$ w^{*\prime} = \frac{1^\prime \Sigma^{-1}}{\vec 1^\prime \Sigma^{-1} \vec 1} $$
In practice, the results that I have gotten from direct closed form estimation of $w^*$ are somewhat unstable for even small values of $N$ and yield results including very high leverage. It may be a coding issue and I am re-re-re checking code but I am fairly confident that there are not and severe coding errors.
If each factor is represented by a portfolio, it seems that it may be best to estimate the $K$ weights of the minimum variance portfolio of the factors then multiply through to get final portfolio weights.