# A simple question on Delta hedging

In the Black and Scholes model, when it is needed to immunize the portfolio from variations in the stock the argument given is the following. If $\alpha_t$ is the amount of invested in the stock, $\beta_t$ the amount in the bond, we construct a portfolio whose value is

$$V_t = -C_t+\alpha_t\,S_t+\beta_t\,B_t,$$

where $C_t=f\left(t,S_t\right)$ is the price of a Call option and where $S_t$ and $B_t$ are, respectively, the price of the stock and the price of the bond at time $t$. So we are short selling one unit of the call and buying the portfolio whose $\alpha_t\,S_t+\beta_t\,B_t$. Now one chooses $x$ such that

$$\frac{\partial V_t}{\partial S_t} = 0\Leftrightarrow -\frac{\partial C_t}{\partial S_t}+\alpha_t=0\Leftrightarrow \alpha_t = \frac{\partial C_t}{\partial S_t}\equiv \Delta_t.$$

What puzzles me is the fact that when deriving the value of the portfolio we assume that $\alpha_t$ does not depend from $S_t$ whereas the final solution does depend. So in principle one should do this computation (assuming that $\beta_t$ does not depend on $S_t$)

$$\frac{\partial V_t}{\partial S_t} = -\frac{\partial C_t}{\partial S_t}+\alpha_t+\frac{\partial \alpha_t}{\partial S_t}\,S_t = 0$$

whose solution is of course different from $\alpha_t=\Delta_t$. Where am I wrong?

$\alpha_t$ must be chosen prior to stock price movements so the expression $S_t d\alpha$ does not make sense: we can't take a position in a stock based off information that we don't know yet.
The missing step is that the replicating portfolio is required to be self financing: that is, for all $t$ the following equations hold: $$X_t=\Delta S_t+\Gamma M_t$$ $$dX=\Delta dS+\Gamma dM$$ Where $X$ is the portfolio value and $S$ and $M$ are the stock and riskless asset. The first equation states that no external asset is injected or removed at any time. The second states that we cannot take a position in an asset based off information that is not available at time $t$ (since naively applying Ito's lemma to $X_t$ would yield a $d\Delta$ and $d\Gamma$ term).
Combining the two equations yields $$dX=\Delta dS +r(X_t-\Delta S_t)dt$$
Matching this equation with $df(S, t)$ yields the correct PDE.