Converting Sim.DiffProc Objects to LaTeX

A.C. Guidoum1 and K. Boukhetala2

2019-05-27

The TEX.sde() function

TEX.sde(object,...) produces the related LATEX code (table and mathematic expression) for Sim.DiffProc environment, which can be copied and pasted in a scientific article.

LaTeX table for object of class MCM.sde

The Monte Carlo results of MCM.sde class can be presented in terms of LaTeX tables.

\[\begin{equation}\label{eq01} \begin{cases} dX_t = -\frac{1}{\mu} X_t dt + \sqrt{\sigma} dW_t\\ dY_t = X_{t} dt \end{cases} \end{equation}\]

    Exact Estimate     Bias Std.Error    RMSE    CI( 2.5 % , 97.5 % )
m1   2.00  1.99660  0.00340   0.00559 0.01711   ( 1.98564 , 2.00756 )
m2  28.00 27.98221  0.01779   0.04691 0.14184 ( 27.89027 , 28.07415 )
S1   0.25  0.25135 -0.00135   0.00402 0.01213   ( 0.24347 , 0.25923 )
S2   6.75  6.60499  0.14501   0.12703 0.40773   ( 6.35602 , 6.85396 )
C12  0.25  0.24391  0.00609   0.01758 0.05308   ( 0.20945 , 0.27837 )

In R we create simple LaTeX table for this object using the following code:

%%% LaTeX table generated in R 3.6.0 by TEX.sde() method 
%%% Copy and paste the following output in your LaTeX file 

\begin{table}[t]

\caption{\label{tab:unnamed-chunk-2}LaTeX 
          table for Monte Carlo results generated by `TEX.sde()` method.}
\centering
\begin{tabular}{lrrrrrr}
\toprule
  & Exact & Estimate & Bias & Std.Error & RMSE & CI( 2.5 \% , 97.5 \% )\\
\midrule
$m_{1}(t)$ & 2.00 & 1.99660 & 0.00340 & 0.00559 & 0.01711 & ( 1.98564 , 2.00756 )\\
$m_{2}(t)$ & 28.00 & 27.98221 & 0.01779 & 0.04691 & 0.14184 & ( 27.89027 , 28.07415 )\\
$S_{1}(t)$ & 0.25 & 0.25135 & -0.00135 & 0.00402 & 0.01213 & ( 0.24347 , 0.25923 )\\
$S_{2}(t)$ & 6.75 & 6.60499 & 0.14501 & 0.12703 & 0.40773 & ( 6.35602 , 6.85396 )\\
$C_{12}(t)$ & 0.25 & 0.24391 & 0.00609 & 0.01758 & 0.05308 & ( 0.20945 , 0.27837 )\\
\bottomrule
\end{tabular}
\end{table} 

For inclusion in LaTeX documents, and optionally if we use booktabs = TRUE in the previous function, the LaTeX add-on package booktabs must be loaded into the .tex document.

LaTeX table for Monte Carlo results generated by TEX.sde() method.
Exact Estimate Bias Std.Error RMSE CI( 2.5 % , 97.5 % )
m1 2.00 1.99660 0.00340 0.00559 0.01711 ( 1.98564 , 2.00756 )
m2 28.00 27.98221 0.01779 0.04691 0.14184 ( 27.89027 , 28.07415 )
S1 0.25 0.25135 -0.00135 0.00402 0.01213 ( 0.24347 , 0.25923 )
S2 6.75 6.60499 0.14501 0.12703 0.40773 ( 6.35602 , 6.85396 )
C12 0.25 0.24391 0.00609 0.01758 0.05308 ( 0.20945 , 0.27837 )

LaTeX mathematic for object of class MEM.sde

we want to automatically generate the LaTeX code appropriate to moment equations obtained from the previous model using TEX.sde() method.

Itô Sde 2D:
 | dX(t) = 1/mu * (theta - X(t)) * dt + sqrt(sigma) * dW1(t)
 | dY(t) = X(t) * dt + 0 * dW2(t)
 | t in [t0,T].

Moment equations: 
 | dm1(t)  = (theta - m1(t))/mu
 | dm2(t)  = m1(t)
 | dS1(t)  = sigma - 2 * (S1(t)/mu)
 | dS2(t)  = 2 * C12(t)
 | dC12(t) = S1(t) - C12(t)/mu

In R we create LaTeX mathematical expressions for this object using the following code:

%%% LaTeX equation generated in R 3.6.0 by TEX.sde() method
%%% Copy and paste the following output in your LaTeX file

\begin{equation}\label{eq:}
\begin{cases}
\begin{split}
\frac{d}{dt} m_{1}(t) ~&= \frac{\left( \theta - m_{1}(t) \right)}{\mu} \\
\frac{d}{dt} m_{2}(t) ~&= m_{1}(t) \\
\frac{d}{dt} S_{1}(t) ~&= \sigma - 2 \, \left( \frac{S_{1}(t)}{\mu} \right) \\
\frac{d}{dt} S_{2}(t) ~&= 2 \, C_{12}(t) \\
\frac{d}{dt} C_{12}(t) &= S_{1}(t) - \frac{C_{12}(t)}{\mu}
\end{split}
\end{cases}
\end{equation}

that can be typed with LaTeX to produce a system:

\[\begin{equation} \begin{cases} \begin{split} \frac{d}{dt} m_{1}(t) ~&= \frac{\left( \theta - m_{1}(t) \right)}{\mu} \\ \frac{d}{dt} m_{2}(t) ~&= m_{1}(t) \\ \frac{d}{dt} S_{1}(t) ~&= \sigma - 2 \, \left( \frac{S_{1}(t)}{\mu} \right) \\ \frac{d}{dt} S_{2}(t) ~&= 2 \, C_{12}(t) \\ \frac{d}{dt} C_{12}(t) &= S_{1}(t) - \frac{C_{12}(t)}{\mu} \end{split} \end{cases} \end{equation}\]

Note that it is obvious the LaTeX package amsmath must be loaded into the .tex document.

LaTeX mathematic for an R expression of SDEs

In this section, we will convert the R expressions of a SDEs, i.e., drift and diffusion coefficients into their LaTeX mathematical equivalents with the same procedures previous. An example sophisticated that will make this clear.

%%% LaTeX equation generated in R 3.6.0 by TEX.sde() method
%%% Copy and paste the following output in your LaTeX file

\begin{equation}\label{eq:}
\begin{cases}
\begin{split}
dX_{t} &= \left( \alpha \, X_{t} \, \left( 1 - \frac{X_{t}}{\beta} \right) - \frac{\delta \, X_{t}^2 \, Y_{t}}{\left( \kappa + X_{t}^2 \right)} \right) \:dt +  \sqrt{\sigma_{1}} \, X_{t} \, \left( 1 - Y_{t} \right) \:dW_{1,t} \\
dY_{t} &= \left( \frac{\gamma \, X_{t}^2 \, Y_{t}}{\left( \kappa + X_{t}^2 \right)} - \mu \, Y_{t}^2 \right) \:dt +  \left| \sigma_{2}\right|  \, Y_{t} \, \left( 1 - X_{t} \right) \:dW_{2,t}
\end{split}
\end{cases}
\end{equation}

under LaTeX will create this system:

\[\begin{equation*} \begin{cases} \begin{split} dX_{t} &= \left( \alpha \, X_{t} \, \left( 1 - \frac{X_{t}}{\beta} \right) - \frac{\delta \, X_{t}^2 \, Y_{t}}{\left( \kappa + X_{t}^2 \right)} \right) \:dt + \sqrt{\sigma_{1}} \, X_{t} \, \left( 1 - Y_{t} \right) \:dW_{1,t} \\ dY_{t} &= \left( \frac{\gamma \, X_{t}^2 \, Y_{t}}{\left( \kappa + X_{t}^2 \right)} - \mu \, Y_{t}^2 \right) \:dt + \left| \sigma_{2}\right| \, Y_{t} \, \left( 1 - X_{t} \right) \:dW_{2,t} \end{split} \end{cases} \end{equation*}\]

Further reading

  1. snssdekd() & dsdekd() & rsdekd()- Monte-Carlo Simulation and Analysis of Stochastic Differential Equations.
  2. bridgesdekd() & dsdekd() & rsdekd() - Constructs and Analysis of Bridges Stochastic Differential Equations.
  3. fptsdekd() & dfptsdekd() - Monte-Carlo Simulation and Kernel Density Estimation of First passage time.
  4. MCM.sde() & MEM.sde() - Parallel Monte-Carlo and Moment Equations for SDEs.
  5. TEX.sde() - Converting Sim.DiffProc Objects to LaTeX.
  6. fitsde() - Parametric Estimation of 1-D Stochastic Differential Equation.

References

  1. Xie Y (2015). Dynamic Documents with R and knitr. 2nd edition. Chapman and Hall/CRC, Boca Raton, Florida. ISBN 978-1498716963, URL https://yihui.name/knitr/.

  2. Wickham H (2015). Advanced R. Chapman & Hall/CRC The R Series. CRC Press. ISBN 9781498759809.

  3. Guidoum AC, Boukhetala K (2018). Performing Parallel Monte Carlo and Moment Equations Methods for Ito and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc. Preprint submitted to Journal of Statistical Software.

  4. Guidoum AC, Boukhetala K (2019). Sim.DiffProc: Simulation of Diffusion Processes. R package version 4.4, URL https://cran.r-project.org/package=Sim.DiffProc.


  1. Department of Probabilities & Statistics, Faculty of Mathematics, University of Science and Technology Houari Boumediene, BP 32 El-Alia, U.S.T.H.B, Algeria, E-mail ()

  2. Faculty of Mathematics, University of Science and Technology Houari Boumediene, BP 32 El-Alia, U.S.T.H.B, Algeria, E-mail ()