# Interchange the deterministic and stochastic integrals

We fix $$T >0$$ and let $$\mathbb T$$ be the interval $$[0, T]$$. Let $$(X_t, t \in \mathbb T)$$ be a continuous adapted process on some filtered probability space $$(\Omega, \mathcal A, (\mathcal F_t)_{t \in \mathbb T}, \mathbb P)$$. Let $$g : \mathbb T \times \mathbb R^d \to \mathbb R$$ be continuous. Assume that $$\int_0^t g(s, X_s) \, \mathrm d s$$ is well-defined and $$\mathbb P$$-integrable for each $$t \in \mathbb T$$.

Can we interchange the deterministic and stochastic integrals, i.e., $$\mathbb E \left [ \int_0^t g(s, X_s) \, \mathrm d s \right ] = \int_0^t \mathbb E \left [ g(s, X_s) \right ] \mathrm d s$$ ?

Thank you so much for your elaboration!

$$\newcommand\om\omega\newcommand\Om\Omega$$No. E.g., suppose that $$\Om=(0,1]$$, $$T=1$$, for each $$t\in[0,T]$$ the $$\sigma$$-algebra $$\mathcal F_t=\mathcal A$$ is the Borel $$\sigma$$-algebra over $$\Om$$, $$\mathbb P$$ is the uniform distribution over $$\Om$$, and $$X_s(\om)=1/\om$$ for $$\om\in\Om$$. Let $$h$$ be any continuous function from $$[0,T]\times\mathbb R$$ to $$\mathbb R$$ such that $$\int_1^\infty du\,\int_0^T ds\,h(s,u)\ne \int_0^T ds\,\int_1^\infty du\,h(s,u)$$ and $$\int_1^\infty du\,\int_0^t ds\,h(s,u)\in\mathbb R$$ for each $$t\in[0,T]$$. Let $$g(s,u):=u^2 h(s,u)$$ for all $$(s,u)\in[0,T]\times\mathbb R$$.
Then all your conditions hold, but $$\mathbb E\int_0^T ds\,g(s,X_s) =\int_1^\infty du\,\int_0^T ds\,h(s,u) \\ \ne\int_0^T ds\,\int_1^\infty du\,h(s,u) =\int_0^T ds\,\mathbb E g(s,X_s).$$