<-- Previous || Up || Next -->

XIRR Sample Sub
Math Financial Class

Private Sub XIRRSample()
    'Print some samples of the XIRR function.

    Dim Flow() As Variant


    ReDim Flow(1 To 2, 1 To 2)

    Flow(1, 1) = -10000#
    Flow(2, 1) = #4/1/1984#
    Flow(1, 2) = 50674#
    Flow(2, 2) = #4/1/1994#

    GoSub One_XIRRSample
    

    ReDim Flow(1 To 2, 1 To 2)

    Flow(1, 1) = 10000#
    Flow(2, 1) = #4/1/1984#
    Flow(1, 2) = -50674#
    Flow(2, 2) = #4/1/1994#

    GoSub One_XIRRSample
    
    
    ReDim Flow(1 To 2, 1 To 2)

    Flow(1, 1) = -10000#
    Flow(2, 1) = #4/1/1989#
    Flow(1, 2) = 20660#
    Flow(2, 2) = #4/1/1994#

    GoSub One_XIRRSample
    
    
    ReDim Flow(1 To 2, 1 To 2)

    Flow(1, 1) = 10000#
    Flow(2, 1) = #4/1/1989#
    Flow(1, 2) = -20660#
    Flow(2, 2) = #4/1/1994#

    GoSub One_XIRRSample


    ReDim Flow(1 To 2, 1 To 2)
    
    Flow(1, 1) = -10000#
    Flow(2, 1) = #4/1/1993#
    Flow(1, 2) = 10482#
    Flow(2, 2) = #4/1/1994#
    
    GoSub One_XIRRSample
    

    ReDim Flow(1 To 2, 1 To 5)
    
    Flow(1, 1) = -10000#
    Flow(2, 1) = #1/1/1992#
    Flow(1, 2) = 2750#
    Flow(2, 2) = #3/1/1992#
    Flow(1, 3) = 4250#
    Flow(2, 3) = #10/30/1992#
    Flow(1, 4) = 3250#
    Flow(2, 4) = #2/15/1993#
    Flow(1, 5) = 2750#
    Flow(2, 5) = #4/1/1993#

    GoSub One_XIRRSample
    

    ReDim Flow(1 To 2, 1 To 4)
    
    Flow(1, 1) = -70000#
    Flow(2, 1) = #1/1/1990#
    Flow(1, 2) = 10000#
    Flow(2, 2) = #1/1/1991#
    Flow(1, 3) = 20000#
    Flow(2, 3) = #1/1/1992#
    Flow(1, 4) = 30000#
    Flow(2, 4) = #1/1/1993#
    
    GoSub One_XIRRSample
    
    
    ReDim Flow(1 To 2, 1 To 2)
    
    Flow(1, 1) = -10000#
    Flow(2, 1) = #4/1/1984#
    Flow(1, 2) = 10000#
    Flow(2, 2) = #4/1/1994#
    
    GoSub One_XIRRSample


    ReDim Flow(1 To 2, 1 To 2)
    
    Flow(1, 1) = -10000#
    Flow(2, 1) = #4/1/1984#
    Flow(1, 2) = 0#
    Flow(2, 2) = #4/1/1994#
    
    GoSub One_XIRRSample


    ReDim Flow(1 To 2, 1 To 2)
    
    Flow(1, 1) = -10000#
    Flow(2, 1) = #4/1/1984#
    Flow(1, 2) = -100#
    Flow(2, 2) = #4/1/1994#

    GoSub One_XIRRSample

    ReDim Flow(1 To 2, 1 To 512)

    Flow(1, 1) = -694369.54
    Flow(2, 1) = #10/22/1997#

    Dim intCur As Integer
    intCur = 2
    Dim lngMon As Long
    lngMon = 12 + 12 * 1997
    Do While lngMon <= 7 + 12 * 2009
        Dim bytMon As Byte
        Dim intYr As Integer
        bytMon = lngMon Mod 12
        intYr = lngMon \ 12
        If bytMon = 0 Then
            bytMon = 12
            intYr = intYr - 1
        End If

        Flow(1, intCur) = 8421.79
        Flow(2, intCur) = DateSerial(intYr, bytMon, 25)
        
        intCur = intCur + 1
        lngMon = lngMon + 1&
    Loop

    ReDim Preserve Flow(1 To 2, 1 To intCur - 1)

    GoSub One_XIRRSample

    Exit Sub

One_XIRRSample:

    Dim intCurFlow As Integer
    For intCurFlow = LBound(Flow, 2) To UBound(Flow, 2)
        Debug.Print Right$(Space$(3) & Format$(intCurFlow, "#,##0"), 3);
        Debug.Print " " & Right$(Space$(20) & Format$(Flow(1, intCurFlow), "$#,##0.00"), 20);
        Debug.Print " " & Format$(Flow(2, intCurFlow), "Short Date");
        Debug.Print
    Next intCurFlow

    Debug.Print "XIRR = " & Format$(XIRR(Flow()) * 100#, "#,##0.000 000") & "%"
    Debug.Print

    Return
End Sub

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.