3

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}
ajafarov
  • 757
  • Can you also include the function (either the formula or a link) since not everybody here is mathematically specialized? – percusse Aug 01 '13 at 09:46
  • @percusse I have edited it, thanks for help! – ajafarov Aug 01 '13 at 11:28
  • Well you have the exact code given in the linked question what is the problem? – percusse Aug 01 '13 at 11:31
  • @percusse I have difficulties integrating it into the code written by you, that's my problem – ajafarov Aug 01 '13 at 11:46
  • What exactly are you trying to plot (myfun and d2 aren't very enlightening function names)? Could you provide a link to a Wolfram Alpha plot of the desired function? – Jake Aug 01 '13 at 13:28
  • @Jake the code was initially written by percusse, he has established these definitions – ajafarov Aug 01 '13 at 13:43
  • @Jake but it all has to do with the pricing of financial derivatives, to be more precise options – ajafarov Aug 01 '13 at 13:46
  • If I understand correctly, you're talking about http://tex.stackexchange.com/q/124878/2552. It seems to me like you provided the names N' and d_2, and didn't explain what the first function does, hence percusse's choice of myfun. Anyway, what do you mean with "difficulties integrating it into the code"? If you take the definition of normcdf and plug it into your code, do you get an error message? Or is the result not what you expected? – Jake Aug 01 '13 at 13:53
  • @Jake I didnt explain it, you're right. I used the function declared by you from the topic that I have linked, and I have replaced Nprime by normcdf(\x,\m,\s)=1/(1 + exp(-0.07056((\x-\m)/\s)^3 - 1.5976(\x-\m)/\s)); As a result I had an error, if you want, I can integrate it in accordance with my needs and show you the whole code, should I? – ajafarov Aug 01 '13 at 14:08
  • @ajafarov: Yes, I think that would be helpful – Jake Aug 01 '13 at 14:11

1 Answers1

4

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}
Jake
  • 232,450