Financial.Rate Cannot calculate rate using the arguments provided

G

Guest

I'm getting this error when running this program:
Cannot calculate rate using the arguments provided

Module Module1

Sub Main()

Rate(360, -694.44444444444446, 244274.69178082192)
End Sub

End Module

This is a vb console application, has anybody seen this before? how can I
fix this?
 
L

Larry Lard

Programador said:
I'm getting this error when running this program:
Cannot calculate rate using the arguments provided

Module Module1

Sub Main()

Rate(360, -694.44444444444446, 244274.69178082192)
End Sub

End Module

This is a vb console application, has anybody seen this before? how can I
fix this?

There is an indispensible .NET tool called Reflector (first result on
google for that word), which disassembles the CLR into your choice of
VB.NET or C#. If you ever need to know what the Framework is doing, or
how it does it, it should be your first port of call. This is its
output when asked to examine the Microsoft.VisualBasic.Financial.Rate
function:

Public Shared Function Rate(ByVal NPer As Double, ByVal Pmt As Double,
ByVal PV As Double, ByVal FV As Double = 0, ByVal Due As DueDate = 0,
ByVal Guess As Double = 0.1) As Double
Dim num2 As Double
If (NPer <= 0) Then
Throw New
ArgumentException(Utils.GetResourceString("Rate_NPerMustBeGTZero"))
End If
Dim num1 As Double = Guess
Dim num4 As Double = Financial.LEvalRate(num1, NPer, Pmt, PV, FV,
Due)
If (num4 > 0) Then
num2 = (num1 / 2)
Else
num2 = (num1 * 2)
End If
Dim num5 As Double = Financial.LEvalRate(num2, NPer, Pmt, PV, FV,
Due)
Dim num6 As Integer = 0
Do While True
If (num5 = num4) Then
If (num2 > num1) Then
num1 = (num1 - 1E-05)
Else
num1 = (num1 - -1E-05)
End If
num4 = Financial.LEvalRate(num1, NPer, Pmt, PV, FV,
Due)
If (num5 = num4) Then
Throw New
ArgumentException(Utils.GetResourceString("Financial_CalcDivByZero"))
End If
End If
num1 = (num2 - (((num2 - num1) * num5) / (num5 - num4)))
num4 = Financial.LEvalRate(num1, NPer, Pmt, PV, FV, Due)
If (Math.Abs(num4) < 1E-07) Then
Return num1
End If
Dim num3 As Double = num4
num4 = num5
num5 = num3
num3 = num1
num1 = num2
num2 = num3
num6 += 1
If (num6 > 39) Then
Throw New
ArgumentException(Utils.GetResourceString("Financial_CannotCalculateRate"))
End If
Loop
End Function


Now, since I know less than nothing about the purpose of this function,
or the meaning of the arguments, I can't say what is going wrong or
why. It looks like the loop in the second part of the function is
repeatedly run until num4 is very close to zero, and if this doesn't
happen within 40 iterations, the Exception you saw is thrown.
Presumably some kind of iterative solution is taking place, and the
fact that it doesn't converge in 40 iterations is used as a signal that
there is no solution.

At any rate, you should be able at the very least to now step through
this code yourself and work out what is going wrong.
 
C

Claes Bergefall

From the docs:

"Rate is calculated by iteration. Starting with the value of Guess, Rate
cycles through the calculation until the result is accurate to within
0.00001 percent. If Rate cannot find a result after 20 tries, it fails. If
your guess is 10 percent and Rate fails, try a different value for Guess"

Provide a different value for the Guess parameter (default is 0.1).
0.01 seems to be working for those particular parameters

/claes
 
D

Don

How can you have a payment of -694.44444444444446 or a balance of
244274.69178082192? Just curious. As far as I know, US Dollars have to
be paid in increments of .01. At least the mortgage companies I've
worked at for over 20 years have required it that way. I don't think
their servicing software will accept payments down to one trillionith
of a penny anyway.

I can't think of any real world scenario where that would make sense,
and, it will return non-sense results for your Rate calculation.

If you round your figures to the nearest penny your function should
not only work but should also return an accurate rate.

Regards,

Don
 
J

Jim Hughes

I have come across several instances where financial calculations use 4
decimal places until the final result is rounded to 2 decimal places.

One example is fuel e.g. 1.8990 per gallon
 
D

Don

The mathematical formula for calculating the periodic payment required
to amortize an amount will result in a theoretical payment amount.
E.g. -694.44444444444446 as in the original post.

Using that figure in the Rate calculation will give an equally
theoretical result. Try to give the gas station attendant 9.495 for 5
gallons of gas at 1.899 per gallon.

As I said:

"As far as I know, US Dollars have to be **PAID** in increments of
..01."

My post wasn't meant to be as strident as it may have sounded.

Regards,

Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top