贷款50000 分12期 每期4247 每月利息80.3 一共连本带息50964
年利率多少?
C#计算
using System;
class Program
{
static void Main()
{
double loanAmount = 50000;
double[] cashFlows = new double[13];
cashFlows[0] = -loanAmount;
for (int i = 1; i <= 12; i++)
{
cashFlows[i] = 4247;
}
double monthlyRate = CalculateIRR(cashFlows);
double annualRate = Math.Pow(1 + monthlyRate, 12) - 1;
Console.WriteLine($"年利率为: {annualRate * 100:F2}%");
Console.ReadKey();
}
static double CalculateIRR(double[] cashFlows, double guess = 0.1)
{
double x0 = guess;
double x1 = 0;
double tolerance = 1e-6;
int maxIterations = 1000;
int iteration = 0;
while (iteration < maxIterations)
{
double fValue = 0;
double fDerivative = 0;
for (int i = 0; i < cashFlows.Length; i++)
{
fValue += cashFlows[i] / Math.Pow(1 + x0, i);
fDerivative += -i * cashFlows[i] / Math.Pow(1 + x0, i + 1);
}
x1 = x0 - fValue / fDerivative;
if (Math.Abs(x1 - x0) < tolerance)
{
break;
}
x0 = x1;
iteration++;
}
return x1;
}
}
也不算很低吧
- 本文固定链接: https://bono504.com/?p=225
- 转载请注明: bono 于 bono504 技术生活站点 发表
《贷款利率》有 2 条评论