我正在尝试编写一个脚本,其中用户插入每月收入并获得 30 年后复利的未来价值。现在,我已经分配了一些值用于测试目的。
// Future Value
var investment = 800;
var annualRate = 2;
var monthlyRate = annualRate / 12 / 100;
var years = 30;
var months = years * 12;
var futureValue = 0;
for ( i = 1; i <= months; i++ ) {
futureValue = futureValue + investment * Math.pow(1 + monthlyRate, months);
}
问题是,我实际上是从一个使用内置 FV() 公式的 Excel 电子表格构建的,当交叉检查时,我的结果完全不对...知道我做错了什么,因为我不喜欢根本没有金融数学。提前致谢。
The Math.pow
是不必要的,因为您正在计算和递增futureValue
逐月。只需乘以1 + monthlyRate
。您还需要在相乘之前将投资的当前价值添加到新投资中:
for ( i = 1; i <= months; i++ ) {
futureValue = (futureValue + investment) * (1 + monthlyRate);
}
或者,您也可以使用以下公式一次性计算:
futureValue = investment * (Math.pow(1 + monthlyRate, months) - 1) / monthlyRate;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)