Math-Business-BlackscholesMerton

 view release on metacpan or  search on metacpan

t/BlackScholes.t  view on Meta::CPAN

        type     => 'put',
        barriers => [1.34],
        foreign  => 0.3096,
        domestic => 0.315,
    },
    {
        type     => 'onetouch',
        barriers => [1.36],
        foreign  => 0.6307,
        domestic => 0.6261,
    },
    {
        type     => 'notouch',
        barriers => [1.36],
        foreign  => 0.3692,
        domestic => 0.3739,
    },
    {
        type     => 'expiryrange',
        barriers => [1.36, 1.34],
        foreign  => 0.3732,
        domestic => 0.3732,
    },
    {
        type     => 'expirymiss',
        barriers => [1.36, 1.34],
        foreign  => 0.6268,
        domestic => 0.6268,
    },
    {
        type     => 'range',
        barriers => [1.36, 1.34],
        foreign  => 0.006902,
        domestic => 0.006902,
    },
    {
        type     => 'upordown',
        barriers => [1.36, 1.34],
        foreign  => 0.993093,
        domestic => 0.993088,
    },
    {
        type     => 'range',
        barriers => [1.35, 1.34],
        foreign  => 0,
        domestic => 0,
    },
    {
        type     => 'upordown',
        barriers => [1.36, 1.35],
        foreign  => 1,
        domestic => 1,
    },

);

foreach
    my $test_group (['Math::Business::BlackScholesMerton::Binaries::', \@binaries], ['Math::Business::BlackScholesMerton::NonBinaries::', \@vanillas])
{
    foreach my $test_case (@{$test_group->[1]}) {
        my $formula_name = $test_group->[0] . $test_case->{type};
        my %probs        = (
            domestic => &$formula_name($S, @{$test_case->{barriers}}, $t, $r, $r - $q,             $sigma),
            foreign  => &$formula_name($S, @{$test_case->{barriers}}, $t, $q, $r - $q + $sigma**2, $sigma),
        );

        foreach my $curr (sort keys %probs) {
            my $length = length($test_case->{$curr});
            my $precision = ($length < 2) ? 1 : 10**(-1 * ($length - 2));
            is(roundnear($precision, $probs{$curr}), $test_case->{$curr}, $test_case->{type} . ' ' . $curr);
        }
    }
}



( run in 1.090 second using v1.01-cache-2.11-cpan-b16cb0d3907 )