PDA

View Full Version : [SOLVED:] VBA Function - Portfolio Volatility using Co-variance Matrix



tsimamora
07-16-2015, 09:14 PM
Hi everyone,

I am a newbie in VBA and in this forum and I am in need of your help. :) I am trying to write a code for calculating portfolio volatility using co-variance matrix:

13937

The Port_Vol function that I created does not work when I included "Square Root (^0.5)". But if I didn't include Square Root, the function works just fine.

I need to include the Square Root in order to calculate the real value of volatility. Can you help me with this?

Thank you very much beforehand!

p45cal
07-17-2015, 01:15 AM
try:
Port_Vol = Application.MMult(Application.MMult(Application.Transpose(W), CovMat), W)(1) ^ 0.5

tsimamora
07-17-2015, 01:33 AM
Wow, it works! Many thanks p45cal. :)

May I know why adding (1) could make the function work?

p45cal
07-17-2015, 02:27 AM
because the result of Application.MMult is an array (albeit with only one member).

tsimamora
07-17-2015, 05:00 AM
Got it. At first I thought the output will already be the sum of all of the array (variances); so I just needed to SQRT them.

Apparently I was wrong. Thank you for your awesome answers! :content: