Math-Business-BlackScholes-Binaries-Greeks
view release on metacpan or search on metacpan
lib/Math/Business/BlackScholes/Binaries/Greeks/Delta.pm view on Meta::CPAN
my $mu_new = $mu - (0.5 * $vol * $vol);
my $mu_dash =
sqrt(max($Math::Business::BlackScholesMerton::Binaries::SMALL_VALUE_MU, ($mu_new * $mu_new) + (2 * $vol * $vol * $r_q * (1 - $w))));
my $series_part = 0;
my $hyp_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 2);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($vol * $vol) + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
my $phi = ($vol * $vol) / ($h * $h * $h) * exp(-$lambda_k_dash * $t) * $k * $k / $lambda_k_dash;
$series_part += $phi * $pi * $pi * cos($k * $pi * ($h - $x) / $h);
#
# For delta, the stability function is $phi/$S, for gamma it is different,
# but we shall ignore for now.
#
lib/Math/Business/BlackScholes/Binaries/Greeks/Gamma.pm view on Meta::CPAN
my $mu_ = $mu - (0.5 * $vol * $vol);
my $mu_dash =
sqrt(max($Math::Business::BlackScholesMerton::Binaries::SMALL_VALUE_MU, ($mu_ * $mu_) + (2 * $vol * $vol * $r_q * (1 - $w))));
my $series_part = 0;
my $hyp_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 3);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($vol * $vol) + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
my $phi = ($vol * $vol) / ($h**4) * exp(-$lambda_k_dash * $t) * ($k**3) / $lambda_k_dash;
$series_part += $phi * ($pi**3) * sin($k * $pi * ($h - $x) / $h);
if ($k == 1
and (not(abs($phi / ($S**2)) < $stability_constant)))
{
die
lib/Math/Business/BlackScholes/Binaries/Greeks/Theta.pm view on Meta::CPAN
my $mu_ = $mu - (0.5 * $vol * $vol);
my $mu_dash =
sqrt(max($Math::Business::BlackScholesMerton::Binaries::SMALL_VALUE_MU, ($mu_ * $mu_) + (2 * $vol * $vol * $r_q * (1 - $w))));
my $hyp_part = 0;
my $series_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 1);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($vol * $vol) + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
my $phi = ($vol * $vol) / ($h * $h) * (1 + ($r_q * $w / $lambda_k_dash)) * exp(-($r_q * $w + $lambda_k_dash) * $t) * $k;
$series_part += $phi * $pi * sin($k * $pi * ($h - $x) / $h);
if ($k == 1 and (not(abs($phi) < $stability_constant))) {
die
"$0: PELSSER THETA formula for S=$S, U=$U, D=$D, t=$t, r=$r_q, mu=$mu, vol=$vol, w=$w, eta=$eta cannot be evaluated because PELSSER THETA stability conditions ($phi less than $stability_constant) not met. This could be due to barriers...
}
lib/Math/Business/BlackScholes/Binaries/Greeks/Vanna.pm view on Meta::CPAN
my $mu_dash = sqrt(max($Math::Business::BlackScholesMerton::Binaries::SMALL_VALUE_MU, ($mu_new * $mu_new) + (2 * $vol * $vol * $r_dash)));
my $omega = ($vol * $vol);
my $series_part = 0;
my $hyp_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 1);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($vol * $vol) + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
# d{lambda_k}/dw
my $dlambdak_domega = 0.5 * (-($mu_new / $omega) - (($mu_new * $mu_new) / ($omega * $omega)) + (($k * $k * $pi * $pi) / ($h * $h)));
my $beta_k = exp(-$lambda_k_dash * $t) / $lambda_k_dash;
# d{beta_k}/d{lambda_k}
my $dbetak_dlambdak = -exp(-$lambda_k_dash * $t) * (($t * $lambda_k_dash + 1) / ($lambda_k_dash**2));
lib/Math/Business/BlackScholes/Binaries/Greeks/Vega.pm view on Meta::CPAN
my $mu_dash = sqrt(max($Math::Business::BlackScholesMerton::Binaries::SMALL_VALUE_MU, ($mu_new * $mu_new) + (2 * $vol * $vol * $r_dash)));
my $omega = ($vol * $vol);
my $series_part = 0;
my $hyp_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 1);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / $omega + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
# d{lambda_k}/dw
my $dlambdak_domega = 0.5 * (-($mu_new / $omega) - (($mu_new * $mu_new) / ($omega * $omega)) + (($k * $k * $pi * $pi) / ($h * $h)));
my $beta_k = exp(-$lambda_k_dash * $t) / $lambda_k_dash;
# d{beta_k}/d{lambda_k}
my $dbetak_dlambdak = -exp(-$lambda_k_dash * $t) * (($t * $lambda_k_dash + 1) / ($lambda_k_dash**2));
lib/Math/Business/BlackScholes/Binaries/Greeks/Volga.pm view on Meta::CPAN
my $r_dash = $r_q * (1 - $w);
my $omega = ($vol * $vol);
my $series_part = 0;
my $hyp_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 1);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($vol * $vol) + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
# d{lambda_k}/dw
my $dlambdak_domega = 0.5 * (-($mu_new / $omega) - (($mu_new * $mu_new) / ($omega * $omega)) + (($k * $k * $pi * $pi) / ($h * $h)));
my $d2lambdak_domega2 = 0.5 * ($omega + 2 * $mu_new) / (2 * $omega * $omega);
$d2lambdak_domega2 *= (1 + (2 * $mu_new / $omega));
# d{beta_k}/d{lambda_k}
my $dbetak_dlambdak = -exp(-$lambda_k_dash * $t) * (($t * $lambda_k_dash + 1) / ($lambda_k_dash**2));
my $d2betak_dlambdak2 = -($t * $dbetak_dlambdak) + exp(-$lambda_k_dash * $t) * (($t / ($lambda_k_dash**2)) + (2 / ($lambda_k_dash**3)));
( run in 2.122 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )