XNPV
function XNPV(arg1: any = null, arg2: any = null, arg3: any = null): number | string | boolean
Description
Returns the net present value for a schedule of cash flows.
Parameters
- arg1
any
null Is the discount rate to apply to the cash flows.
- arg2
any
null Is a series of cash flows that correspond to a schedule of payments in dates.
- arg3
any
null Is a schedule of payment dates that corresponds to the cash flow payments.
Returns
number | string | boolean
Try It
var oWorksheet = Api.GetActiveSheet();
var oFunction = Api.GetWorksheetFunction();
oWorksheet.GetRange("A1").SetValue("Rate");
oWorksheet.GetRange("A2").SetValue(0.05);
var payment = ["Payment/Income", -10000, 500, 5000, 3000];
var dates = ["Payment dates", "1/1/2018", "4/1/2018", "8/1/2018", "12/1/2018"];
for (var i = 0; i < payment.length; i++) {
oWorksheet.GetRange("B" + (i + 1)).SetValue(payment[i]);
}
for (var j = 0; j < dates.length; j++) {
oWorksheet.GetRange("C" + (j + 1)).SetValue(dates[j]);
}
oWorksheet.GetRange("C1").SetColumnWidth(15);
var oRange1 = oWorksheet.GetRange("B2:B5");
var oRange2 = oWorksheet.GetRange("C2:C5");
oWorksheet.GetRange("D5").SetValue(oFunction.XNPV(0.05, oRange1, oRange2));