Converting Sim.DiffProc Objects to LaTeX

A.C. Guidoum1 and K. Boukhetala2

2020-03-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  2.00589 -0.00589   0.00555 0.01765   ( 1.99501 , 2.01677 )
m2  28.00 27.95881  0.04119   0.02358 0.08185 ( 27.91259 , 28.00503 )
S1   0.25  0.24784  0.00216   0.00623 0.01882   ( 0.23563 , 0.26005 )
S2   6.75  6.74426  0.00574   0.12736 0.38212   ( 6.49464 , 6.99388 )
C12  0.25  0.23211  0.01789   0.02296 0.07115   ( 0.18711 , 0.27711 )

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

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

\begin{table}

\caption{\label{tab:unnamed-chunk-2}LaTeX 
          table for Monte Carlo results generated by `TEX.sde()` method.}
\centering
\begin{tabular}[t]{lrrrrrr}
\toprule
  & Exact & Estimate & Bias & Std.Error & RMSE & CI( 2.5 \% , 97.5 \% )\\
\midrule
$m_{1}(t)$ & 2.00 & 2.00589 & -0.00589 & 0.00555 & 0.01765 & ( 1.99501 , 2.01677 )\\
$m_{2}(t)$ & 28.00 & 27.95881 & 0.04119 & 0.02358 & 0.08185 & ( 27.91259 , 28.00503 )\\
$S_{1}(t)$ & 0.25 & 0.24784 & 0.00216 & 0.00623 & 0.01882 & ( 0.23563 , 0.26005 )\\
$S_{2}(t)$ & 6.75 & 6.74426 & 0.00574 & 0.12736 & 0.38212 & ( 6.49464 , 6.99388 )\\
$C_{12}(t)$ & 0.25 & 0.23211 & 0.01789 & 0.02296 & 0.07115 & ( 0.18711 , 0.27711 )\\
\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 2.00589 -0.00589 0.00555 0.01765 ( 1.99501 , 2.01677 )
m2 28.00 27.95881 0.04119 0.02358 0.08185 ( 27.91259 , 28.00503 )
S1 0.25 0.24784 0.00216 0.00623 0.01882 ( 0.23563 , 0.26005 )
S2 6.75 6.74426 0.00574 0.12736 0.38212 ( 6.49464 , 6.99388 )
C12 0.25 0.23211 0.01789 0.02296 0.07115 ( 0.18711 , 0.27711 )

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.3 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.3 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 (2020). Performing Parallel Monte Carlo and Moment Equations Methods for Ito and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc. Accept Submission to Journal of Statistical Software.

  4. Guidoum AC, Boukhetala K (2020). Sim.DiffProc: Simulation of Diffusion Processes. R package version 4.5, 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 ()