[Tex/LaTex] Declaration of cumulative distribution function

tikz-pgf

I have a code that illustrates a certain figure.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}[
declare function={ Nprime(\x)                 = 1/(sqrt(2*pi))*exp(-0.5*(pow(\x,2))); 
                   d2(\x,\y,\KK,\RR,\SIG)     = (ln(\x/\KK)+(\RR-(pow(\SIG,2)/2)*\y))/(\SIG*(sqrt(\y)));
                   myfun(\x,\y,\KK,\RR,\SIG)  = exp(-\RR*\y)*Nprime(d2(\x,\y,\KK,\RR,\SIG))/(\x*\SIG*sqrt(\y));
                 },
]
\begin{axis}[y domain=0.01:0.3,domain=95:105,view={150}{20}]
\addplot3[surf] {myfun(x,y,100,0,0.09)};
\end{axis}
\end{tikzpicture}


\end{document}

Instead of Nprime(\x) I would like to declare and integrate a cumulative distribution function `N(\x). A very close approximation of cumulative distribution function would also be fine. Everything else should remain equal. Does anybody know how to do it? Thanks in advance!!!
Here is the formula: enter link description here
Something similar is provided here enter link description here but I dont know how to integrate is according to my needs 🙁

Here is a modified version that doesn't work. The last part of the function, i.e. (\x*\SIG*sqrt(\y)) was removed because it is not needed in this case. Here is the code

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}[
declare function={ normcdf(\x,\m,\s)          = 1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));; 
                   d2(\x,\y,\KK,\RR,\SIG)     = (ln(\x/\KK)+(\RR-(pow(\SIG,2)/2)*\y))/(\SIG*(sqrt(\y)));
                   myfun(\x,\y,\KK,\RR,\SIG)  = exp(-\RR*\y)*normdcf(d2(\x,\y,\KK,\RR,\SIG))
                 },
]
\begin{axis}[y domain=0.01:0.3,domain=95:105,view={150}{20}]
\addplot3[surf] {myfun(x,y,100,0,0.09)};
\end{axis}
\end{tikzpicture}


\end{document}

Best Answer

There are three issues in your code:

  1. Missing semicolon at the end of the definition of myfun. All functions defined using declare function have to end with a semicolon.
  2. Typo in the function name (it's normcdf, not normdcf).
  3. Incorrect call of the normcdf function. It takes three parameters: The x value, the mean, and the standard deviation of the normal distribution.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}[
declare function={ normcdf(\x,\m,\s)          = 1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
                   d2(\x,\y,\KK,\RR,\SIG)     = (ln(\x/\KK)+(\RR-(pow(\SIG,2)/2)*\y))/(\SIG*(sqrt(\y)));
                   myfun(\x,\y,\KK,\RR,\SIG)  = exp(-\RR*\y)*normcdf(d2(\x,\y,\KK,\RR,\SIG),0,1);
                 },
]
\begin{axis}[y domain=0.01:0.3,domain=95:105,view={210}{20}]
\addplot3[surf] {myfun(x,y,100,0,0.09)};
\end{axis}
\end{tikzpicture}


\end{document}