vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="VB6Parse Library Reference - mirr - Financial">
    <title>mirr - Financial - VB6Parse Library Reference</title>
    <link rel="stylesheet" href="../../../assets/css/style.css">
    <link rel="stylesheet" href="../../../assets/css/docs-style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
    <script src="../../../assets/js/theme-switcher.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
    <script>hljs.highlightAll();</script>
</head>
<body>
    <header class="docs-header">
        <div class="container">
            <h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/financial/index.html">Financial</a> / mirr</h1>
            <p class="tagline">VB6 Library Reference</p>
        </div>
    </header>

    <nav class="docs-nav">
        <div class="container">
            <a href="../../../index.html">Home</a>
            <a href="../../../library/index.html">Library Reference</a>
            <a href="../../../documentation.html">Documentation</a>
            <a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
            <a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
            <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
                <span class="theme-icon">🌙</span>
            </button>
        </div>
    </nav>

    <main class="container">
        
        <article class="library-item">
            <h1 id="mirr-function">MIRR Function</h1>
<p>Returns a Double specifying the modified internal rate of return for a series of periodic
cash flows (payments and receipts).</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">MIRR(values(), finance_rate, reinvest_rate)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong><code>values()</code></strong> (Required) - Array of Double specifying cash flow values. The array must contain
  at least one negative value (payment) and one positive value (receipt).</li>
<li><strong><code>finance_rate</code></strong> (Required) - Double specifying the interest rate paid as the cost of financing.</li>
<li><strong><code>reinvest_rate</code></strong> (Required) - Double specifying the interest rate received on gains from cash
  reinvestment.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a <strong>Variant (Double)</strong> representing the modified internal rate of return, expressed as
a decimal per period. For example, 0.1 represents 10%.</p>
<h2 id="remarks">Remarks</h2>
<p>The Modified Internal Rate of Return (MIRR) is a variation of the internal rate of return (IRR)
that addresses some of IRR's limitations. Unlike IRR, MIRR assumes:
- Negative cash flows (investments) are financed at the <code>finance_rate</code>
- Positive cash flows (returns) are reinvested at the <code>reinvest_rate</code>
This makes MIRR more realistic than IRR for most real-world investment scenarios where the
cost of capital and reinvestment rate differ.</p>
<h3 id="key-characteristics">Key Characteristics:</h3>
<ul>
<li>Returns a rate per period (e.g., if values are monthly cash flows, result is monthly rate)</li>
<li>To convert to annual percentage: multiply by periods per year and by 100</li>
<li>Values must include at least one positive and one negative value</li>
<li>Values are assumed to occur at regular intervals (end of each period)</li>
<li>First value occurs at end of first period (not at time zero like NPV)</li>
<li>Error 5 (Invalid procedure call) if values array contains no positive or no negative values</li>
<li><code>Finance_rate</code> and <code>reinvest_rate</code> should be expressed as decimals (e.g., 0.1 for 10%)</li>
</ul>
<h3 id="mirr-vs-irr">MIRR vs IRR:</h3>
<ul>
<li><strong>IRR</strong> assumes all cash flows are reinvested at the IRR itself (often unrealistic)</li>
<li><strong>MIRR</strong> allows separate rates for financing costs and reinvestment gains (more realistic)</li>
<li><strong>MIRR</strong> is generally more stable and easier to interpret than IRR</li>
<li><strong>MIRR</strong> always returns a single value, while IRR can have multiple solutions</li>
</ul>
<h3 id="when-to-use">When to Use:</h3>
<ul>
<li>Evaluating capital investments with different borrowing and reinvestment rates</li>
<li>Comparing mutually exclusive projects with different cash flow patterns</li>
<li>Analysis of real estate investments, business projects, or equipment purchases</li>
<li>Any scenario where the cost of capital differs from the expected return on reinvestment</li>
<li>When you need a more conservative and realistic return measure than IRR</li>
</ul>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Capital Budgeting</strong> - Evaluate investment projects with realistic rate assumptions</li>
<li><strong>Real Estate Analysis</strong> - Calculate returns on property investments</li>
<li><strong>Equipment Purchase Decisions</strong> - Assess whether to buy or lease equipment</li>
<li><strong>Business Valuation</strong> - Determine value of business investments</li>
<li><strong>Portfolio Management</strong> - Evaluate investment performance with actual reinvestment rates</li>
<li><strong>Loan vs Investment Comparison</strong> - Compare cost of financing to investment returns</li>
<li><strong>Project Ranking</strong> - Rank multiple projects by profitability</li>
<li><strong>Sensitivity Analysis</strong> - Test how changes in rates affect investment viability</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<pre><code class="language-vbnet">&#x27; Example 1: Simple investment analysis
Dim cashFlows(4) As Double
cashFlows(0) = -100000  &#x27; Initial investment
cashFlows(1) = 30000    &#x27; Year 1 return
cashFlows(2) = 35000    &#x27; Year 2 return
cashFlows(3) = 40000    &#x27; Year 3 return
cashFlows(4) = 25000    &#x27; Year 4 return
Dim financeRate As Double
Dim reinvestRate As Double
Dim result As Double
financeRate = 0.08   &#x27; 8% cost of capital
reinvestRate = 0.05  &#x27; 5% reinvestment rate
result = MIRR(cashFlows(), financeRate, reinvestRate)
&#x27; Result is approximately 0.1065 (10.65% annual return)</code></pre>
<pre><code class="language-vbnet">&#x27; Example 2: Real estate investment
Dim propertyFlows(9) As Double
Dim i As Integer
propertyFlows(0) = -500000  &#x27; Purchase price
For i = 1 To 8
    propertyFlows(i) = 50000  &#x27; Annual rental income
Next i
propertyFlows(9) = 600000   &#x27; Sale price in year 9
Dim mortgageRate As Double
Dim marketRate As Double
mortgageRate = 0.06   &#x27; 6% mortgage cost
marketRate = 0.04     &#x27; 4% market return
If MIRR(propertyFlows(), mortgageRate, marketRate) &gt; mortgageRate Then
    MsgBox &quot;Property investment beats financing cost&quot;
End If</code></pre>
<pre><code class="language-vbnet">&#x27; Example 3: Monthly cash flows (convert to annual)
Dim monthlyCashFlows(11) As Double
monthlyCashFlows(0) = -10000
&#x27; ... populate remaining months
Dim monthlyFinanceRate As Double
Dim monthlyReinvestRate As Double
monthlyFinanceRate = 0.08 / 12    &#x27; Annual rate / 12
monthlyReinvestRate = 0.05 / 12   &#x27; Annual rate / 12
Dim monthlyReturn As Double
Dim annualReturn As Double
monthlyReturn = MIRR(monthlyCashFlows(), monthlyFinanceRate, monthlyReinvestRate)
annualReturn = (1 + monthlyReturn) ^ 12 - 1  &#x27; Convert to annual</code></pre>
<pre><code class="language-vbnet">&#x27; Example 4: Comparing two projects
Dim projectA(3) As Double
Dim projectB(3) As Double
projectA(0) = -50000: projectA(1) = 20000
projectA(2) = 25000: projectA(3) = 30000
projectB(0) = -50000: projectB(1) = 15000
projectB(2) = 20000: projectB(3) = 40000
Dim costOfCapital As Double
Dim reinvestmentRate As Double
costOfCapital = 0.1
reinvestmentRate = 0.06
Dim mirrA As Double, mirrB As Double
mirrA = MIRR(projectA(), costOfCapital, reinvestmentRate)
mirrB = MIRR(projectB(), costOfCapital, reinvestmentRate)
If mirrA &gt; mirrB Then
    Debug.Print &quot;Project A has better MIRR&quot;
Else
    Debug.Print &quot;Project B has better MIRR&quot;
End If</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<pre><code class="language-vbnet">&#x27; Pattern 1: Safe MIRR calculation with validation
Function SafeMIRR(cashFlows() As Double, finRate As Double, _
                  reinvRate As Double) As Variant
    Dim hasPositive As Boolean
    Dim hasNegative As Boolean
    Dim i As Integer
    &#x27; Validate array has both positive and negative values
    For i = LBound(cashFlows) To UBound(cashFlows)
        If cashFlows(i) &gt; 0 Then hasPositive = True
        If cashFlows(i) &lt; 0 Then hasNegative = True
    Next i
    If Not hasPositive Or Not hasNegative Then
        SafeMIRR = Null
        Exit Function
    End If
    On Error Resume Next
    SafeMIRR = MIRR(cashFlows(), finRate, reinvRate)
    If Err.Number &lt;&gt; 0 Then
        SafeMIRR = Null
    End If
    On Error GoTo 0
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 2: Convert MIRR to annualized percentage
Function AnnualizedMIRR(cashFlows() As Double, finRate As Double, _
                        reinvRate As Double, periodsPerYear As Integer) As Double
    Dim periodMIRR As Double
    periodMIRR = MIRR(cashFlows(), finRate, reinvRate)
    &#x27; Convert to effective annual rate
    AnnualizedMIRR = ((1 + periodMIRR) ^ periodsPerYear - 1) * 100
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 3: MIRR-based investment decision
Function ShouldInvest(cashFlows() As Double, finRate As Double, _
                      reinvRate As Double, hurdle As Double) As Boolean
    Dim projectMIRR As Double
    projectMIRR = MIRR(cashFlows(), finRate, reinvRate)
    ShouldInvest = (projectMIRR &gt;= hurdle)
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 4: Sensitivity analysis on rates
Sub AnalyzeMIRRSensitivity(cashFlows() As Double)
    Dim finRate As Double
    Dim reinvRate As Double
    Dim result As Double
    Debug.Print &quot;Finance Rate&quot;, &quot;Reinvest Rate&quot;, &quot;MIRR&quot;
    For finRate = 0.05 To 0.15 Step 0.01
        For reinvRate = 0.03 To 0.1 Step 0.01
            result = MIRR(cashFlows(), finRate, reinvRate)
            Debug.Print Format(finRate, &quot;0.00%&quot;), _
                       Format(reinvRate, &quot;0.00%&quot;), _
                       Format(result, &quot;0.00%&quot;)
        Next reinvRate
    Next finRate
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 5: Break-even analysis
Function BreakEvenFinanceRate(cashFlows() As Double, _
                              targetMIRR As Double, _
                              reinvRate As Double) As Double
    Dim lowRate As Double, highRate As Double
    Dim midRate As Double, testMIRR As Double
    Dim tolerance As Double
    lowRate = 0
    highRate = 1
    tolerance = 0.0001
    &#x27; Binary search for break-even rate
    Do While (highRate - lowRate) &gt; tolerance
        midRate = (lowRate + highRate) / 2
        testMIRR = MIRR(cashFlows(), midRate, reinvRate)
        If testMIRR &gt; targetMIRR Then
            lowRate = midRate
        Else
            highRate = midRate
        End If
    Loop
    BreakEvenFinanceRate = midRate
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 6: Compare MIRR to IRR
Sub CompareMIRRtoIRR(cashFlows() As Double, finRate As Double, reinvRate As Double)
    Dim irrValue As Double
    Dim mirrValue As Double
    irrValue = IRR(cashFlows())
    mirrValue = MIRR(cashFlows(), finRate, reinvRate)
    Debug.Print &quot;IRR: &quot; &amp; Format(irrValue * 100, &quot;0.00&quot;) &amp; &quot;%&quot;
    Debug.Print &quot;MIRR: &quot; &amp; Format(mirrValue * 100, &quot;0.00&quot;) &amp; &quot;%&quot;
    Debug.Print &quot;Difference: &quot; &amp; Format((irrValue - mirrValue) * 100, &quot;0.00&quot;) &amp; &quot;%&quot;
End Sub</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 7: Multi-year project evaluation
Function EvaluateMultiYearProject(initialInvestment As Double, _
                                  annualReturns() As Double, _
                                  salvageValue As Double, _
                                  finRate As Double, _
                                  reinvRate As Double) As String
    Dim cashFlows() As Double
    Dim i As Integer
    Dim years As Integer
    years = UBound(annualReturns) - LBound(annualReturns) + 1
    ReDim cashFlows(0 To years)
    cashFlows(0) = -initialInvestment
    For i = LBound(annualReturns) To UBound(annualReturns)
        cashFlows(i - LBound(annualReturns) + 1) = annualReturns(i)
    Next i
    cashFlows(years) = cashFlows(years) + salvageValue
    Dim projectMIRR As Double
    projectMIRR = MIRR(cashFlows(), finRate, reinvRate)
    EvaluateMultiYearProject = &quot;Project MIRR: &quot; &amp; _
        Format(projectMIRR * 100, &quot;0.00&quot;) &amp; &quot;%&quot;
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 8: Ranking multiple investments
Type Investment
    Name As String
    CashFlows() As Double
    MIRR As Double
End Type
Function RankInvestments(investments() As Investment, _
                        finRate As Double, _
                        reinvRate As Double) As Investment()
    Dim i As Integer, j As Integer
    Dim temp As Investment
    &#x27; Calculate MIRR for each investment
    For i = LBound(investments) To UBound(investments)
        investments(i).MIRR = MIRR(investments(i).CashFlows(), finRate, reinvRate)
    Next i
    &#x27; Bubble sort by MIRR (descending)
    For i = LBound(investments) To UBound(investments) - 1
        For j = i + 1 To UBound(investments)
            If investments(j).MIRR &gt; investments(i).MIRR Then
                temp = investments(i)
                investments(i) = investments(j)
                investments(j) = temp
            End If
        Next j
    Next i
    RankInvestments = investments
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 9: Net Present Value equivalent using MIRR
Function MIRRtoNPV(initialInvestment As Double, mirrRate As Double, _
                   periods As Integer) As Double
    &#x27; Convert MIRR back to equivalent NPV
    &#x27; Useful for comparing MIRR-based and NPV-based analyses
    MIRRtoNPV = initialInvestment * ((1 + mirrRate) ^ periods)
End Function</code></pre>
<pre><code class="language-vbnet">&#x27; Pattern 10: Quarterly to annual MIRR conversion
Function QuarterlyToAnnualMIRR(quarterlyCashFlows() As Double, _
                               quarterlyFinRate As Double, _
                               quarterlyReinvRate As Double) As Double
    Dim quarterlyMIRR As Double
    quarterlyMIRR = MIRR(quarterlyCashFlows(), quarterlyFinRate, quarterlyReinvRate)
    &#x27; Convert quarterly rate to effective annual rate
    QuarterlyToAnnualMIRR = (1 + quarterlyMIRR) ^ 4 - 1
End Function</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="example-1-investment-analysis-class">Example 1: Investment Analysis Class</h3>
<pre><code class="language-vbnet">&#x27; Class: InvestmentAnalyzer
&#x27; Provides comprehensive investment analysis using MIRR
Option Explicit
Private m_cashFlows() As Double
Private m_financeRate As Double
Private m_reinvestRate As Double
Private m_periods As Integer
Public Sub Initialize(cashFlows() As Double, finRate As Double, reinvRate As Double)
    Dim i As Integer
    m_periods = UBound(cashFlows) - LBound(cashFlows) + 1
    ReDim m_cashFlows(0 To m_periods - 1)
    For i = 0 To m_periods - 1
        m_cashFlows(i) = cashFlows(LBound(cashFlows) + i)
    Next i
    m_financeRate = finRate
    m_reinvestRate = reinvRate
End Sub
Public Function GetMIRR() As Double
    GetMIRR = MIRR(m_cashFlows(), m_financeRate, m_reinvestRate)
End Function
Public Function GetIRR() As Double
    GetIRR = IRR(m_cashFlows())
End Function
Public Function GetNPV(discountRate As Double) As Double
    GetNPV = NPV(discountRate, m_cashFlows())
End Function
Public Function GetPaybackPeriod() As Integer
    Dim cumulative As Double
    Dim i As Integer
    cumulative = 0
    For i = 0 To m_periods - 1
        cumulative = cumulative + m_cashFlows(i)
        If cumulative &gt;= 0 Then
            GetPaybackPeriod = i + 1
            Exit Function
        End If
    Next i
    GetPaybackPeriod = -1 &#x27; Never pays back
End Function
Public Function GenerateReport() As String
    Dim report As String
    report = &quot;Investment Analysis Report&quot; &amp; vbCrLf
    report = report &amp; String(40, &quot;-&quot;) &amp; vbCrLf
    report = report &amp; &quot;Periods: &quot; &amp; m_periods &amp; vbCrLf
    report = report &amp; &quot;Finance Rate: &quot; &amp; Format(m_financeRate * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    report = report &amp; &quot;Reinvest Rate: &quot; &amp; Format(m_reinvestRate * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    report = report &amp; vbCrLf
    report = report &amp; &quot;MIRR: &quot; &amp; Format(GetMIRR() * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    report = report &amp; &quot;IRR: &quot; &amp; Format(GetIRR() * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    report = report &amp; &quot;NPV @ Finance Rate: &quot; &amp; _
        Format(GetNPV(m_financeRate), &quot;$#,##0.00&quot;) &amp; vbCrLf
    report = report &amp; &quot;Payback Period: &quot; &amp; GetPaybackPeriod() &amp; &quot; periods&quot; &amp; vbCrLf
    GenerateReport = report
End Function
Public Function IsViable(hurdleRate As Double) As Boolean
    IsViable = (GetMIRR() &gt;= hurdleRate)
End Function</code></pre>
<h3 id="example-2-real-estate-investment-calculator">Example 2: Real Estate Investment Calculator</h3>
<pre><code class="language-vbnet">&#x27; Class: RealEstateInvestment
&#x27; Specialized calculator for real estate MIRR analysis
Option Explicit
Private m_purchasePrice As Double
Private m_downPayment As Double
Private m_annualRent As Double
Private m_holdingPeriod As Integer
Private m_appreciationRate As Double
Private m_mortgageRate As Double
Private m_reinvestmentRate As Double
Public Sub ConfigureInvestment(purchasePrice As Double, downPayment As Double, _
                               annualRent As Double, holdingYears As Integer, _
                               appreciation As Double)
    m_purchasePrice = purchasePrice
    m_downPayment = downPayment
    m_annualRent = annualRent
    m_holdingPeriod = holdingYears
    m_appreciationRate = appreciation
End Sub
Public Sub ConfigureRates(mortgageRate As Double, reinvestmentRate As Double)
    m_mortgageRate = mortgageRate
    m_reinvestmentRate = reinvestmentRate
End Sub
Public Function CalculateMIRR() As Double
    Dim cashFlows() As Double
    Dim i As Integer
    Dim salePrice As Double
    ReDim cashFlows(0 To m_holdingPeriod)
    &#x27; Initial investment (down payment)
    cashFlows(0) = -m_downPayment
    &#x27; Annual rental income
    For i = 1 To m_holdingPeriod - 1
        cashFlows(i) = m_annualRent
    Next i
    &#x27; Final year: rent + sale proceeds
    salePrice = m_purchasePrice * ((1 + m_appreciationRate) ^ m_holdingPeriod)
    cashFlows(m_holdingPeriod) = m_annualRent + (salePrice - (m_purchasePrice - m_downPayment))
    CalculateMIRR = MIRR(cashFlows(), m_mortgageRate, m_reinvestmentRate)
End Function
Public Function GetAnnualizedReturn() As String
    Dim mirrValue As Double
    mirrValue = CalculateMIRR()
    GetAnnualizedReturn = Format(mirrValue * 100, &quot;0.00&quot;) &amp; &quot;% per year&quot;
End Function
Public Function CompareToStocks(stockMarketReturn As Double) As String
    Dim propertyReturn As Double
    propertyReturn = CalculateMIRR()
    If propertyReturn &gt; stockMarketReturn Then
        CompareToStocks = &quot;Property investment outperforms stocks by &quot; &amp; _
            Format((propertyReturn - stockMarketReturn) * 100, &quot;0.00&quot;) &amp; &quot;%&quot;
    Else
        CompareToStocks = &quot;Stocks outperform property by &quot; &amp; _
            Format((stockMarketReturn - propertyReturn) * 100, &quot;0.00&quot;) &amp; &quot;%&quot;
    End If
End Function</code></pre>
<h3 id="example-3-project-portfolio-optimizer">Example 3: Project Portfolio Optimizer</h3>
<pre><code class="language-vbnet">&#x27; Module: PortfolioOptimizer
&#x27; Selects optimal mix of projects given budget constraint
Option Explicit
Type Project
    ID As String
    Name As String
    InitialCost As Double
    CashFlows() As Double
    MIRR As Double
    Selected As Boolean
End Type
Function OptimizePortfolio(projects() As Project, budget As Double, _
                          finRate As Double, reinvRate As Double) As Project()
    Dim i As Integer, j As Integer
    Dim totalCost As Double
    Dim temp As Project
    &#x27; Calculate MIRR for each project
    For i = LBound(projects) To UBound(projects)
        projects(i).MIRR = MIRR(projects(i).CashFlows(), finRate, reinvRate)
        projects(i).Selected = False
    Next i
    &#x27; Sort by MIRR descending (greedy approach)
    For i = LBound(projects) To UBound(projects) - 1
        For j = i + 1 To UBound(projects)
            If projects(j).MIRR &gt; projects(i).MIRR Then
                temp = projects(i)
                projects(i) = projects(j)
                projects(j) = temp
            End If
        Next j
    Next i
    &#x27; Select projects until budget exhausted
    totalCost = 0
    For i = LBound(projects) To UBound(projects)
        If totalCost + projects(i).InitialCost &lt;= budget Then
            projects(i).Selected = True
            totalCost = totalCost + projects(i).InitialCost
        End If
    Next i
    OptimizePortfolio = projects
End Function
Function GetPortfolioMIRR(projects() As Project) As Double
    Dim combinedFlows() As Double
    Dim maxPeriods As Integer
    Dim i As Integer, p As Integer
    &#x27; Find maximum periods across all selected projects
    For i = LBound(projects) To UBound(projects)
        If projects(i).Selected Then
            If UBound(projects(i).CashFlows) &gt; maxPeriods Then
                maxPeriods = UBound(projects(i).CashFlows)
            End If
        End If
    Next i
    ReDim combinedFlows(0 To maxPeriods)
    &#x27; Combine cash flows from all selected projects
    For i = LBound(projects) To UBound(projects)
        If projects(i).Selected Then
            For p = 0 To UBound(projects(i).CashFlows)
                combinedFlows(p) = combinedFlows(p) + projects(i).CashFlows(p)
            Next p
        End If
    Next i
    GetPortfolioMIRR = MIRR(combinedFlows(), 0.08, 0.05) &#x27; Example rates
End Function</code></pre>
<h3 id="example-4-monte-carlo-simulation-with-mirr">Example 4: Monte Carlo Simulation with MIRR</h3>
<pre><code class="language-vbnet">&#x27; Module: MIRRSimulation
&#x27; Performs Monte Carlo simulation on MIRR with uncertain cash flows
Option Explicit
Function SimulateMIRR(baseCashFlows() As Double, volatility As Double, _
                      finRate As Double, reinvRate As Double, _
                      simulations As Long) As Double()
    Dim results() As Double
    Dim sim As Long, i As Integer
    Dim simulatedFlows() As Double
    Dim periods As Integer
    periods = UBound(baseCashFlows) - LBound(baseCashFlows) + 1
    ReDim results(1 To simulations)
    ReDim simulatedFlows(0 To periods - 1)
    Randomize Timer
    For sim = 1 To simulations
        &#x27; Generate random cash flows based on volatility
        For i = 0 To periods - 1
            Dim randomFactor As Double
            randomFactor = 1 + (Rnd() - 0.5) * 2 * volatility
            simulatedFlows(i) = baseCashFlows(i) * randomFactor
        Next i
        On Error Resume Next
        results(sim) = MIRR(simulatedFlows(), finRate, reinvRate)
        If Err.Number &lt;&gt; 0 Then
            results(sim) = 0 &#x27; Invalid scenario
        End If
        On Error GoTo 0
    Next sim
    SimulateMIRR = results
End Function
Function AnalyzeSimulationResults(results() As Double) As String
    Dim i As Long
    Dim sum As Double, sumSq As Double
    Dim mean As Double, stdDev As Double
    Dim count As Long
    count = UBound(results) - LBound(results) + 1
    For i = LBound(results) To UBound(results)
        sum = sum + results(i)
        sumSq = sumSq + results(i) ^ 2
    Next i
    mean = sum / count
    stdDev = Sqr((sumSq / count) - (mean ^ 2))
    Dim report As String
    report = &quot;Monte Carlo MIRR Analysis&quot; &amp; vbCrLf
    report = report &amp; &quot;Simulations: &quot; &amp; count &amp; vbCrLf
    report = report &amp; &quot;Mean MIRR: &quot; &amp; Format(mean * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    report = report &amp; &quot;Std Dev: &quot; &amp; Format(stdDev * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    report = report &amp; &quot;95% Confidence Interval: &quot; &amp; _
        Format((mean - 1.96 * stdDev) * 100, &quot;0.00&quot;) &amp; &quot;% to &quot; &amp; _
        Format((mean + 1.96 * stdDev) * 100, &quot;0.00&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    AnalyzeSimulationResults = report
End Function</code></pre>
<h2 id="error-handling">Error Handling</h2>
<pre><code class="language-vbnet">On Error Resume Next
result = MIRR(cashFlows(), finRate, reinvRate)
If Err.Number = 5 Then
    MsgBox &quot;Invalid procedure call - check that cash flows &quot; &amp; _
           &quot;contain both positive and negative values&quot;
ElseIf Err.Number &lt;&gt; 0 Then
    MsgBox &quot;Error calculating MIRR: &quot; &amp; Err.Description
End If
On Error GoTo 0</code></pre>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li>MIRR calculation is iterative and can be computationally intensive for large arrays</li>
<li>Cache MIRR results if using the same cash flows repeatedly</li>
<li>For sensitivity analysis with many rate variations, consider pre-calculating once</li>
<li>Array size affects performance - MIRR on 1000 periods is slower than 10 periods</li>
<li>Consider using simplified models for real-time calculations</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li><strong>Validate inputs</strong> - Ensure array contains both positive and negative values before calling MIRR</li>
<li><strong>Use realistic rates</strong> - Finance and reinvestment rates should reflect actual market conditions</li>
<li><strong>Match rate periods</strong> - If cash flows are monthly, use monthly rates (annual rate / 12)</li>
<li><strong>Compare to hurdle rate</strong> - Set minimum acceptable MIRR based on cost of capital</li>
<li><strong>Consider risk</strong> - Higher risk projects should have higher required MIRR</li>
<li><strong>Document assumptions</strong> - Clearly state finance and reinvestment rate assumptions</li>
<li><strong>Use with other metrics</strong> - Combine MIRR with NPV, IRR, and payback period for complete analysis</li>
<li><strong>Test sensitivity</strong> - Vary rates to see how robust the investment is to assumption changes</li>
<li><strong>Account for inflation</strong> - Use real rates (adjusted for inflation) for long-term projects</li>
<li><strong>Round appropriately</strong> - Display MIRR as percentage with 2 decimal places for clarity</li>
</ol>
<h2 id="comparison-with-other-financial-functions">Comparison with Other Financial Functions</h2>
<table>
<thead>
<tr>
<th>Function</th>
<th>Purpose</th>
<th>Key Difference from MIRR</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>IRR</strong></td>
<td>Internal Rate of Return</td>
<td>Assumes reinvestment at IRR (often unrealistic); MIRR uses separate reinvestment rate</td>
</tr>
<tr>
<td><strong>NPV</strong></td>
<td>Net Present Value</td>
<td>Returns dollar amount, not percentage; uses single discount rate</td>
</tr>
<tr>
<td><strong>PV</strong></td>
<td>Present Value</td>
<td>Works with annuities/single payments, not irregular cash flows</td>
</tr>
<tr>
<td><strong>FV</strong></td>
<td>Future Value</td>
<td>Forward-looking value calculation; MIRR calculates rate of return</td>
</tr>
<tr>
<td><strong>Rate</strong></td>
<td>Interest rate for annuity</td>
<td>For regular payments only; MIRR handles irregular cash flows</td>
</tr>
</tbody>
</table>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in VBA (Excel, Access, etc.)</li>
<li>Not available in <code>VBScript</code></li>
<li>Part of VBA Financial functions library</li>
<li>Requires at least one positive and one negative value in the array</li>
<li>Arrays can be 0-based or 1-based (function handles both)</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Requires at least one positive and one negative cash flow value</li>
<li>All cash flows must occur at regular intervals</li>
<li>Does not account for irregular timing between cash flows (see XIRR for that)</li>
<li>Result is sensitive to both <code>finance_rate</code> and <code>reinvest_rate</code> assumptions</li>
<li>Cannot handle multiple sign changes as robustly as some other methods</li>
<li>First cash flow is assumed to occur at end of first period (not time zero)</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><strong>IRR</strong> - Calculate internal rate of return (assumes reinvestment at IRR)</li>
<li><strong>NPV</strong> - Calculate net present value using discount rate</li>
<li><strong>PV</strong> - Calculate present value of an investment</li>
<li><strong>FV</strong> - Calculate future value of an investment</li>
<li><strong>Rate</strong> - Calculate interest rate for an annuity</li>
<li><strong>Pmt</strong> - Calculate payment for a loan/annuity</li>
<li><strong>XIRR</strong> - IRR for irregular cash flow timing (Excel only)</li>
<li><strong>XNPV</strong> - NPV for irregular cash flow timing (Excel only)</li>
</ul>
<h2 id="vb6-parser-notes">VB6 Parser Notes</h2>
<p>MIRR is parsed as a regular function call (<code>CallExpression</code>). This module exists primarily
for documentation purposes to provide comprehensive reference material for VB6 developers
working with financial calculations involving modified internal rate of return analysis.</p>
        </article>
        
        <div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
            <p>
                <a href="index.html">← Back to Financial</a> |
                <a href="../index.html">View all functions</a>
            </p>
        </div>

    </main>

    <footer>
        <div class="container">
            <p>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>