# Problems in understanding BSM formula

I'm currently learning Black-Scholes-Merton partial differential equation, and there are some confusions I can't work out.

Under the Black-Scholes assumption, we have: $$df=\left(\frac{\partial f}{\partial S}\mu S+\frac{\partial f}{\partial t}+\frac 12\frac{\partial^2f}{\partial S^2}\sigma^2S^2\right)dt+\frac{\partial f}{\partial S}\sigma S dB_t$$

To construct a portfolio: $$\Pi=-f+\frac{\partial f}{\partial S}S$$ We can eliminate the randomness, so we have: $$\Delta \Pi=\left(-\frac{\partial f}{\partial t}-\frac 12\frac{\partial^2f}{\partial S^2}\sigma^2S^2\right)\Delta t$$

Any riskless asset must satisfy $\Delta\Pi=r\Pi\Delta t$, then we can reach to the differential equation.

My question is:

1. Is S in $\Delta \Pi=\left(-\frac{\partial f}{\partial t}-\frac 12\frac{\partial^2f}{\partial S^2}\sigma^2S^2\right)\Delta t$ still a stochastic process? or the stock price at the beginning, which is deterministic?
2. If S is a stochastic process, then according to the Geometric Brownian Motion assumption, $S=S_0e^{\sigma B_t+(\mu-\frac12\sigma^2)t}$ , which contains $\mu$ as a parameter. Then how can we say it has no dependence on $\mu$ and replace $\mu$ with $r^f$ in the risk-neutral world?

Regarding your first question, you actually have:

$$d\Pi_t=-\left(\frac{\partial f_t}{\partial t}+\frac{1}{2}\frac{\partial^2f_t}{\partial S_t^2}\sigma^2S_t^2\right)dt$$

The equation represents the portfolio evolution in an infinitesimal timespan $dt$ (i.e. from $t$ to $t+dt$). Note that the term $S_t$ is the stock price at time $t$ hence it is already known during the interval $[t,t+dt]$ so it is not a random variable but a deterministic quantity.

As for your second question, note that the Black-Scholes equation is:

$$\frac{\partial f_t}{\partial t}+\frac{1}{2}\frac{\partial^2f_t}{\partial S_t^2}\sigma^2 S_t+\frac{\partial f_t}{\partial S_t}rS_t=rf_t$$

As per the Feynman-Kac formula, the solution to the PDE above is the discounted expectation of the terminal condition $-$ the terminal condition in this case is the payoff of the derivative at maturity $f(T,S_T)$, for example $\max(0,S_T-K)$ for a European call $-$ for a probability measure $Q$ under which the stock price follows the SDE:

$$dS_t=rS_tdt+\sigma S_tdW^Q_t$$

i.e. replacing $\mu$ by $r$ is a mathematical "trick" which comes from Feynman-Kac. This convenient trick $-$ convenient as it allows to compute derivative prices as expectations instead of solutions to PDEs $-$ has been formalized and generalized, for example by Harrison and Pliska (1981).