最近贷款买了一件商品,贷款前商家说年利率只要 3.11%
,看着确实挺低的,但后面发现由于是分期,综合年利率其实并不低。
买的这件商品共分 36
期,每期偿还相等的金额,即:假设贷款金额是
A
A
A 元,每期应偿还:
A
+
A
∗
0.0311
∗
3
36
\frac{A+A*0.0311*3}{36}
36A+A∗0.0311∗3那么请问综合年利率大概是多少?下面就尝试算一算。
假设,贷款金额为
A
A
A 元,综合年利率为
x
x
x,第
i
i
i 期偿还的金额为:
y
y
y(每期等额),其中本金为:
w
(
i
)
w(i)
w(i),利息为:
v
(
i
)
v(i)
v(i),则有以下几个等式:
y
=
A
+
A
∗
0.0311
∗
3
36
(1)
\tag{1} y = \frac{A+A*0.0311*3}{36}
y=36A+A∗0.0311∗3(1)
y
=
w
(
i
)
+
v
(
i
)
(2)
\tag{2} y = w(i) + v(i)
y=w(i)+v(i)(2)
v
(
i
)
=
(
A
−
∑
j
=
1
i
−
1
w
(
j
)
)
∗
x
12
(3)
\tag{3} v(i) = (A-\sum_{j=1}^{i-1}w(j)) * \frac{x}{12}
v(i)=(A−j=1∑i−1w(j))∗12x(3)
∑
i
=
1
36
v
(
i
)
=
A
∗
0.0311
∗
3
(4)
\tag{4}\sum_{i=1}^{36}v(i) = A * 0.0311 * 3
i=1∑36v(i)=A∗0.0311∗3(4)
已知上述 4
个等式,求:
x
x
x ?
数学功底比较差,虽然列出式子,但不知道如何计算 😦 。只能手动编写以下程序求
(
3
)
(3)
(3) 式中的
x
x
x,基本原理是:假设综合年利率在 0.0311
(商家说的年利率)到 0.1
(估计不会超过 10%
)之间,那么可以从 [0.0311, 0.1]
之间均匀选取 1000
个点,再从这 1000
个点中选取一个使
(
4
)
(4)
(4) 式左右两端误差最小的
x
x
x 值。仔细观察上面几个式子,可以发现在
(
4
)
(4)
(4) 式展开后,等式两端可以同时约掉贷款本金,也就是说,贷款本金与综合年利率没有关系,下面代码中假设贷款本金为 100000。代码如下所示:
#include
#define A 100000
#define CANDIDATE_MAX_NUM 1000
struct candidate {
double rate;
double result;
double diff;
};
double abs_double(double num)
{
return num >= 0 ? num : -num;
}
double v_sum(double rate)
{
double y = (A + A * 0.0311 * 3) / 36;
double vi, wi, w_sum = 0, _v_sum = 0;
int i = 0;
for (i = 1; i <= 36; ++i) {
vi = (A - w_sum) * rate * 1 / 12;
wi = y - vi;
w_sum += wi;
_v_sum += vi;
}
return _v_sum;
}
void calc(void)
{
double min = 0.0311;
double max = 0.1000;
double step = (max - min) / CANDIDATE_MAX_NUM;
double r = min;
struct candidate cand = {0, 0, 0};
double target = A * 0.0311 * 3;
double result, diff;
int i = 0;
for (i = 0; i < CANDIDATE_MAX_NUM; ++i) {
result = v_sum(r);
diff = abs_double(result - target);
if (i == 0 || diff < cand.diff) {
cand.rate = r;
cand.result = result;
cand.diff = diff;
}
r += step;
}
printf("rate = %lf, result = %lf, target = %lf, diff = %lf\n",
cand.rate, cand.result, target, cand.diff);
}
int main(void)
{
calc();
return 0;
}
程序运行结果如下:
[zhoumin@localhost]$ ./main
rate = 0.058867, result = 9334.592459, target = 9330.000000, diff = 4.592459
由上面的运行结果可知,计算出的综合年利率
x
x
x 为 5.88%
,比商家所说的年利率高了不少,这样来看,分期付款的综合年利率其实并不低。