line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
use strict; |
2
|
2
|
|
|
2
|
|
123751
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
60
|
|
3
|
2
|
|
|
2
|
|
11
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
4
|
|
|
|
|
|
|
use List::Util qw(max min); |
5
|
2
|
|
|
2
|
|
12
|
use Math::CDF qw(pnorm); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
176
|
|
6
|
2
|
|
|
2
|
|
463
|
|
|
2
|
|
|
|
|
2863
|
|
|
2
|
|
|
|
|
107
|
|
7
|
|
|
|
|
|
|
use Math::Business::Lookback::Common; |
8
|
2
|
|
|
2
|
|
421
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1818
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; ## VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head2 lbfixedcall |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Delta of a Lookback Fixed Call |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min) = @_; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
1
|
1788
|
my $delta; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
13
|
$S_min = undef; |
22
|
|
|
|
|
|
|
my $a1 = _a1($S, $K, $t, $r_q, $mu, $sigma, max($S_max, $K)); |
23
|
2
|
|
|
|
|
4
|
|
24
|
2
|
|
|
|
|
15
|
$delta = exp(($mu - $r_q) * $t) * pnorm($a1) + _l_max_delta($S, $K, $t, $r_q, $mu, $sigma, max($S_max, $K)); |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
49
|
return $delta; |
27
|
|
|
|
|
|
|
} |
28
|
2
|
|
|
|
|
5
|
|
29
|
|
|
|
|
|
|
=head2 lbfixedput |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Delta of a Lookback Fixed Put |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $delta; |
38
|
2
|
|
|
2
|
1
|
1393
|
|
39
|
|
|
|
|
|
|
$S_max = undef; |
40
|
2
|
|
|
|
|
6
|
my $a1 = _a1($S, $K, $t, $r_q, $mu, $sigma, min($S_min, $K)); |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
5
|
$delta = -exp(($mu - $r_q) * $t) * pnorm(-$a1) + _l_min_delta($S, $K, $t, $r_q, $mu, $sigma, min($S_min, $K)); |
43
|
2
|
|
|
|
|
12
|
|
44
|
|
|
|
|
|
|
return $delta; |
45
|
2
|
|
|
|
|
21
|
} |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
6
|
=head2 lbfloatcall |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Delta of a Lookback Float Call |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $delta; |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
3
|
1
|
1462
|
$S_max = undef; |
58
|
|
|
|
|
|
|
my $a1 = _a1($S, $K, $t, $r_q, $mu, $sigma, $S_min); |
59
|
3
|
|
|
|
|
6
|
|
60
|
|
|
|
|
|
|
$delta = exp(($mu - $r_q) * $t) * pnorm($a1) + _l_min_delta($S, $K, $t, $r_q, $mu, $sigma, $S_min); |
61
|
3
|
|
|
|
|
6
|
|
62
|
3
|
|
|
|
|
10
|
return $delta; |
63
|
|
|
|
|
|
|
} |
64
|
3
|
|
|
|
|
25
|
|
65
|
|
|
|
|
|
|
=head2 lbfloatput |
66
|
3
|
|
|
|
|
10
|
|
67
|
|
|
|
|
|
|
Delta of a Lookback Float Put |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $delta; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$S_min = undef; |
76
|
3
|
|
|
3
|
1
|
1220
|
my $a1 = _a1($S, $K, $t, $r_q, $mu, $sigma, $S_max); |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
7
|
$delta = -exp(($mu - $r_q) * $t) * pnorm(-$a1) + _l_max_delta($S, $K, $t, $r_q, $mu, $sigma, $S_max); |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
5
|
return $delta; |
81
|
3
|
|
|
|
|
10
|
} |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
24
|
=head2 lbhighlow |
84
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
8
|
Delta of a Lookback HighLow |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min) = @_; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $delta = lbfloatcall($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min) + lbfloatput($S, $K, $t, $r_q, $mu, $sigma, $S_max, $S_min); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return $delta; |
94
|
|
|
|
|
|
|
} |
95
|
1
|
|
|
1
|
1
|
643
|
|
96
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_min_or_max) = @_; |
97
|
1
|
|
|
|
|
4
|
|
98
|
|
|
|
|
|
|
my $a1 = (log($S / $S_min_or_max) + ($mu + (0.5 * ($sigma**2))) * $t) / ($sigma * sqrt($t)); |
99
|
1
|
|
|
|
|
2
|
|
100
|
|
|
|
|
|
|
return $a1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
20
|
|
|
20
|
|
45
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_min) = @_; |
104
|
|
|
|
|
|
|
|
105
|
20
|
|
|
|
|
82
|
my $a1 = _a1($S, $K, $t, $r_q, $mu, $sigma, $S_min); |
106
|
|
|
|
|
|
|
|
107
|
20
|
|
|
|
|
41
|
my $l_min_delta; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if ($mu == 0) { |
110
|
|
|
|
|
|
|
$l_min_delta = exp(-$r_q * $t) * $sigma * sqrt($t) * Math::Business::Lookback::Common::dnorm($a1); |
111
|
5
|
|
|
5
|
|
15
|
$l_min_delta = $l_min_delta + exp(-$r_q * $t) * (pnorm($a1) - 1) * (log($S / $S_min) + 1 + ($mu * $t) + (0.5 * ($sigma**2) * $t)); |
112
|
|
|
|
|
|
|
} else { |
113
|
5
|
|
|
|
|
13
|
$l_min_delta = (exp(($mu - $r_q) * $t) * 0.5 * ($sigma**2) * pnorm(-$a1)) / $mu; |
114
|
|
|
|
|
|
|
$l_min_delta = |
115
|
5
|
|
|
|
|
9
|
$l_min_delta + |
116
|
|
|
|
|
|
|
(-1 + 0.5 * ($sigma**2) / $mu) * |
117
|
5
|
100
|
|
|
|
17
|
exp(-$r_q * $t) * |
118
|
2
|
|
|
|
|
11
|
(($S / $S_min)**(-2 * $mu / ($sigma**2))) * |
119
|
2
|
|
|
|
|
23
|
pnorm(-$a1 + (2 * $mu * sqrt($t)) / $sigma); |
120
|
|
|
|
|
|
|
} |
121
|
3
|
|
|
|
|
13
|
|
122
|
3
|
|
|
|
|
20
|
return $l_min_delta; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my ($S, $K, $t, $r_q, $mu, $sigma, $S_max) = @_; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $b1 = _a1($S, $K, $t, $r_q, $mu, $sigma, $S_max); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $l_max_delta; |
130
|
5
|
|
|
|
|
15
|
|
131
|
|
|
|
|
|
|
if ($mu == 0) { |
132
|
|
|
|
|
|
|
$l_max_delta = exp(-$r_q * $t) * $sigma * sqrt($t) * Math::Business::Lookback::Common::dnorm($b1); |
133
|
|
|
|
|
|
|
$l_max_delta = $l_max_delta + exp(-$r_q * $t) * pnorm($b1) * (log($S / $S_max) + 1 + ($mu * $t) + (0.5 * ($sigma**2) * $t)); |
134
|
5
|
|
|
5
|
|
18
|
} else { |
135
|
|
|
|
|
|
|
$l_max_delta = (exp(($mu - $r_q) * $t) * 0.5 * ($sigma**2) * pnorm($b1)) / $mu; |
136
|
5
|
|
|
|
|
15
|
$l_max_delta = $l_max_delta + |
137
|
|
|
|
|
|
|
(1 - 0.5 * ($sigma**2) / $mu) * exp(-$r_q * $t) * (($S / $S_max)**(-2 * $mu / ($sigma**2))) * pnorm($b1 - (2 * $mu * sqrt($t)) / $sigma); |
138
|
5
|
|
|
|
|
10
|
} |
139
|
|
|
|
|
|
|
|
140
|
5
|
100
|
|
|
|
16
|
return $l_max_delta; |
141
|
2
|
|
|
|
|
11
|
} |
142
|
2
|
|
|
|
|
12
|
|
143
|
|
|
|
|
|
|
1; |