4
A
回答
1
這是相當容易使用迭代求解器,如平分法或牛頓法。如果你的現金流C_t_j
發生在次t_j
然後內部回報率r
滿足總結j = 1
到n
的
C_t_j/(1 + r)^t_j
等於零。致電f(r)
。然後f'(r)
是n
-t_j * C_t_j/(1 + r)^(t_j+1).
現在,您可以申請牛頓的方法來解決r
總和j = 1
。
0
這是我多年前寫的一個IRR Excel宏。我無法解釋它是如何工作的,但我認爲它是正確的:
它被調用,如:= IrrCont(A8:A15,F8:F15)其中第一個範圍是日期範圍和其次是一系列的價值觀。有些值必須是正值,有些值必須是負值。
Option Explicit
'
' Internal Rate of return -- Calculation
' Returns a result (Double) or an error message (String)
Private Function IrrCalc(DateRange As Object, ValueRange As Object)
Dim i As Integer
Dim it As Integer
Dim Count As Integer
Dim u As Double
Dim time As Double
Dim d_positive As Double
Dim positive As Double
Dim d_negative As Double
Dim negative As Double
Dim sum As Double
Const epsilon As Double = 0.000001
Const iterations As Integer = 20
Dim StartTime As Double
Dim pos As Boolean
Dim neg As Boolean
Dim value As Double
Dim temp As Double
Dim delta As Double
If DateRange.Count <> ValueRange.Count Then
IrrCalc = "*** Date Range (argument 1) and Value Range " & _
"(argument 2) must contain the same number of cells. ***"
Exit Function
End If
Count = DateRange.Count
For i = 1 To Count
If ValueRange.Cells(i).value > 0 Then pos = True
If ValueRange.Cells(i).value < 0 Then neg = True
If pos And neg Then Exit For
Next i
If Not pos Or Not neg Then
IrrCalc = "*** Cannot calculate IRR: Need both income and expenditure. ***"
Exit Function
End If
StartTime = Application.Min(DateRange)
u = 0 ' Initial interest rate guess
For it = 1 To iterations
positive = 0
d_positive = 0
negative = 0
d_negative = 0
For i = 1 To Count
value = ValueRange.Cells(i).value
time = (DateRange.Cells(i).value - StartTime)/365.2425
If value > 0 Then
temp = value * Exp(u * time)
positive = positive + temp
d_positive = d_positive + temp * time
ElseIf value < 0 Then
temp = -value * Exp(u * time)
negative = negative + temp
d_negative = d_negative + temp * time
End If
Next i
delta = Log(negative/positive)/(d_negative/negative - d_positive/positive)
If Abs(delta) < epsilon Then Exit For
u = u - delta
Next it
If it > iterations Then
IrrCalc = "*** irr does not converge in " & Str(iterations) & " iterations ***"
Else
IrrCalc = u
End If
End Function
' ====================================================================================================
'
' Internal Rate of Return: Discrete interest calculation
Function IrrDiscrete(DateRange As Object, ValueRange As Object)
Dim result As Variant
result = IrrCalc(DateRange, ValueRange)
If VarType(result) = vbDouble Then
IrrDiscrete = Exp(-result) - 1#
Else
IrrDiscrete = result
End If
End Function
' ====================================================================================================
'
' Internal Rate of Return: Continuous (compounding) interest calculation
Function IrrCont(DateRange As Object, ValueRange As Object)
Dim result As Variant
result = IrrCalc(DateRange, ValueRange)
If VarType(result) = vbDouble Then
IrrCont = -result
Else
IrrCont = result
End If
End Function
0
下面是我的迭代實現,在ActionScript:
package xattam.net.math
{
public class Financial
{
public static const MAX_IRR_ITERATIONS:int = 1000;
public static function IRR(cashFlow:Array,guess:Number=0.1):Number {
var npv:Number;
var cnt:Number = 0;
do
{
npv = Financial.NPV(guess,cashFlow);
guess+= 0.001;
if(cnt > Financial.MAX_IRR_ITERATIONS) return NaN;
else cnt++;
}
while(npv > 0)
return guess;
}
public static function NPV(discountRate:Number,cashFlow:Array):Number {
var npv:Number = 0;
for(var t:int = 0; t < cashFlow.length;t++) {
npv += cashFlow[t]/Math.pow((1+ discountRate),t);
}
return npv;
}
}
}
相關問題
- 1. 好友功能和實現
- 2. Excel中的IRR計算與.NET IRR計算
- 3. 尋找準確的Ruby,Javascript或R Excel RATE()或IRR()函數實現
- 4. opencv實現的Java fillConvexPoly和approxPolyDP功能
- 5. 實現parallel_for_each功能
- 6. 實現`distrib`功能
- 7. OpenCV的(功能未實現)
- 8. 的功能實現爲lambda
- 9. 的.bashrc功能實現grepall
- 10. 邏輯功能簡化和實現
- 11. ASP.NET - 實現搜索功能和SQL
- 12. 流行功能和鏈表實現
- 13. VB-新的VB Excel
- 14. VB循環和Excel
- 15. 如何實現類似於Microsoft Excel的「記錄宏」功能?
- 16. 使用JTable實現少量的Excel功能
- 17. VB到C#的功能
- 18. R和MS Excel之間IRR計算的不同結果
- 19. 實施Excel的小計功能
- 20. 實現根計算功能
- 21. 實現搖回家功能
- 22. Python實現吊頸功能
- 23. 實現matlab查找功能
- 24. 實現地圖功能
- 25. 實現「更新」功能
- 26. 實現搜索功能sailsjs
- 27. iOS APNs功能實現
- 28. 實現咖喱功能
- 29. 實現註銷功能
- 30. 實現超時功能/塊
你基本上暴力破解的解決方案。解決這個問題有更高效和更可靠的方法。我在迴應中概述了一個。 – jason 2009-02-10 03:12:36