# Option Pricing and Greeks – Jedox

Hi,

In this post, I would like to present you the “Option Pricing n Greeks” in Jedox.

Well continuing on my previous post, I would like to highlight the potential of Jedox in terms of number crunching capacity, where I have designed the macro for option pricing most commonly used in any front desk team of an investment bank.

For all the background about options derivatives used in the financial industry and the measures (the Greeks) incorporated in this model references are as below:

http://www.investopedia.com/university/options/

http://www.investopedia.com/university/option-greeks/

http://en.wikipedia.org/wiki/Option_(finance)

http://en.wikipedia.org/wiki/Greeks_(finance)

This model in Jedox computes the option prices and its greeks based on the user inputs and as the benefits of Jedox come along together the possibilities are enormous. Code:

```
function dOne(\$S, \$X, \$T, \$r, \$v, \$d){
\$n1 = application()-&gt;Log(\$S / \$X);
\$n2 = (\$r - \$d + 0.5 * pow(\$v , 2)) * \$T;
\$d1 = \$v * pow(\$T,2);
\$value = (\$n1 + \$n2) / \$d1;
return \$value;
}

function NdOne(\$S, \$X, \$T, \$r, \$v, \$d){
\$nd = dOne(\$S, \$X, \$T, \$r, \$v, \$d);
\$n1 = -1* (pow(\$nd , 2) / 2);
\$d1 = application()-&gt;sqrt(2 * application()-&gt;Pi());
\$value = application()-&gt;Exp(\$n1) / \$d1 ;
return \$value;
}

function dTwo(\$S, \$X, \$T, \$r, \$v, \$d){
\$value = dOne(\$S, \$X, \$T, \$r, \$v, \$d) - \$v * application()-&gt;sqrt(\$T);
return \$value;
}

function NdTwo(\$S, \$X, \$T, \$r, \$v, \$d){
\$value = application()-&gt;NormSDist(dTwo(\$S, \$X, \$T, \$r, \$v, \$d));
return \$value;
}

function OptionPrice(\$OptionType, \$S, \$X, \$T, \$r, \$v, \$d) {
if(\$OptionType == 'C'){
\$value = application()-&gt;Exp(-\$d * \$T) * \$S * application()-&gt;NormSDist(dOne(\$S, \$X, \$T, \$r, \$v, \$d)) - \$X * application()-&gt;Exp(-\$r * \$T) * application()-&gt;NormSDist(dOne(\$S, \$X, \$T, \$r, \$v, \$d) - \$v * applica   tion()-&gt;sqrt(\$T));
} elseif (\$OptionType == 'P'){
\$m1 = application()-&gt;Exp(-1*\$r * \$T);
\$m2 = application()-&gt;NormSDist(-1 * dTwo(\$S, \$X, \$T, \$r, \$v, \$d));
\$m3 = application()-&gt;Exp(-1 * \$d * \$T);
\$m4 = application()-&gt;NormSDist(-1 * dOne(\$S, \$X, \$T, \$r, \$v, \$d));
\$s1 = \$X * \$m1 * \$m2;
\$s2 = \$S * \$m3 * \$m4;
\$value = \$s1-\$s2;
}
return \$value;
}

function OptionDelta(\$OptionType, \$S, \$X, \$T, \$r, \$v, \$d){
if(\$OptionType == 'C') {
\$value = application()-&gt;NormSDist(dOne(\$S, \$X, \$T, \$r, \$v, \$d));
}elseif (\$OptionType == 'P'){
\$value = application()-&gt;NormSDist(dOne(\$S, \$X, \$T, \$r, \$v, \$d)) - 1;
}
return \$value;
}

function Gamma(\$S, \$X, \$T, \$r, \$v, \$d){
\$value = NdOne(\$S, \$X, \$T, \$r, \$v, \$d) / (\$S * (\$v * application()-&gt;sqrt(\$T)));
return \$value;
}

function Vega(\$S, \$X, \$T, \$r, \$v, \$d){
\$value = 0.01 * \$S * application()-&gt;sqrt(\$T) * NdOne(\$S, \$X, \$T, \$r, \$v, \$d);
return \$value;
}

function OptionRho(\$OptionType, \$S, \$X, \$T, \$r, \$v, \$d){
if(\$OptionType == 'C'){
\$value = 0.01 * \$X * \$T * Exp(-1 * \$r * \$T) * application()-&gt;NormSDist(dTwo(\$S, \$X, \$T, \$r, \$v, \$d));
}elseif (\$OptionType == 'P'){
\$value = -0.01 * \$X * \$T * Exp(-1*\$r * \$T) * (1 - application()-&gt;NormSDist(dTwo(\$S, \$X, \$T, \$r, \$v, \$d)));
}
return \$value;
}

function OptionTheta(\$OptionType, \$S, \$X, \$T, \$r, \$v, \$d){
if(\$OptionType == 'C'){
\$value = -((\$S * \$v * NdOne(\$S, \$X, \$T, \$r, \$v, \$d)) / (2 * application()-&gt;sqrt(\$T)) - \$r * \$X * Exp(-1 * \$r * (\$T)) * NdTwo(\$S, \$X, \$T, \$r, \$v, \$d)) / 365;
}elseif (\$OptionType == 'P'){
\$value = -((\$S * \$v * NdOne(\$S, \$X, \$T, \$r, \$v, \$d)) / (2 * application()-&gt;sqrt(\$T)) + \$r * \$X * Exp(-1 * \$r * (\$T)) * (1 - NdTwo(\$S, \$X, \$T, \$r, \$v, \$d))) / 365;
}
return \$value;
}

```

Hope you like it.

Enjoy !!!