Can someone provide a detailed example to prove the following statement: "When the investment horizon is equal to the Macaulay duration of the bond, coupon reinvestment risk offsets price risk."
Proof:
The future value at investment horizon time $t$ of a set of $n$ cashflows is
$$
FV(t;y) = \sum_{i=1}^n CF_i \cdot D(t,t_i) = \sum_{i=1}^n CF_i \cdot \exp\left(-y\cdot (t_i-t)\right),
$$
where $D(t,t_i)$ be the discount factor between time $t$ and time $t_i$, and $y$ is the constant continuously compunded interest rate or yield.
For what value of $t$ is the future value immune to a small change in yield?
\begin{align}
\frac{\partial FV(t;y)}{\partial y} &= -\sum_{i=1}^n CF_i \cdot (t_i-t) \exp\left(-y\cdot (t_i-t)\right),
\end{align}
setting equal to zero and solving for $t$ gives us
\begin{align}
t^* = \frac{\sum_{i=1}^n t_i \cdot CF_i \cdot \exp(-y\cdot t_i)}{\sum_{i=1}^n CF_i \cdot \exp(-y\cdot t_i)},
\end{align}
which is identical to the Macaulay duration.
Relative to horizon $t$, cashflows before time $t$ are compounded forward (increasing in value), and cashflows after time $t$ are discounted back (decreasing in value). A small positive increase in yield $y$ will cause future cashflows to be less valuable (price risk) at time $t$ wheareas past received cashflows be more valuable (investment risk). If the horizon is $t^*$, which is equal to the Macaulay duration, these two effects will cancel out.
Example:
Consider a 3y annual paying coupon bond with notional $N=100$, yield $y=19.5\%$ , coupon $c=21.5\%$, $t_i=i$ where $i=1,2,3$. The cashflows are $CF_i=N\cdot c=21.5$ for $i<3$ and $CF_3=Nc+N = 121.5$.
Performing the above exercise you will see that the Macaulay duration is $t^*=2.5$.
The change in the future value to a small change $\epsilon$ in yield is given by
$\Delta FV(t;y) = FV(t;y+\epsilon) - FV(t;y)$.
With e.g. $\epsilon=1\%$ you will find that the change in value is minimized when $t=t^*$.