本文主要是介绍计算免息分期的收益 及 年金/复利现值终值的理解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天有朋友问到他买的手机分几期合适,于是写了代码帮他计算免息分期具体能带来多少收益。
比如,10000的手机,选择24期免息分期,把这些钱买成银行年利率3.9%的理财,那么相比较于不分期,两年的收益率是多少。
上代码:
#include<iostream>
#include<Windows.h>
using namespace std;
double CalcEarning(int periods, double totalAmount, double depositAnnualRate, double installmentRateofEachPeriod = 0.0)
{double totalEarning = 0.0;double curAmount = totalAmount;double curMonthEarning = 0.0;for (int i = 0; i < periods; i++){curMonthEarning = curAmount * depositAnnualRate / 12;//220816感谢cby的提醒,此处应加上每月的利息计算复利 curAmount = curAmount- totalAmount / periods + curMonthEarning;totalEarning += curMonthEarning;}return totalEarning;
}void main()
{cout << CalcEarning(24, 10000, 0.039) << endl; //427.048cout << CalcEarning(12, 10000, 0.039) << endl; //216.347cout << CalcEarning(6, 10000, 0.039) << endl; //114.988cout << CalcEarning(3, 10000, 0.039) << endl; //65.282system("pause");
}
代码很简单,可直接编译,参数名和语句应该好懂吧。
输出就是收益。
朋友是学会计的,说跟年金复利现值终值这些概念很像,顺便研究了一下。
整理下知识碎片:
按照年利率10%,3年期表示.
1.复利现值:
200*(P/F,10%,3)
翻译:希望在三年后取出200万元,那么今天应该存入多少钱?
2.复利终值:
200*(F/P,10%,3)
翻译:这个很好理解,现在存入200万元,三年后值多少钱。
3.年金现值
翻译:我是租客,每年付1w元给房东,租三年,我准备现在一次性凑齐然后放在银行里边买着理财边付房租,那么我需要准备多少钱。
4.年金终值
翻译:我是房东,把房子租出去三年,我每年会收到1w元房租,那么三年后我会有多少钱。
这个其实算的是期初年金终值,因为房租会在每年年初收到。
如果是每年年末才收到房租,那算出来就是期末年金终值 。
这篇关于计算免息分期的收益 及 年金/复利现值终值的理解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!