如何在Google表格中计算现值(PV)? [英] How is present value (PV) calculated on Google Sheets?

查看:129
本文介绍了如何在Google表格中计算现值(PV)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google表格上的PV公式可以包含3、4或5个参数.我正在尝试在JavaScript中给定参数的情况下计算当前值,但似乎无法弄清或找到Google表格正在使用的公式.

The PV formula on Google Sheets can take 3, 4, or 5 parameters. I am trying to calculate the present value given the parameters in JavaScript but cannot seem to figure out or find the formula that Google Sheets is using.

当前传递给该函数的参数为​​=PV(.00115, 7.57, $66.88),该函数的输出为$ 503.89.这是如何计算的?我需要在JavaScript中复制此公式,或者找到某种类型的函数库,该函数将为我执行此操作.

The parameters being passed into the function are currently =PV(.00115, 7.57, $66.88) and the output from the function is $503.89. How is this being calculated? I need to either replicate this formula in JavaScript or find some type of library with a function that will do this for me.

推荐答案

咨询 Wikipedia 我想出了这个函数,它将与内置的PV返回相同的结果.通过将其作为自定义函数输入并向其抛出一些随机值进行测试.

After consulting Wikipedia I came up with this function, which returns identical result to built-in PV. Tested by entering it as a custom function and throwing some random values at it.

function myPV(rate, num, amount, remain, type) {
  if (type == 0) {
    var factor = (rate == 0 ? num : (1 - Math.pow(1+rate, -num))/rate);
    return -amount*factor - remain * Math.pow(1+rate, -num);
  }
  else {
    var factor = (rate == 0 ? num : (1 - Math.pow(1+rate, -num))*(1+rate)/rate);
    return -amount*factor - remain * Math.pow(1+rate, -num);
  }
}

经过优化和现代化:

/**
 * @param {number} rate - interest rate
 * @param {number} num - number of payments
 * @param {number} amount - payment amount
 * @param {number} remain - final value
 * @param {number} type - 0 for end-of-period payments, 1 for start-of-period payments
*/
function myPV(rate, num, amount, remain, type) {
  let factor;

  if (type == 0) {
    factor = (rate == 0 ? num : (1 - Math.pow(1+rate, -num))/rate);
  } else {
    factor = (rate == 0 ? num : (1 - Math.pow(1+rate, -num))*(1+rate)/rate);
  }

  return -amount*factor - remain * Math.pow(1+rate, -num);
}

这篇关于如何在Google表格中计算现值(PV)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆