Solution (source code)

= Solution

Let $N=T-t$ and use the discounted multipliers $u,d$. Under $Q$, the number $K$ of up moves in the remaining $N$ periods has the <binomial distribution> $\operatorname{Binomial}(N,q)$. Since
$$
S_T^1=S_t^1u^Kd^{N-K},
$$
the conditional expectation in part (b) becomes
$$
\boxed{
V_t=\sum_{k=0}^{T-t}\binom{T-t}{k}q^k(1-q)^{T-t-k}
h\left(S_t^1u^kd^{T-t-k}\right).}
$$
For an undiscounted stock, replace $u,d$ by $U,D$ and discount the resulting payoff by the appropriate power of $R$.