line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::StockAccount::AccountTransaction; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
3672
|
use parent 'Finance::StockAccount::Transaction'; |
|
9
|
|
|
|
|
1862
|
|
|
9
|
|
|
|
|
45
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
410
|
use strict; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
270
|
|
8
|
9
|
|
|
9
|
|
41
|
use warnings; |
|
9
|
|
|
|
|
11
|
|
|
9
|
|
|
|
|
3656
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
275
|
|
|
275
|
0
|
3887
|
my ($class, $init) = @_; |
13
|
275
|
|
|
|
|
752
|
my $self = $class->SUPER::new($init); |
14
|
275
|
|
|
|
|
354
|
$self->{accounted} = 0; |
15
|
275
|
|
|
|
|
523
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub accounted { |
19
|
2161
|
|
|
2161
|
0
|
1645
|
my ($self, $accounted) = @_; |
20
|
2161
|
50
|
|
|
|
2316
|
if ($accounted) { |
21
|
0
|
|
|
|
|
0
|
$self->{accounted} = $accounted; |
22
|
0
|
|
|
|
|
0
|
return 1; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
2161
|
|
|
|
|
5429
|
return $self->{accounted}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub resetAccounted { |
30
|
2615
|
|
|
2615
|
0
|
1889
|
my $self = shift; |
31
|
2615
|
|
|
|
|
2782
|
$self->{accounted} = 0; |
32
|
2615
|
|
|
|
|
5146
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub available { |
36
|
11809
|
|
|
11809
|
0
|
9159
|
my $self = shift; |
37
|
11809
|
|
|
|
|
12358
|
my $available = $self->{quantity} - $self->{accounted}; |
38
|
11809
|
100
|
|
|
|
25083
|
return ($available > 0 ? $available : 0); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub accountShares { |
42
|
3001
|
|
|
3001
|
0
|
3073
|
my ($self, $shares) = @_; |
43
|
3001
|
50
|
33
|
|
|
9243
|
unless ($shares and $shares > 0) { |
44
|
0
|
|
|
|
|
0
|
warn "AccountShares of $shares bad input.\n"; |
45
|
0
|
|
|
|
|
0
|
return 0; |
46
|
|
|
|
|
|
|
} |
47
|
3001
|
|
|
|
|
3850
|
my $available = $self->available(); |
48
|
3001
|
50
|
|
|
|
5383
|
if (0 == $available) { |
|
|
100
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
warn "Requested accountShares but no shares available.\n"; |
50
|
0
|
|
|
|
|
0
|
return 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ($shares > $available) { |
53
|
644
|
|
|
|
|
855
|
$self->{accounted} = $self->{quantity}; |
54
|
644
|
|
|
|
|
1077
|
return $available; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
2357
|
|
|
|
|
2326
|
$self->{accounted} += $shares; |
58
|
2357
|
|
|
|
|
5018
|
return $shares; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub possiblePurchase { |
63
|
9475
|
|
|
9475
|
0
|
8136
|
my ($self, $actionString) = @_; |
64
|
9475
|
100
|
66
|
|
|
22517
|
if ( (($actionString eq 'sell' and $self->buy()) or |
|
|
|
100
|
|
|
|
|
65
|
|
|
|
|
|
|
($actionString eq 'cover' and $self->short())) |
66
|
|
|
|
|
|
|
and $self->available()) { |
67
|
2631
|
|
|
|
|
4626
|
return 1; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
6844
|
|
|
|
|
13077
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub hashKey { |
75
|
257
|
|
|
257
|
0
|
235
|
my $self = shift; |
76
|
257
|
|
|
|
|
476
|
my $stock = $self->stock(); |
77
|
257
|
|
|
|
|
526
|
return $stock->hashKey(); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub lineFormatValues { |
81
|
147
|
|
|
147
|
0
|
143
|
my ($self, $available) = @_; |
82
|
147
|
|
|
|
|
312
|
my $lineFormatValues = $self->SUPER::lineFormatValues(); |
83
|
147
|
50
|
|
|
|
293
|
$lineFormatValues->[3] = $available ? $self->available : $self->{accounted}; |
84
|
147
|
|
|
|
|
227
|
return $lineFormatValues; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub lineFormatString { |
88
|
0
|
|
|
0
|
0
|
|
my ($self, $available) = @_; |
89
|
0
|
|
|
|
|
|
return sprintf(Finance::StockAccount::Transaction->lineFormatPattern(), @{$self->lineFormatValues($available)}); |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |