Results 1 to 7 of 7
  1. #1
    bytreeide is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    47

    Trouble with MIRR

    This is probably a pretty simple answer, but I have been having some trouble with Access' built in Financial Function: MIRR



    I have the following code:

    Code:
    Private Sub ROI_Button_Click()
    Static CFA(6) As Double 'Define array
    CFA(0) = -14875 'Initial Investment
    CFA(1) = 4635 'Positive Cash flows for five years
    CFA(2) = 6180
    CFA(3) = 6180
    CFA(4) = 6180
    CFA(5) = 6180
    Me.T6ROI = MIRR(CFA(), 0.07, 0.09) 'Calculated Modified Internal Rate of Return
    
    End Sub
    The result that I get is 16.89%

    When I do the same thing in Excell:

    =MIRR({-14875, 4635, 6180, 6180, 6180, 6180}, 0.07, 0.09)

    I get 18.53%

    I have also alternatively tried to write the equation out for the MIRR function

    Code:
    Private Sub ROI_Button_Click()
    Dim I As Long
    Dim F As Long
    Dim R As Long
    Dim Y1 As Long
    Dim Y2 As Long
    Dim Y3 As Long
    Dim Y4 As Long
    Dim Y5 As Long
    F = 1.07 'Loan Rate
    R = 1.09 'Reinvest Rate
    I = -14875 'Initial Investment
    Y1 = 4635 'Positive Cash flows for five years
    Y2 = 6180
    Y3 = 6180
    Y4 = 6180
    Y5 = 6180
    Me.T6ROI = (((((Y1 / (R ^ 1)) + (Y2 / (R ^ 2)) + (Y3 / (R ^ 3)) + (Y4 / (R ^ 4)) + (Y5 / (R ^ 5))) * (R ^ 5)) _
    / (I / F * F)) ^ (1 / 5)) - 1
    End Sub
    I get 14.56%

    What am I missing? What have I done wrong?

    Thanks

    bytreeide

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Similar to my experience with programming matrix multiplication.

    I tested 2 methods (one using Excel functions and one not) in Access against the Excel functions in worksheet. 3 different results.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bytreeide is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    47
    I just feel like something is wrong with my code somewhere.

    My instinct is to trust the Excel calculated number.

    I would like to make them all equal the same thing, any insights?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    None. I never did get the various matrix calc methods to agree.

    I wondered if invoking Excel function would return a 4th result. I am trying but can't get VBA to accept the {} characters.

    Excel.WorksheetFunction.MIRR({-14875, 4635, 6180, 6180, 6180, 6180}, 0.07, 0.09)

    And this returns the same as not invoking WorksheetFunction

    Excel.WorksheetFunction.MIRR(CFA(), 0.07, 0.09)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    bytreeide is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    47
    I figured out what I had wrong. I think I was informed incorrectly on one of the help site I looked at. I was defining my array of entries as ARRAY(n) and then assigning values to my array starting with ARRAY(0) and ending with ARRAY(n-1). This yield an inconsistent answer from what I had been getting in Excel (which I considered to be correct, as I understand how excel works better than access).

    The solution that I found is to have an array defined as ARRAY(n) and assign values from ARRAY(0) to ARRAY(n). It would appear that the way that I was doing it before I was automatically throwing a "zero" value in at the end of my array and that was causing a problem.

    So lesson learned, when using arrays, if you want to have "n" values stored in the array, then your array should be defined as "n+1".

    I hope this helps someone.

    bytreeide

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    I don't work with arrays often and I always have to relearn some things when I do. I changed the array declaration to:

    Static CFA(5) As Double

    And that will return 18.53%

    That's because the array is 0 based (the default). Can change the array to 1 based with code in module header:

    Option Base 1

    Then the (6) declaration would work with indexes 1 through 6, not using 0.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I agree with June ---CFA(5) has 6 elements
    Code:
    Sub AWF_MIRR()
    Static CFA(5) As Double 'Define array
    CFA(0) = -14875 'Initial Investment
    CFA(1) = 4635 'Positive Cash flows for five years
    CFA(2) = 6180
    CFA(3) = 6180
    CFA(4) = 6180
    CFA(5) = 6180
    Debug.Print MIRR(CFA(), 0.07, 0.09) 'Calculated Modified Internal Rate of Return
    
    End Sub
    Returns 0.185321001727451

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Trouble
    By Daryl2106 in forum Access
    Replies: 3
    Last Post: 03-27-2015, 11:53 AM
  2. Trouble Getting the Data I want
    By rts in forum Queries
    Replies: 6
    Last Post: 08-21-2013, 01:29 PM
  3. Hope NOT to get in trouble here
    By djclntn in forum Forms
    Replies: 12
    Last Post: 03-06-2012, 02:36 PM
  4. Trouble with (R)
    By NOTLguy in forum Access
    Replies: 3
    Last Post: 10-29-2010, 11:55 AM
  5. Iff trouble
    By JackT in forum Access
    Replies: 3
    Last Post: 08-18-2010, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums