【发布时间】:2020-02-25 08:50:40
【问题描述】:
我目前正在尝试将 google 表格中的方程式转换为 Javascript,但我得到了不同的结果。
我正在尝试从 here 复制以下公式:
原始方程式:
F = P*(1+rate)^nper + A*( ((1+rate)^nper - 1)/rate )
这是我目前拥有的:(在我的实际代码中,sn-p 下面的变量名称不同)
v = ((p*(Math.pow((1+rate),nper))) + (A*(Math.pow((1+rate),nper - 1))/rate));
来自原始网站的额外信息:
r = 名义年利率(小数)
n = 每年的复利期数
p = 每年的付款期数
费率 = 每个付款期的费率
nper = 付款期总数
A = 在每个付款期结束时添加到本金的金额
率 = ((1+r/n)^(n/p))-1
nper = p * t
总付款 = A*nper
总利息 = F - P - 总付款
完整上下文(我的 Vue 代码):
var app = new Vue({
el: '#app',
data: {
principal: 0,
interest_rate: 0,
time_invested: 0,
additional_investment: 0,
additional_investment_frequency : 1,
options: {
additional_investment_frequency: {
"1": "Yearly",
"12": "Monthly",
"26": "Fortnightly",
"52": "Weekly",
"365": "Daily"
}
},
compound_frequency : 1,
options: {
compound_frequency: {
"1": "Yearly",
"12": "Monthly"
}
}
},
methods:{
},
computed: {
total_pay_periods: function () {
// calculate total number of pay periods
total_pay_periods = parseFloat(this.additional_investment_frequency) * parseFloat(this.time_invested);
return parseFloat(this.additional_investment_frequency) * parseFloat(this.time_invested);
},
total_additional_investment: function () {
// calculate total number of pay periods
total_pay_periods = parseFloat(this.additional_investment_frequency) * parseFloat(this.time_invested);
// times total pay periods by additional investment installment amount to get overall total additional investment
return parseFloat(this.additional_investment) * total_pay_periods;
},
rate: function () {
ir = parseFloat(this.interest_rate) / 100;
cf = parseFloat(this.compound_frequency);
aif = parseFloat(this.additional_investment_frequency);
return (Math.pow((1+ir/cf),(cf/aif))-1);
// return (((1+ir/cf)^(cf/aif))-1);
},
future_value: function () {
p = parseFloat(this.principal);
r = parseFloat(this.rate);
tpp = parseFloat(this.total_pay_periods);
ai = parseFloat(this.additional_investment);
// F = P*(1+rate)^nper + A*( ((1+rate)^nper - 1)/rate )
// https://www.vertex42.com/Calculators/compound-interest-calculator.html#rate-per-period
// calculate final future value
v = ((p*(Math.pow((1+r),tpp))) + (ai*(Math.pow((1+r),tpp - 1))/r));
// convert to 2 decimal places
return v.toFixed(2);
}
}
})
【问题讨论】:
标签: javascript vue.js math calculator