The main difference between an annuity immediate and an annuity due is when payments are made. For an annuity immediate, payments are received at the end of each period, while for an annuity due, payments are received at the beginning of each period.

It's also important to distinguish between annuities and life annuities. Regular annuities provide payments for a set period, whereas life annuities make payments only as long as the policyholder is alive.

## Annuity immediate

In an annuity immediate, payments are made at the end of each period.

### Present value

To find the present value of an annuity immediate, use this formula:

\( PV_{\text{immediate}} = P \cdot \frac{1-(1+i)^{-n}}{i} \)In this formula, \( P \) is the payment amount per period, \( i \) is the interest rate per period, and \( n \) is the number of periods.

For example, the present value of payments of 50 for 12 periods (e.g. months) at an interest rate of 1% is:

\( 50 \cdot \frac{1-(1+0.01)^{-12}}{0.01} = 562.75\)This means the current value of these future payments is approximately 562.75.

Here’s how you can model this in Python using the `cashflower` package:

model.py```
@variable()
def annuity_immediate_pv(t):
if t == 0:
return annuity_immediate_pv(t+1) * 1/(1 + 0.01)
elif t < 12:
return 50 + annuity_immediate_pv(t+1) * 1/(1 + 0.01)
elif t == 12:
return 50
else:
return 0
```

### Future value

The future value of an annuity immediate is calculated using the following formula:

\( FV_{\text{immediate}} = P \cdot \frac{(1+i)^{n}-1}{i} \)For example, with the same payment of 50 for 12 periods and a 1% interest rate, the future value would be:

\( 50 \cdot \frac{(1+0.01)^{12}+1}{0.01} = 634.13 \)This is the amount accumulated after all payments are made, including interest.

model.py```
@variable()
def annuity_immediate_fv(t):
if t == 0:
return 0
elif t <= 12:
return 50 + annuity_immediate_fv(t-1) * (1 + 0.01)
else:
return annuity_immediate_fv(t-1)
```

## Annuity due

The payments in the annuity due happen at the beginning of periods.

### Present value

The present value of an annuity due can be calculated using the following formula:

\( PV_{\text{due}} = P \cdot \frac{1-(1+i)^{-n}}{i} \cdot (1+i) \)Using the same example as above, but with payments at the beginning of the periods, the present value becomes:

\( 50 \cdot \frac{1-(1+0.01)^{-12}}{0.01} \cdot (1+0.01) = 568.38 \)This value is slightly higher than that of the annuity immediate due to the earlier timing of the payments.

model.py```
@variable()
def annuity_due_pv(t):
if t < 12:
return 50 + annuity_due_pv(t+1) * 1/(1 + 0.01)
else:
return 0
```

### Future value

The future value of an annuity due is given by the following formula:

\( FV_{\text{due}} = P \cdot \frac{(1+i)^{n}-1}{i} \cdot (1+i) \)For our example, this results in:

\( 50 \cdot \frac{(1+0.01)^{12}-1}{0.01} \cdot (1+0.01) = 640.47 \)The future value of the annuity due is higher than that of the annuity immediate because each payment is invested for an additional period.

model.py```
@variable()
def annuity_due_fv(t):
if t == 0:
return 50
elif t < 12:
return 50 + annuity_due_fv(t-1) * (1 + 0.01)
elif t == 12:
return annuity_due_fv(t-1) * (1 + 0.01)
else:
return annuity_due_fv(t-1)
```

In summary, the main difference between an annuity immediate and an annuity due lies in the timing of the payments, which affects both the present and future values.