Solution
= Solution
If $θ_n$ shares are held during period $n$, the remaining wealth $X_{n-1}-θ_nS_{n-1}$ is in the bank account. <Self-financing portfolio>[Self-financing] therefore gives
$$
X_n=θ_nS_n+(1+r)(X_{n-1}-θ_nS_{n-1}),
$$
which rearranges to the required equation.