+ Reply to Thread
Results 1 to 2 of 2

VBA array input array output problem

  1. #1
    Registered User
    Join Date
    11-29-2017
    Location
    breda
    MS-Off Ver
    2013
    Posts
    1

    VBA array input array output problem

    Hi all,

    I am trying to program something in VBA. The inputs are matrices which varies on the amount of stocks, which is unfortunately not the same all the time.
    I already managed to get VBA to calculate 4 constants (A, B, C, D) with the matrices as input, there will always be only 4 constants, but they depend on the input of course. These 4 constants are calculated with the function letters (see attachment).

    The next thing is that I want to calculate minimum variance portfolio weights, which could be done with the following excel formula: MMULT(inverse covariance matrix, 1-vector) / C. I tried to program this into VBA with the help of google but it is not really working. I hope the problem is a bit clear by my text and the attachted excel file including the vba code letters and my attempts for the portfolio weights (minvar and minvar2).

    All tips are more than welcome!
    Thanks in advance!

    Job
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    13,363

    Re: VBA array input array output problem

    As I explain here (https://www.excelforum.com/tips-and-...uild-udfs.html ), one of the first things I do when writing a UDF is to add a stop statement or a breakpoint so that I can enter debug mode. So the first thing I did with your file was to add a stop statement to each of the minvar() UDFs, then enter each into a cell on the spreadsheet.

    Stepping through each function, it looks like the same error in both. In each function, you are attempting to divide an array (X or the result of the matrix multiplication) by a scalar (C) using the division operator. Unfortunately, it does not appear that the VBA division operator knows how to divide an array/matrix by a scalar.

    The first solution that I see is to loop through each element of the array X (so the minvar approach will be better than minvar2) and divide by C one element at a time. Are you familiar with VBA loops (For..Next in particular? https://msdn.microsoft.com/en-us/VBA...next-statement )?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] finding an output from 5 variables in an array using exterior input user variables
    By Allsort in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2013, 11:16 AM
  2. Array function only displays first value of array as output
    By q-tip in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2013, 12:51 PM
  3. [SOLVED] Excel 2003 Array as input - how to place output in a second array?
    By theelkhunter in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-10-2013, 02:04 PM
  4. Replies: 19
    Last Post: 05-09-2012, 03:31 AM
  5. Replace hard coded array in formula with link to input array
    By David Brown in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-08-2011, 07:45 AM
  6. Replies: 2
    Last Post: 04-01-2010, 03:54 PM
  7. Input/output values into/from an array
    By Brane Ded in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 11-18-2009, 09:11 PM
  8. Problem with Time Output from Array.
    By cgatlan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2009, 05:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1