# Numerical algorithm to calculate stream of discounted cash flows

Is it possible to calculate the flow of cash in each period given a certain fixed net present value with a numerical algorithm?

I would like to be able to apply a certain weighting that can be applied to the cash flows of each period e.g. 90% will be paid back in the last period, 1/(number of periods-1) in all other preceding periods.

For example, parameters could be: number of periods of the cash flow, discount rate, indexation/inflation, certain weighting that can be applied to the cash flows of each period, etc.

What formula should I start from? Or is there a R/Python/... package that can calculate this for me? So I want to calculate the uneven cash flows CF 1-n, which has to be done numerically I guess.

If you can express the payment in each period as $$CF_i = a_i x$$ where $$x$$ is the sum to be paid. You can easily plug x in easily substitute this in the equation and calculate the value of $$x$$, once you know $$x$$ you can calculate $$CF_i$$

To determine $$x$$ start with

$$PV = \sum_{i=0}^n \frac{CF_i}{(1+r)^i} = \sum_{i=0}^n \frac{a_i x}{(1+r)^i}$$

and solve

$$x = \frac{PV}{\sum_{i=0}^n a_i{(1+r)^{-i}}}$$

$$a_{i} = \left\{\begin{matrix} 1/(10n)&\textrm{if }i \ne n \\ 9/10 & \textrm{if } i=n \end{matrix}\right.$$

• Something I forgot to mention, is that I also need to calculate net present value, not just present value. So e.g. in the initial period there is a negative value of e.g. -100, and at the end it is assumed it can be resold for e.g. +95. Or based on some formula that relates the 100 to the 95 which can be complex and dependent on n. But let's assume it's not dependent on n and weights can be give beforehand. All the in between cash flows are dependent on the 100 too, e.g. if they were discounted; they would each equal 1/(number of periods-2) of the initial cashflow.This seems to make it harder? Jun 21 at 17:33
• Ach no you are right, there is no index i for x so you can indeed just get it out of the summation from i to n. Jun 21 at 17:49
• $a_i$ may add to something different than 1, if you have a distribution $a_i$ and another distribution $b a_i$, the second will give $x/b$ instead of $x$, and $b a_i (x / b) = a_i x$. The only restriction is that the discounted values of $a_i$ must add to something different than zero, in the denominator of the formula for x.
– Bob
Jun 21 at 20:27
• Yes, you got it
– Bob
Jun 22 at 9:24
• If you get a negative X it means that you are trying to pay a negative amount for a positive PV, or vice-versa, the formula is working as an anti-fraud for you hehe
– Bob
Jun 22 at 10:52