Hi All
I have spent quite some time trying to convert:
[pre]
[/pre]
But I just work out how to get it to work. If someone is able to take a look that would be great. It is meant to calculate the interest rate
Cheers
Shaun
I have spent quite some time trying to convert:
[pre]
Code:
min_rate = 0; max_rate = 100; # Set Maximum and minimum rate
while (min_rate < max_rate - 0.0001)
{
mid_rate = (min_rate + max_rate) / 2; # Divide by 2 to find midpoint
J = mid_rate / 1200; # Convert to monthly decimal percentage
# calculate payment based on this interest, term of F and loan_amt
guessed_pmt = loan_amt * ( J / (1 - (1 + J) ** -N ));
if (guessed_pmt > actual_payment)
{
max_rate = mid_rate; # current rate is new maximum
}
else
{
min_rate = mid_rate; # current rate is new minimum
}
}
print " The Rate is ", mid_rate;
for use in VBA but I am just having no luck. What I have so far is:
Sub Interest_Rate()
Dim min_rate As Single
Dim max_rate As Single
Dim mid_rate As Single
Dim J As Single
Dim N As Single
Dim guessed_pmt As Single
Dim loan_amount As Single
Dim actual_pmt As Single
loan_amount = 32520
N = 48
min_rate = 0
max_rate = 100
actual_pmt = 583.25
Debug.Print loan_amount; N; min_rate; max_rate; actual_pmt
Do Until guessed_pmt = actual_pmt
mid_rate = (min_rate + max_rate) / 2
Debug.Print mid_rate
J = mid_rate / 1200
Debug.Print J
guessed_pmt = loan_amount * (J / (1 - (1 + J) ^ -N))
If guessed_pmt > actual_pmt Then
Debug.Print guessed_pmt; actual_pmt
max_rate = mid_rate
Else
min_rate = mid_rate
End If
Loop
ActiveSheet.Range("$G$9") = mid_rate * 1200
End Sub
But I just work out how to get it to work. If someone is able to take a look that would be great. It is meant to calculate the interest rate
Cheers
Shaun