Given the factor structure below with K factors, the return for N assets is given by (under matrix notation):
$R =\alpha + \beta F + \epsilon$
where $F$ is matrix of K factor returns and $\beta$ is matrix of NxK factor loadings and $\epsilon \sim N(0,\Omega)$. The return on a portfolio of those N stocks with weight vector $w$ can be written as:
$Ptf = wR = w\alpha + wBF + w\epsilon$
Taking the expectation and variance yields:
$E[Ptf] = w\alpha + w \beta E[F]$
$V[Ptf] = (w\beta)\Sigma (w \beta)^T + w\Omega w^T$
Where $\Sigma$ is the covariance matrix of the factors and $\Omega$ is the diagonal covariance matrix of specific risk component.
It follows that the standard deviation of the portfolio is: $\sigma_{ptf}=\sqrt{V[Ptf]}$
I am interested in the marginal risk contribution $MRC$ of the stocks, but also the factors to the portfolio. My derivation of $MRC$ which I obtained by generalizing the common case of no factor structure is as follows:
$MRC = \partial \sigma_{ptf} /\partial w = (w\beta\Sigma \beta^T + w\Omega)/\sigma_{ptf} $
My problem arises when I compute $MRC$ using the the equation above. In fact when I re-compose the risk using the weights, I do not find it is equal to the portfolio risk. Any help is appreciated. I will upload sample code shortly.