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.

CropperCapture[22]

Code:


function dOne($S, $X, $T, $r, $v, $d){
  $n1 = application()->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()->sqrt(2 * application()->Pi());
  $value = application()->Exp($n1) / $d1 ;
  return $value;
}

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

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

function OptionPrice($OptionType, $S, $X, $T, $r, $v, $d) {
  if($OptionType == 'C'){
   $value = application()->Exp(-$d * $T) * $S * application()->NormSDist(dOne($S, $X, $T, $r, $v, $d)) - $X * application()->Exp(-$r * $T) * application()->NormSDist(dOne($S, $X, $T, $r, $v, $d) - $v * applica   tion()->sqrt($T));
  } elseif ($OptionType == 'P'){
   $m1 = application()->Exp(-1*$r * $T);
   $m2 = application()->NormSDist(-1 * dTwo($S, $X, $T, $r, $v, $d));
   $m3 = application()->Exp(-1 * $d * $T);
   $m4 = application()->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()->NormSDist(dOne($S, $X, $T, $r, $v, $d));
  }elseif ($OptionType == 'P'){
   $value = application()->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()->sqrt($T)));
   return $value;
}

function Vega($S, $X, $T, $r, $v, $d){
  $value = 0.01 * $S * application()->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()->NormSDist(dTwo($S, $X, $T, $r, $v, $d));
  }elseif ($OptionType == 'P'){
   $value = -0.01 * $X * $T * Exp(-1*$r * $T) * (1 - application()->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()->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()->sqrt($T)) + $r * $X * Exp(-1 * $r * ($T)) * (1 - NdTwo($S, $X, $T, $r, $v, $d))) / 365;
  }
  return $value;
}

Hope you like it.

Enjoy !!!

Downloads:

http://amolpandey.com/home/downloads/blog34_download.zip

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

*