Linear quadratic stochastic optimal control problem confusion with Hamilton-Jacobi Bellman equation

I have the following stochastic optimal control problem, where

$$dx = u(t)dt + \sqrt{2\nu}dW(t)$$

and $$x(t_0) = x_0$$ and where $$W(t)$$ is the Wiener process/Brownian motion, and the cost function is,

$$J(x_0,t_0,u) = \mathbb{E}\left[\int_{t_0}^T \frac{1}{2}\|u(\tau)\|^2 + \frac{1}{2}\|x(\tau)\|^2\, d\tau + g(x(T)) \right]$$

with $$g(x) = \frac{1}{2}\|x\|^2$$. The value function is,

$$\phi(x,t) = \inf_u J(x,t,u)$$

and we have that $$\phi$$ solves the HJB equation,

$$-\partial_t \phi - \nu \Delta \phi + \frac{1}{2} \|\nabla_x \phi\|^2 - \frac{1}{2}\|x\|^2 = 0$$

A solution to the above HJB equation is $$\phi(x,t) = \frac{1}{2}\|x\|^2 + \nu(T-t)$$. From this, the optimal control should then be $$u(t) = -\nabla_x \phi$$, so we should have,

$$x(t) = x(t_0)e^{-(t-t_0)} + \sqrt{2\nu} W(t - t_0)$$

But if I insert the $$u(t)$$ and the $$x(t)$$ into the cost function $$J(x_0, t_0, u)$$, I do NOT get $$\phi(x,t) = \frac{1}{2} \|x\|^2 + \nu(T-t)$$. Rather, I get $$\phi(x,t) = \frac{1}{2}\|x\|^2 + \frac{\nu}{2}(T-t)^2 + \nu(T-t)$$, but this doesn't solve the HJB equation.

What am I doing wrong? Thank you in advance.

Edit: The above is when $$x$$ is 1 dimension. If $$x$$ is of dimension $$d$$ then all that needs to be changed is in $$\phi(x,t)$$, where instead of $$\nu$$ we should change to $$\nu d$$.

Edit2, What I did: For simplicity, assume $$t_0=0$$, and let $$X(0)=x_0$$. In 1 dimension, if $$dX_t = -X_tdt + \sqrt{2\nu}dW_t$$ then the solution for $$X_t$$ should be,

$$X(t) = x_0 e^{-t} + \sqrt{2\nu} W_{t}$$

is that right? Then using that $$u(t) = -x_0e^{-t}$$, if I plug this into $$J(x_0, t_0, u)$$, I get:

\begin{align} J(x_0, 0, u) &= \mathbb{E} \left[ \int_{0}^T \frac{1}{2} x_0^2e^{-2t} + \frac{1}{2}\left(x_0 e^{-t} + \sqrt{2\nu} W_t \right)^2 \, dt + \frac{1}{2}\left(x_0 e^{-T} + \sqrt{2\nu} W_T \right)^2 \right] \\ &= \mathbb{E} \left[ \int_{0}^T x_0^2 e^{-2t} + x_0e^{-t}\sqrt{2\nu}W_t + \nu W_t^2\,dt \right] \\ &\qquad +\mathbb{E}\left[\frac{1}{2}x_0^2 e^{-2T} + x_0 e^{-T}\sqrt{2\nu}W_T + \nu W_T^2 \right] \\ &= \int_0^T x_0^2 e^{-2t} + x_0 e^{-t} \sqrt{2\nu}\mathbb{E}[W_t] + \nu \mathbb{E}[W_t^2]\,dt \\ &\qquad + \frac{1}{2}x_0^2 e^{-2T} + x_0 e^{-T}\sqrt{2\nu}\mathbb{E}[W_T] + \nu \mathbb{E}[W_T^2] \end{align}

At this point since $$\mathbb{E}[W_t] = 0$$ and $$\mathbb{E}[W_t^2] = t$$ for all $$t$$, then,

\begin{align} J(x_0, 0, u) &= -\frac{1}{2}x_0^2 e^{-2T} + \frac{1}{2}x_0^2 + \frac{\nu}{2}T^2 + \frac{1}{2}x_0^2 e^{-2T} + vT \\ &= \frac{1}{2}x_0^2 + \frac{\nu}{2}T^2 + \nu T \end{align}

So I get an extra $$\frac{\nu}{2}T^2$$ term. Where did I go wrong?

• What is $\tau$ in the argument of $u$ in the definition of the cost function $J$? Was this a typo and $t$ was meant to be used or is $\tau$ perhaps a stopping time of some sort? Commented Jul 9, 2020 at 19:27
• Oh sorry I wanted the integration dummy variable to be $\tau$. I'll edit it. Commented Jul 9, 2020 at 19:29
• I want to take a look at this but just to be sure, what norm are you using here? Commented Jul 9, 2020 at 19:51
• It's the standard Euclidean norm. Thank you for taking the time to look at it. Edit: But I mainly did the computations in 1D, which was enough to produce my confusion. Edit2: Oh if it is more than 1D, then everywhere you see $\nu$ you should change to $\nu d$ where $d$ is the space dimension. Sorry for the confusion! Commented Jul 9, 2020 at 19:51
• Okay sorry, but just to be extra precise, if you go to higher dimensions, then you should change to $\nu d$ in the exact solution $\phi$, but not anywhere else. Commented Jul 9, 2020 at 20:03

$$dX_t = -X_tdt + \sqrt{2\nu}dW_t$$
$$X(t) = X(0)e^{-t} + \sqrt{2\nu} \int_0^t e^{s-t}\,dW(s).$$