Solution (source code)

= Solution

The marked-to-market value of the current holdings is $X_t=H_t\cdot P_t$. In a <self-financing portfolio>, purchases are paid for by sales within the <portfolio>, so rebalancing itself changes no net wealth. Asset price changes contribute $H_t\cdot dP_t$, and nonnegative <consumption> removes $c_t\,dt$ from wealth. Hence
$$
\boxed{X_t=H_t\cdot P_t,\qquad dX_t=H_t\cdot dP_t-c_t\,dt.}
$$
The holdings must be <predictable> and stochastically integrable. The second identity is the self-financing definition with withdrawals; it is not obtained by incorrectly setting the changes in the holdings themselves to zero.