# Time Varying Payoffs?

I'm trying to write some code that will return the final value of an annuity whose monthly payouts may or may not be constant each month. Right now I have working code for constant payments, but I'm not sure how to do changing payments. Would I use Range?

Code:

vals = Function[{P, r, n}, P ((1 + r)^n)];
Total[Table[vals[200, .01, n], {n, 60}]]

• Have you looked at built in functions such as Annuity and Cashflow? – Daniel Lichtblau Mar 12 '14 at 18:46
• Agree with Dan Lichtblau. If the pattern of payments can readily be emulated by a function, use Annuity with a function as the first argument and wrap it up with TimeValue. If the pattern is too irregular, use Cashflow and wrap it up with TimeValue. These functions are designed precisely to save you the trouble of re-re-inventing the wheel. – Seth Chandler May 12 '14 at 16:24

vals = Function[{P, r, n}, P ((1 + r)^n)];
Total[Table[vals[200, .01, n], {n, 60}]]


16497.3

With separate payments (of the same size) :-

(a[#] = 200) & /@ Range[60];
Total[Table[vals[a[n], .01, n], {n, 60}]]


16497.3

Also like so :-

Sum[vals[a[n], .01, n], {n, 60}]


16497.3

Now with different sized payments :-

(a[#] = RandomInteger[{190, 210}]) & /@ Range[60];
Sum[vals[a[n], .01, n], {n, 60}]


16483.3

Earlier answer below, left for posterity.

Here is a calculation based on a loan type annuity. It finds the present value rather than the final value, but you should be able to adapt the method.

a is the periodic payment
i is the annual percentage rate
n is the number of payments per year
t is the number of years
pv is present value of the loan


Based on a 3 month loan of varying payments :-

a[1] = 1000;
a[2] = 1200;
a[3] = 1050;

i = 0.1;
n = 12;
t = 0.25;

pv = Sum[a[k] (1 + i)^(-k/n), {k, 1, n*t}]


3198.45

Edit

To more fully illustrate the method, first some calculations with fixed payments :-

i = 0.1;
a = 1000;
n = 12;
t = 0.25;

pv = TimeValue[Annuity[a, t, 1/n], i, 0]


2952.78

Reversing the calculation using monthly rate r and loan formula :-

r = (1 + i)^(1/n) - 1;
a = r*pv/(1 - (1 + r)^-(n*t))


1000

Calculating the present value again but with a formula :-

pv = Sum[a (1 + i)^(-k/n), {k, 1, n*t}]


2952.78

The payment amounts can be specified separately :-

Clear[a]
a[1] = a[2] = a[3] = 1000;
pv = Sum[a[k] (1 + i)^(-k/n), {k, 1, n*t}]


2952.78

Or the amounts can be specified differently :-

a[1] = 1000;
a[2] = 1200;
a[3] = 1050;

pv = Sum[a[k] (1 + i)^(-k/n), {k, 1, n*t}]


3198.45