Overview
Basic present value calculations often assume that there is a sinlge rate that can applied to cash flows at any time.
The reality is more complex. Rather, the rate that needs to be applied is determined by the current interest rate curve. That is, for each cash flow in a series, a different rate is applied based on the date of the cash flow. The rate applied is taken from the zero coupon rate curve, or the discount curve.
Discount Curve
AS a general rule, cash flows that occur on different dates should have a different discount rate applied.
The typical way to model this situation is to have a function which accepts a date (or a time period) that indicates when a cash flow occurs, and returns either a rate or a discount. Then, for each cash flow, retrieve the appropriate rate before calculating the present value.
function curve(time){
//return the appropriate discount rate
}
let presentValue = 0;
let cashFlows = [{ time:1.0, value:100 }, {time:1.5, value}];
for(let cashFlow of cashFlows) {
presentValue += cashFlow.value * Math.exp(-1*rate(cashFlow.time)*cashFlow.time);
}