Finding the optimal strategy of a stock trading game Assume there is a stock, its price at time $t$ is $S(t)$. Its price is changing according to a geometric brownian motion, that is $dS=S(\mu dt+\sigma dW)$. You start with $\$1$ and you are allowed to choose a fraction $f$ amout of your net worth to put into the stock at any given time. After a period of time $T$, if your net worth is greater than $\$e$, you win, otherwise you lose. What strategy should you choose to maximise the probability of winning? (A strategy is a function that inputs the current wealth, the remaining time until $T$, and outputs the fraction $f$).
Let the wealth at time $t$ be $N(t)$, for a given strategy $f$, the change of wealth $dN(t)=f(N(t),T-t)N(t)(\mu dt+\sigma dW)$
A simpler version of this question would be asking for a fixed $f$ for all time (instead of a function of time). This will gives $dN(t)=fN(t)(\mu dt+\sigma dW)$, which means $N(T)$~$lognormal(f\mu T-\frac{(f\sigma)^2T}{2},(f\sigma)^2T)$. Then calculate the cdf and take the derivative with respect to $f$ to find the maximum.
For the original question, I guess $N(T)$~$lognomal(\hat{\mu}-\frac{\hat{\sigma}^2}{2},\hat{\sigma}^2)$,
where $\hat{\mu}=\int_0^T \mu f(N(t),T-t)dt$ and $\hat{\sigma}^2=\int_0^T (\sigma f(N(t),T-t))^2dt$.
The question is basically functional minimisation, i.e. asking to choose $f$ so that $\int_0^e N(T)dx$ is minimized.
 A: This is a rather difficult and involved problem.  I am going to proceed through the solution informally and sketch the solution, but it can be made rigorous.  We will first compute what this maximum probability is using the duality method, then return to finding the optimal strategy.  Let $N^f(t)$ be the wealth at time $t$ from following strategy $f$, and let
\begin{align*}
v(t,x) &= \max_f \mathbb{P}(N^f(T) \ge e | N^f(t) = x) \\
&= \max_f \mathbb{E}[1_{N^f(T) \ge e} | N^f(t) = x].
\end{align*}
Let $Z(t) := \exp\left(-\frac{\mu}{\sigma} W_t - \frac 12 \left(\frac{\mu}{\sigma}\right)^2t \right)$ be the Radon-Nikodym process for the risk neutral measure, so $Z(t)S(t)$ is a martingale and therefore $Z(t)N^f(t)$ is a martingale for all choices of $f$.  Then we compute
\begin{align*}
v(t,x) &= \max_f \mathbb{E}[1_{N^f(T) \ge e} | N^f(t) = x] \\
&= \max_f \mathbb{E}[1_{N^f(T) \ge e} - \lambda Z(T)N^f(T) + \lambda Z(T)N^f(T) | N^f(t) = x] \\
&= \max_f \mathbb{E}[1_{N^f(T) \ge e} - \lambda Z(T)N^f(T) | N^f(t) = x] +\lambda Z(t)x.
\end{align*}
The function $g(y) := 1_{y \ge e} - \lambda Z(T)y$ is maximized by \begin{align*} y^* = \begin{cases} e & \text{ if } \lambda Z(T) \le \frac{1}{e} \\
0 & \text{ if } \lambda Z(T) > \frac{1}{e},
\end{cases}
\end{align*}
so the terminal wealth that maximizes $\mathbb{E}[1_{N^f(T) \ge e} - \lambda Z(T)N^f(T) | N^f(t) = x]$ is $$N^f(T) = \begin{cases} e & \text{ if }\lambda Z(T) \le \frac{1}{e} \\
0 & \text{ if } \lambda Z(T) > \frac{1}{e}.
\end{cases}$$
Furthermore, since the market is complete, we know that this terminal wealth is achievable as long as $\mathbb{E}[Z(T)N^f(T) | \mathcal F_t] = Z(t)N^f(t)$.  Rewriting and making the substitution $N^f(t) = x$, we can use this to solve for $\lambda$:
\begin{align*}
x &= \mathbb{E}\left[\frac{Z(T)}{Z(t)}N^f(T) | \mathcal{F}_t \right] \\
&= \mathbb{E}\left[\frac{Z(T)}{Z(t)}e 1_{\lambda Z(T) \le \frac{1}{e}} | \mathcal{F}_t \right] \\
&= e \mathbb{E}\left[\frac{Z(T)}{Z(t)} 1_{\lambda Z(T) \le \frac{1}{e}} | \mathcal{F}_t \right] \\
&= e \widetilde{\mathbb{E}} \left[ 1_{\lambda Z(T) \le \frac{1}{e}} | \mathcal{F}_t \right] \\
&= e \widetilde{\mathbb{P}} \left( \lambda Z(T) \le \frac{1}{e} \right)
\end{align*}
where $d\widetilde{\mathbb{P}} = Z(T)d\mathbb{P}$ is the risk-neutral probability measure, under which $\widetilde{W}_t := W_t + \frac{\mu}{\sigma}$ is a Brownian motion.  Since we know the distribution of $Z(T)$, we can solve for $\lambda$ fairly explicitly (I think it requires inverting the normal CDF) in terms of $Z(t)$, but I will leave the details of that for you.  I will point out that sending $\lambda \rightarrow \infty$ shows we can find a solution as long as $x < e$, which makes sense because if $x = N^f(t) \ge e$ then we are already done and can just hold our wealth for the remaining time.
As for determining the strategy $f$, since we know the terminal payout $$N^f(T) = \begin{cases} e & \text{ if }\lambda Z(T) \le \frac{1}{e} \\
0 & \text{ if }\lambda Z(T) > \frac{1}{e},
\end{cases}$$
finding $f$ is equivalent to finding a replicating portfolio.  This is again a rather involved computation, but the standard replication method works, and I will leave the details to you.
