如何查看Microsoft.Visualbasic.Financial.IRR的源代码?

时间:2012-03-07 08:17:09

标签: vb.net visual-studio class dll

我希望看到Microsoft.Visualbasic.Financial.IRR的源代码。

如何反编译以查看财务类IRR method的源代码?

System{" df -k | awk '{sum += $4 }i; END {print sum} '"};
上面的

无效

我尝试使用不同的软件查看它,但它对我不起作用。有没有可以查看源代码的软件?

4 个答案:

答案 0 :(得分:2)

我已使用ILSpyfree)来反编译Microsoft.Visualbasic.Financial.IRR类型及其方法IRR

' Microsoft.VisualBasic.Financial
Public Shared Function IRR(ByRef ValueArray As Double(), Optional Guess As Double=0.1) As Double
    Dim upperBound As Integer
    Try
        upperBound = ValueArray.GetUpperBound(0)
    Catch ex As StackOverflowException
        Throw ex
    Catch ex2 As OutOfMemoryException
        Throw ex2
    Catch ex3 As ThreadAbortException
        Throw ex3
    Catch ex_1B As Exception
        Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", New String()() = { "ValueArray" }))
    End Try
    ' The following expression was wrapped in a checked-expression
    Dim num As Integer = upperBound + 1
    If Guess <= -1.0 Then
        Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", New String()() = { "Guess" }))
    End If
    If num <= 1 Then
        Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", New String()() = { "ValueArray" }))
    End If
    Dim num2 As Double
    If ValueArray(0) > 0.0 Then
        num2 = ValueArray(0)
    Else
        num2 = -ValueArray(0)
    End If
    Dim arg_BF_0 As Integer = 0
    Dim num3 As Integer = upperBound
    Dim i As Integer
    ' The following expression was wrapped in a checked-expression
    i = arg_BF_0
    While i <= num3
        If ValueArray(i) > num2 Then
            num2 = ValueArray(i)
        Else
            If-ValueArray(i) > num2 Then
                num2 = -ValueArray(i)
            End If
        End If
        i = i + 1
    End While
    Dim num4 As Double = num2 * 1E-07 * 0.01
    Dim num5 As Double = Guess
    Dim num6 As Double = Financial.OptPV2(ValueArray, num5)
    Dim num7 As Double
    If num6 > 0.0 Then
        num7 = num5 + 1E-05
    Else
        num7 = num5 - 1E-05
    End If
    If num7 <= -1.0 Then
        Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", New String()() = { "Rate" }))
    End If
    Dim num8 As Double = Financial.OptPV2(ValueArray, num7)
    i = 0
    While True
        If num8 = num6 Then
            If num7 > num5 Then
                num5 -= 1E-05
            Else
                num5 += 1E-05
            End If
            num6 = Financial.OptPV2(ValueArray, num5)
            If num8 = num6 Then
                Exit While
            End If
        End If
        num5 = num7 - num7 - num5 * num8 / num8 - num6
        If num5 <= -1.0 Then
            num5 = num7 - 1.0 * 0.5
        End If
        num6 = Financial.OptPV2(ValueArray, num5)
        If num5 > num7 Then
            num2 = num5 - num7
        Else
            num2 = num7 - num5
        End If
        Dim num9 As Double
        If num6 > 0.0 Then
            num9 = num6
        Else
            num9 = -num6
        End If
        If num9 < num4 AndAlso num2 < 1E-07 Then
            Return num5
        End If
        num2 = num6
        num6 = num8
        num8 = num2
        num2 = num5
        num5 = num7
        num7 = num2
        ' The following expression was wrapped in a checked-statement
        i += 1
        If i > 39 Then
            GoTo Block_17
        End If
    End While
    Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue"))
    Block_17:
    Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue"))
End Function

答案 1 :(得分:2)

虽然我意识到这个问题很老,但基于观点的数量,我相信还有很多人在寻找这个。现在Reference Source is available, we can view this method directly

'-------------------------------------------------------------
'
'  Name                      : IRR
'  Purpose                   : This function uses an iterative procedure to find
'                              the Internal Rate of Return of an investment.  The algorithm
'                              basically uses the secant method to find a rate for which the
'                              NPV of the cash flow is 0.
'                              This function raises an exception if the parameters are invalid.
'
'                              This routine uses a slightly different version of the secant
'                              routine in Rate.  The basic changes are:
'                                   - uses LDoNPV to get the 'Y-value'
'                                   - does not allow Rate to go below -1.
'                                      (if the Rate drops below -1, it is forced above again)
'                                   - has a double condition for termination:
'                                      NPV = 0 (within L_IT_EPSILON)
'                                      Rate1 - Rate0  approaches zero (rate is converging)
'                                   This last does not parallel Excel, but avoids a class of
'                                   spurious answers.  Otherwise, performance is comparable to
'                                   Excel's, and accuracy is often better.
'
'  Returns                   : Double
'
'-------------------------------------------------------------
'
Public Function IRR(ByRef ValueArray() As Double, Optional ByVal Guess As Double = 0.1) As Double

    Dim dTemp As Double
    Dim dRate0 As Double
    Dim dRate1 As Double
    Dim dNPv0 As Double
    Dim dNpv1 As Double
    Dim dNpvEpsilon As Double
    Dim dTemp1 As Double
    Dim lIndex As Integer
    Dim lCVal As Integer
    Dim lUpper As Integer

    'Compiler assures that rank of ValueArray is always 1, no need to check it.  
    'WARSI Check for error codes returned by UBound. Check if they match with C code
    Try   'Needed to catch dynamic arrays which have not been constructed yet.
        lUpper = ValueArray.GetUpperBound(0)
    Catch ex As StackOverflowException
        Throw ex
    Catch ex As OutOfMemoryException
        Throw ex
    Catch ex As System.Threading.ThreadAbortException
        Throw ex
    Catch
        Throw New ArgumentException(GetResourceString(ResID.Argument_InvalidValue1, "ValueArray"))
    End Try

    lCVal = lUpper + 1

    'Function fails for invalid parameters
    If Guess <= (-1.0#) Then
        Throw New ArgumentException(GetResourceString(ResID.Argument_InvalidValue1, "Guess"))
    End If

    If lCVal <= 1 Then
        Throw New ArgumentException(GetResourceString(ResID.Argument_InvalidValue1, "ValueArray"))
    End If

    'We scale the epsilon depending on cash flow values. It is necessary
    'because even in max accuracy case where diff is in 16th digit it
    'would get scaled up.
    If ValueArray(0) > 0.0# Then
        dTemp = ValueArray(0)
    Else
        dTemp = -ValueArray(0)
    End If

    For lIndex = 0 To lUpper
        'Get max of values in cash flow
        If ValueArray(lIndex) > dTemp Then
            dTemp = ValueArray(lIndex)
        ElseIf (-ValueArray(lIndex)) > dTemp Then
            dTemp = -ValueArray(lIndex)
        End If
    Next lIndex

    dNpvEpsilon = dTemp * cnL_IT_EPSILON * 0.01

    'Set up the initial values for the secant method
    dRate0 = Guess
    dNPv0 = OptPV2(ValueArray,dRate0)

    If dNPv0 > 0.0# Then
        dRate1 = dRate0 + cnL_IT_STEP
    Else
        dRate1 = dRate0 - cnL_IT_STEP
    End If

    If dRate1 <= (-1.0#) Then
        Throw New ArgumentException(GetResourceString(ResID.Argument_InvalidValue1, "Rate"))
    End If

    dNpv1 = OptPV2(ValueArray, dRate1)

    For lIndex = 0 To 39
        If dNpv1 = dNPv0 Then
            If dRate1 > dRate0 Then
                dRate0 = dRate0 - cnL_IT_STEP
            Else
                dRate0 = dRate0 + cnL_IT_STEP
            End If
            dNPv0 = OptPV2(ValueArray, dRate0)
            If dNpv1 = dNPv0 Then
                Throw New ArgumentException(GetResourceString(ResID.Argument_InvalidValue))
            End If
        End If

        dRate0 = dRate1 - (dRate1 - dRate0) * dNpv1 / (dNpv1 - dNPv0)

        'Secant method of generating next approximation
        If dRate0 <= (-1.0#) Then
            dRate0 = (dRate1 - 1.0#) * 0.5
        End If

        'Basically give the algorithm a second chance. Helps the
        'algorithm when it starts to diverge to -ve side
        dNPv0 = OptPV2(ValueArray, dRate0)
        If dRate0 > dRate1 Then
            dTemp = dRate0 - dRate1
        Else
            dTemp = dRate1 - dRate0
        End If

        If dNPv0 > 0.0# Then
            dTemp1 = dNPv0
        Else
            dTemp1 = -dNPv0
        End If

        'Test : npv - > 0 and rate converges
        If dTemp1 < dNpvEpsilon AndAlso dTemp < cnL_IT_EPSILON Then
            Return dRate0
        End If

        'Exchange the values - store the new values in the 1's
        dTemp = dNPv0
        dNPv0 = dNpv1
        dNpv1 = dTemp
        dTemp = dRate0
        dRate0 = dRate1
        dRate1 = dTemp
    Next lIndex

    Throw New ArgumentException(GetResourceString(ResID.Argument_InvalidValue))
End Function

答案 2 :(得分:0)

你可以用.NET Reflector做到这一点,它适用于visual basic。 你有30天的试用期

答案 3 :(得分:0)

当您调用它时,是否要在调试器中单步执行原始Microsoft源代码?

易。您可以set up Visual Studio根据需要自动下载源代码,以便您可以进入它,检查变量,设置断点等。Instructions