I need help with my code. Rather than repost everything here, please visit my posting over here which is unresolved. It contains the code which works and here below is the link to the FFEIC tool used to audit banks in the USA. There is a downloadable pdf document via the help link on the tool which shows the math involved for the "general equation". It's at the bottom of the document and the simple example is on page 6. My code has to compute the exact same apr as this tool. See my post and how I tried to add an outer loop. I'm using arrays to store the payments and number of payments.
https://[DELETED]/examtools/FFIEC-Calculators/APR/#/accountdata
See my posting at this forum here. The code is posted here and this is unresolved for me.
https://[DELETED]/showthread.php?898042-Need-to-modify-code-to-compute-annual-percentage-rate-(APR)&p=5583132#post5583132
Public Overridable Function generalEquation1(ByVal period As Integer, ByVal numpmts As ArrayList, ByVal payment As ArrayList, ByVal initialPeriods As Double, ByVal fractions As Double, ByVal rate As Double) As Double
Dim retval As Double = 0
Dim x As Integer = 0
Dim z As Integer = 0
For y = 0 To numpmts.Count - 1
For x = 0 To numpmts(y)
If x = numpmts(y) Then
x = 0
Exit For
End If
retval += payment(y) / ((1.0 + fractions * rate) * Math.Pow(1 + rate, initialPeriods + x))
z = z + 1
Next x
Next y
Return retval
End Function
Public Overridable Function findAPRGEQ1(ByVal amount As Double, ByVal payment As ArrayList, ByVal payments As ArrayList, ByVal ppy As Double, ByVal APRGuess As Double, ByVal odddays As Double, ByVal full As Double) As Double
Dim result As Double = APRGuess
Dim tempguess As Double = APRGuess
Dim totpmts As Integer = 0
Dim info As Decimal = 0
For i = 0 To payments.Count - 1
totpmts += payments(i)
Next
Do
result = tempguess
Dim i As Double = tempguess / (100 * ppy)
Dim A1 As Double = generalEquation1(totpmts, payments, payment, full, odddays, i)
Dim i2 As Double = (tempguess + 0.1) / (100 * ppy)
Dim A2 As Double = generalEquation1(totpmts, payments, payment, full, odddays, i2)
tempguess = tempguess + 0.1 * (amount - A1) / (A2 - A1)
Console.Write(tempguess)
info = Math.Abs(result * 10000 - tempguess * 10000) > 1
Loop While Math.Abs(result * 10000 - tempguess * 10000) > 1
Return result
End Function
What I have tried:
added outer loop. See original code and my modified code at the link provided.