Ito integral under an expectation. I am trying to apply Ito's formula to
$$P(t, X_t) = \mathbb{E}^\mathbb{Q}\left[\exp\left(-\int_t^{T}r(X_s)ds\right)\middle|X_t\right]$$
where $T$ is a fixed constant and
$$
dX_t = \mu\left(X_t\right)dt + \sigma(X_t)dZ_t.$$ I'm only interested in obtaining the term in front of dt which I understand should be $r(X_t)P(t,X_t)$ but I do not see how?
If you apply Ito's formula you get
\begin{equation}
\tag{1}
dP = r(X_t)P(t,X_t)dt +\ldots dX_t + \frac12\frac{\partial^2P}{\partial X_t^2}\sigma^2dt
\end{equation} where I'm not sure what should be in the dots, presumably it must be $0$ otherwise the result would not be correct but I do not see this. Also can anyone provide a justification for applying Ito under the expectation?
[For context this appears in Duffie-Kan 1996 in the derivation for equation (3.5) https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwjfo_Oqg5b5AhVxm1wKHf3FByoQFnoECAgQAQ&url=https%3A%2F%2Fwww.darrellduffie.com%2Fuploads%2Fpubs%2FDuffieKan1996.pdf&usg=AOvVaw2eP5RVrNc3m5LJ7rBiT44c]
 A: I think you are missing the key assumption: we are considering only affine models, i.e. models that are of the form $f(x,t,T) = \exp{\{A(t,T) + B(t,T) x\}}$.
Here we are saying that the ZCB has this form, hence: $P(t,T)= \exp{\{A(T-t) + B(T-t) X_t\}}$ (typically $X_t = r_t$ is the (stochastic) interest rate).
So you just need to apply Ito to this process and not the definition of P as expectation of discounted payoff.
Edit [proof of $\mathcal{D}F-R(X_t)F = 0$]:
We can use Feynman-Kac representation formula. Without all the details we have that for a function $u(x,t)$ following a PDE like BS and with terminal condition $u(x,T) = \psi(x)$ the solution is given as:
$$
u(x,t) = \mathbb{E}_{t,x}^{\mathbb{Q}}\bigg[ \int_{t}^{T} e^{-\int_{t}^{s}R(X_s,s)ds } f(X_s,s)ds + e^{-\int_{t}^{T}R(X_s,s)ds }\psi(X_T)\bigg]
$$
In our case $\psi(X_T) = 1, u=P(t,T)$ and $f(x,t)=0$. We just need to reason in the opposite direction: we know the conditional expectation then we know the PDE followd by the function is:
$$
\mathcal{D}P(t,T) - R(X_t)P(t,T) = 0
$$
where $\mathcal{D}$ is the Kolmogorov infinitesimal generator (the one you computed previously).
A: I will use the usual interest rate modelling framework. The process $P(t,X_t)$ satisfies the 'bond pricing' PDE
$$\begin{cases}
\partial_tP(t,x)+(\mu(x)-\sigma(x)\theta(t,x))\partial_xP(t,x)+\frac{1}{2}\sigma^2(x)\partial_{xx}P(t,x)-r(x)P(t,x)=0\\
P(T,x)=1
\end{cases}$$
where $\theta$ is the relative risk process (i.e. $dW_t^\theta=dW_t+\theta(t,X_t) dt$ is a $Q$-Brownian motion). Therefore by Ito
$$\begin{aligned}dP(t,X_t)&=\partial_tP(t,X_t)dt+\partial_xP(t,X_t)dX_t+\frac{1}{2}\sigma^2(X_t)\partial_{xx}P(t,X_t)dt=\\
&=\bigg(\partial_tP(t,X_t)+\mu(X_t)\partial_xP(t,X_t)+\frac{1}{2}\sigma^2(X_t)\partial_{xx}P(t,X_t)\bigg)dt+\sigma(X_t)\partial_xP(t,X_t)dW_t=\\
&=\bigg(\partial_tP(t,X_t)+(\mu(X_t)-\sigma(X_t)\theta(t,X_t))\partial_xP(t,X_t)+\frac{1}{2}\sigma^2(X_t)\partial_{xx}P(t,X_t)\bigg)dt+\\
&+\sigma(X_t)\partial_xP(t,X_t)dW_t^\theta=\\
&=r(X_t)P(t,X_t)dt+\sigma(X_t)\partial_xP(t,X_t)dW^\theta_t\end{aligned}$$
By Ito product rule
$$d\bigg(P(t,X_t)e^{-\int_0^tr(X_s)ds}\bigg)=e^{-\int_0^tr(X_s)ds}\sigma(X_t)\partial_xP(t,X_t)dW^\theta_t$$
and
$$e^{-\int_0^Tr(X_s)ds}-P(t,X_t)e^{-\int_0^tr(X_s)ds}=\int_{t}^Te^{-\int_0^sr(X_u)du}\sigma(X_s)\partial_xP(s,X_s)dW^\theta_s$$
In the context of bond pricing, a martingale assumption on the rhs yields
$$E^Q[e^{-\int_0^Tr(X_s)ds}|\mathscr{F}_t]-P(t,X_t)e^{-\int_0^tr(X_s)ds}=0$$
as we knew already.
