Consulting

Results 1 to 5 of 5

Thread: VBA Function - Portfolio Volatility using Co-variance Matrix

  1. #1

    VBA Function - Portfolio Volatility using Co-variance Matrix

    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:

    AAA.jpg

    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!

    Attached Images Attached Images

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Port_Vol = Application.MMult(Application.MMult(Application.Transpose(W), CovMat), W)(1) ^ 0.5
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Wow, it works! Many thanks p45cal.

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

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    because the result of Application.MMult is an array (albeit with only one member).
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •