Solution (source code)

= Solution

A <local martingale deflator> makes both $YB$ and $YS$ local martingales. Since the filtration is generated by $W$, the martingale representation theorem and the finite-variation drift forced by $YB$ give
$$
dY_t=-r_tY_tdt+\eta_t dW_t
=-Y_t(r_tdt+\lambda_t dW_t)
$$
for a continuous adapted $\lambda$, where $\eta=-Y\lambda$. Applying the <Itô product rule> to $YS$ gives drift
$$
Y_tS_t(\mu_t-r_t-\lambda_t\sigma_t)dt.
$$
It vanishes exactly when
$$
\boxed{\lambda_t=\frac{\mu_t-r_t}{\sigma_t}.}
$$