StockAccount/Set.pm

filter: Statementstmt 90.4% 245 / 271 Branchbran 79.7% 67 / 84 Conditioncond 69.2% 27 / 39 MC/DCmcdc 58.3% 14 / 24 Subroutinesub 93.0% 40 / 43 Podpod 71.0% 27 / 38 totaltotal 84.1% 420 / 499 CC 64 SCAR 19.6
CC
64
Cov
86%
availableAcquisitions
30.0
dateLimitPortion
15.1
availableAcquisitionsString
12.0
CRAP 7.1
« StockAccount/Import/OptionsXpress.pm ↑ Summary StockAccount/Stock.pm »
1 package Finance::StockAccount::Set;
2  
3 6 our $VERSION = '0.01';
4  
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use Finance::StockAccount::Realization;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 45 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
15 45 my ($class, $init) = @_;
16 45 my $self = {
17 stock => undef,
18 accountTransactions => [],
19 realizations => [],
20 stats => getNewStatsHash(),
21 dateLimit => {
22 start => undef,
23 end => undef,
24 },
25 verbose => 0,
26 };
27 45 bless($self, $class);
28 45 ▶ $init and $self->add($init);
Branch: 1 branch
BranchTrueFalseTotal
$init and $self->add($init) 45 0 45
29 45 return $self;
30 }
31  
32 492 ▶sub getNewStatsHash {
Subroutine getNewStatsHash: called CC=1 SCAR=0.0
Pod undocumented
33 return {
34 492 stale => 1,
35 success => 0,
36 profit => 0,
37 totalOutlays => 0,
38 totalRevenues => 0,
39 commissions => 0,
40 regulatoryFees => 0,
41 otherFees => 0,
42 startDate => undef,
43 endDate => undef,
44 unrealizedTransactionCount => 0,
45 };
46 }
47  
48 460 ▶sub realizationCount {
Subroutine realizationCount: called CC=1 SCAR=0.0
Pod documented
49 460 my $self = shift;
50 460 return scalar(@{$self->{realizations}});
51 }
52  
53 1 ▶sub unrealizedTransactions {
Subroutine unrealizedTransactions: called CC=1 SCAR=0.0
Pod documented
54 1 my $self = shift;
55 1 return [grep { $_->accounted() == 0 } @{$self->{accountTransactions}}];
56 }
57  
58 0 ▶sub realizedTransactions {
Subroutine realizedTransactions: not called CC=1 SCAR=6.9
Pod documented
59 0 my $self = shift;
60 0 return [grep { $_->accounted() > 0 } @{$self->{accountTransactions}}];
61 }
62  
63 174 ▶sub transactionCount {
Subroutine transactionCount: called CC=3 SCAR=11.0
Pod documented
64 174 my $self = shift;
65 174 my $count = 0;
66 174 foreach my $at (@{$self->{accountTransactions}}) {
67 1514 ▶ $at->accounted() > 0 and $count++;
Branch: 1 branch
BranchTrueFalseTotal
$at->accounted > 0 and ++$count 1414 100 1514
68 }
69 174 return $count;
70 }
71  
72 102 ▶sub unrealizedTransactionCount {
Subroutine unrealizedTransactionCount: called CC=3 SCAR=11.0
Pod documented
73 102 my $self = shift;
74 102 my $count = 0;
75 102 foreach my $at (@{$self->{accountTransactions}}) {
76 588 ▶ $at->accounted() == 0 and $count++;
Branch: 1 branch
BranchTrueFalseTotal
$at->accounted == 0 and ++$count 83 505 588
77 }
78 102 return $count;
79 }
80  
81 0 ▶sub availableAcquisitions {
Subroutine availableAcquisitions: not called CC=5 SCAR=34.0
Pod documented
82 0 my $self = shift;
83 0 my @aa;
84 0 foreach my $at (@{$self->{accountTransactions}}) {
85 0 ▶ if ($at->available() and ($at->buy() or $at->short())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at->available and $at->buy || $at->short) 0 0 0
Condition0%0/6
$at->available and $at->buy || $at->short
!ll&&!rl&&r
000
$at->buy or $at->short
l!l&&r!l&&!r
000
MC/DC0%0/3
$at->available and $at->buy || $at->short
$at->available $at->buy $at->short
Truth table0%0/4
A and B or C
A= $at->availableB= $at->buyC= $at->short
ABCresult
0XX0
1000
11X1
1011
86 0 push(@aa, $at);
87 }
88 }
89 0 return \@aa;
90 }
91  
92 0 ▶sub availableAcquisitionsString {
Subroutine availableAcquisitionsString: not called CC=3 SCAR=24.8
Pod documented
93 0 my $self = shift;
94 0 my $aa = $self->availableAcquisitions();
95 0 my $string;
96 0 my $header = Finance::StockAccount::Transaction->lineFormatHeader();
97 0 foreach my $at (@$aa) {
98 0 $string .= $at->lineFormatString(1);
99 }
100 0 ▶ if ($string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string) { } 0 0 0
101 0 $string = $header . $string;
102 }
103 else {
104 0 $string = '';
105 }
106 0 return $string;
107 }
108  
109 1566 ▶sub stale {
Subroutine stale: called CC=5 SCAR=16.4
Pod documented
110 1566 my ($self, $assertion) = @_;
111 1566 ▶ if (defined($assertion)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $assertion) { } 706 860 1566
112 706 ▶ if ($assertion == 1 or $assertion == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($assertion == 1 or $assertion == 0) { } 706 0 706
Condition66%2/3
$assertion == 1 or $assertion == 0
l!l&&r!l&&!r
2604460
MC/DC0%0/2
$assertion == 1 or $assertion == 0
$assertion == 1 $assertion == 0
Truth table66%2/3
A or B
A= $assertion == 1B= $assertion == 0
ABresult
1X1
011
000
113 706 ▶ $self->{stats}{stale} = $assertion ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$assertion ? : 260 446 706
114 706 return 1;
115 }
116 else {
117 0 croak "Method 'stale' only accepts assertions in the form of 1 or 0 -- $assertion is not valid.";
118 }
119 }
120 else {
121 860 return $self->{stats}{stale};
122 }
123 }
124  
125 1 ▶sub symbol {
Subroutine symbol: called CC=1 SCAR=0.0
Pod documented
126 1 my $self = shift;
127 1 my $stock = $self->{stock};
128 1 return $stock->symbol();
129 }
130  
131 260 ▶sub add {
Subroutine add: called CC=9 SCAR=22.9
Pod undocumented
132 260 my ($self, $accountTransactions) = @_;
133 260 ▶ ($accountTransactions and 'ARRAY' eq ref($accountTransactions))
Branch: 1 branch
BranchTrueFalseTotal
$accountTransactions and "ARRAY" eq ref $accountTransactions or confess("Set->add([\$st1, \$st2, \$st3, ...]) ... method requires a reference to a list of st objects.\n") 260 0 260
Condition33%1/3
$accountTransactions and "ARRAY" eq ref $accountTransactions
!ll&&!rl&&r
00260
MC/DC0%0/2
$accountTransactions and "ARRAY" eq ref $accountTransactions
$accountTransactions "ARRAY" eq ref $accountTransactions
Truth table33%1/3
A and B
A= $accountTransactionsB= "ARRAY" eq ref $accountTransactions
ABresult
0X0
100
111
134 or confess "Set->add([\$st1, \$st2, \$st3, ...]) ... method requires a reference to a list of st objects.\n";
135 260 my $set = $self->{accountTransactions};
136 260 my $added = 0;
137 260 my $stock = $self->{stock};
138 260 foreach my $at (@$accountTransactions) {
139 266 ▶ 'Finance::StockAccount::AccountTransaction' eq ref($at) or confess "Not a valid at object.\n";
Branch: 1 branch
BranchTrueFalseTotal
"Finance::StockAccount::AccountTransaction" eq ref $at or confess("Not a valid at object.\n") 266 0 266
140 266 ▶ if (!$stock) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stock) 45 221 266
141 45 ▶ if ($stock = $at->stock()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stock = $at->stock) 45 0 45
142 45 $self->{stock} = $stock;
143 }
144 }
145 266 ▶ $stock->same($at->stock()) or croak "Given Stock Transaction object does not match stock for set, or set stock is undefined.";
Branch: 1 branch
BranchTrueFalseTotal
$stock->same($at->stock) or croak("Given Stock Transaction object does not match stock for set, or set stock is undefined.") 266 0 266
146 266 push(@$set, $at);
147 266 $added = 1;
148 }
149 260 ▶ if ($added) {
Branch: 1 branch
BranchTrueFalseTotal
if ($added) 260 0 260
150 260 $self->stale(1);
151 260 $self->{dateSort} = 0;
152 }
153 260 return $added;
154 }
155  
156 447 ▶sub clearPastAccounting {
Subroutine clearPastAccounting: called CC=2 SCAR=6.9
Pod undocumented
157 447 my $self = shift;
158 447 my $accountTransactions = $self->{accountTransactions};
159 447 ▶ for (my $x=0; $x<scalar(@$accountTransactions); $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < scalar @$accountTransactions) 2615 447 3062
160 2615 my $at = $accountTransactions->[$x];
161 2615 $at->resetAccounted();
162 }
163 447 $self->{realizations} = [];
164 447 $self->{stats} = $self->getNewStatsHash();
165 447 $self->{stats}{success} = 0;
166 447 return 1;
167 }
168  
169 350 ▶sub setDateLimit {
Subroutine setDateLimit: called CC=2 SCAR=7.1
Pod documented
170 350 my ($self, $tm1, $tm2) = @_;
171 350 ▶ if ($tm1 > $tm2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tm1 > $tm2) 0 350 350
172 0 croak "The start date must come before the end date.";
173 }
174 350 my $dateLimit = $self->{dateLimit};
175 350 $dateLimit->{start} = $tm1;
176 350 $dateLimit->{end} = $tm2;
177 350 $self->{stats}{stale} = 1;
178 350 return 1;
179 }
180  
181 338 ▶sub clearDateLimit {
Subroutine clearDateLimit: called CC=1 SCAR=0.0
Pod documented
182 338 my $self = shift;
183 338 my $dateLimit = $self->{dateLimit};
184 338 $dateLimit->{start} = undef;
185 338 $dateLimit->{end} = undef;
186 338 $self->{stats}{stale} = 1;
187 338 return 1;
188 }
189  
190 2603 ▶sub cmpPrice {
Subroutine cmpPrice: called CC=3 SCAR=11.0
Pod undocumented
191 2603 my ($self, $at1, $at2) = @_;
192 2603 my $p1 = $at1->{price};
193 2603 my $p2 = $at2->{price};
194 2603 ▶ return $p1 > $p2 ? 1 :
Branch: 2 branches
BranchTrueFalseTotal
$p1 > $p2 ? : 1969 634 2603
$p1 == $p2 ? : 300 334 634
195 $p1 == $p2 ? 0 :
196 -1;
197 }
198  
199 44 ▶sub dateSort {
Subroutine dateSort: called CC=1 SCAR=0.0
Pod undocumented
200 44 my $self = shift;
201 44 $self->{accountTransactions} = [sort { $a->tm() <=> $b->tm() } @{$self->{accountTransactions}}];
202 44 $self->{dateSort} = 1;
203 44 return 1;
204 }
205  
206 1 ▶sub transactionDates {
Subroutine transactionDates: called CC=2 SCAR=6.9
Pod documented
207 1 my $self = shift;
208 1 my $transactionDates = [];
209 1 foreach my $at (@{$self->{accountTransactions}}) {
210 5 push(@$transactionDates, $at->tm());
211 }
212 1 return $transactionDates;
213 }
214  
215 1 ▶sub printTransactionDates {
Subroutine printTransactionDates: called CC=1 SCAR=0.0
Pod documented
216 1 my $self = shift;
217 1 my $transactionDates = $self->transactionDates();
218 1 print join(', ', map { $_->to_string() } @$transactionDates), "\n";
219 1 return 1;
220 }
221  
222 1500 ▶sub dateLimitPortion {
Subroutine dateLimitPortion: called CC=15 SCAR=27.1
Pod undocumented
223 1500 my ($self, $divestment, $acquisition) = @_;
224 1500 my $dateLimit = $self->{dateLimit};
225 1500 ▶ if (!$dateLimit->{start} or !$dateLimit->{end}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dateLimit->{'start'} && $dateLimit->{'end'}) { } 332 1168 1500
Condition66%2/3
$dateLimit->{'start'} && $dateLimit->{'end'}
!ll&&!rl&&r
33201168
MC/DC50%1/2
$dateLimit->{'start'} && $dateLimit->{'end'}
$dateLimit->{'start'} $dateLimit->{'end'}
Truth table66%2/3
A && B
A= $dateLimit->{'start'}B= $dateLimit->{'end'}
ABresult
0X0
100
111
226 332 return 1;
227 }
228 else {
229 1168 my $limitStart = $dateLimit->{start};
230 1168 my $limitEnd = $dateLimit->{end};
231 1168 my $realStart = $acquisition->tm();
232 1168 my $realEnd = $divestment->tm();
233 1168 ▶ my $startWithinLimit = ($realStart <= $limitEnd and $realStart >= $limitStart) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$realStart <= $limitEnd && $realStart >= $limitStart ? : 186 982 1168
Condition100%3/3
$realStart <= $limitEnd and $realStart >= $limitStart
!ll&&!rl&&r
446536186
MC/DC100%2/2
$realStart <= $limitEnd and $realStart >= $limitStart
$realStart <= $limitEnd $realStart >= $limitStart
Truth table100%3/3
A and B
A= $realStart <= $limitEndB= $realStart >= $limitStart
ABresult
0X0
100
111
234 1168 ▶ my $endWithinLimit = ($realEnd <= $limitEnd and $realEnd >= $limitStart) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$realEnd <= $limitEnd && $realEnd >= $limitStart ? : 184 984 1168
Condition100%3/3
$realEnd <= $limitEnd and $realEnd >= $limitStart
!ll&&!rl&&r
568416184
MC/DC100%2/2
$realEnd <= $limitEnd and $realEnd >= $limitStart
$realEnd <= $limitEnd $realEnd >= $limitStart
Truth table100%3/3
A and B
A= $realEnd <= $limitEndB= $realEnd >= $limitStart
ABresult
0X0
100
111
235 1168 ▶ if ($startWithinLimit and $endWithinLimit) {
Branch: 5 branches
BranchTrueFalseTotal
if ($startWithinLimit and $endWithinLimit) { } 104 1064 1168
elsif ($realStart >= $limitEnd or $realEnd <= $limitStart) { } 862 202 1064
elsif (not $startWithinLimit || $endWithinLimit) { } 40 162 202
elsif ($startWithinLimit) { } 82 80 162
elsif ($endWithinLimit) { } 80 0 80
Condition100%3/3
$startWithinLimit and $endWithinLimit
!ll&&!rl&&r
98282104
MC/DC100%2/2
$startWithinLimit and $endWithinLimit
$startWithinLimit $endWithinLimit
Truth table100%3/3
A and B
A= $startWithinLimitB= $endWithinLimit
ABresult
0X0
100
111
236 104 return 1;
237 }
238 ▶ elsif ($realStart >= $limitEnd or $realEnd <= $limitStart) {
Condition100%3/3
$realStart >= $limitEnd or $realEnd <= $limitStart
l!l&&r!l&&!r
446416202
MC/DC100%2/2
$realStart >= $limitEnd or $realEnd <= $limitStart
$realStart >= $limitEnd $realEnd <= $limitStart
Truth table100%3/3
A or B
A= $realStart >= $limitEndB= $realEnd <= $limitStart
ABresult
1X1
011
000
239 862 return 0;
240 }
241 ▶ elsif (!$startWithinLimit and !$endWithinLimit) {
Condition100%3/3
$startWithinLimit || $endWithinLimit
l!l&&r!l&&!r
828040
MC/DC100%2/2
$startWithinLimit || $endWithinLimit
$startWithinLimit $endWithinLimit
Truth table100%3/3
A || B
A= $startWithinLimitB= $endWithinLimit
ABresult
1X1
011
000
242 40 my $limitRangeSeconds = $limitEnd->epoch() - $limitStart->epoch();
243 40 my $realRangeSeconds = $realEnd->epoch() - $realStart->epoch();
244 40 return $limitRangeSeconds / $realRangeSeconds;
245 }
246 elsif ($startWithinLimit) {
247 82 my $realRangeSeconds = $realEnd->epoch() - $realStart->epoch();
248 82 my $secondsWithinLimit = $limitEnd->epoch() - $realStart->epoch();
249 82 return $secondsWithinLimit / $realRangeSeconds;
250 }
251 elsif ($endWithinLimit) {
252 80 my $realRangeSeconds = $realEnd->epoch() - $realStart->epoch();
253 80 my $secondsWithinLimit = $realEnd->epoch() - $limitStart->epoch();
254 80 return $secondsWithinLimit / $realRangeSeconds;
255 }
256 else {
257 0 warn "Unexpected result from date comparisons when trying to calculate portion of realization within the given date limit.";
258 0 return 0;
259 }
260 }
261 }
262  
263 1004 ▶sub accountPriorPurchase {
Subroutine accountPriorPurchase: called CC=9 SCAR=22.0
Pod undocumented
264 1004 my ($self, $index) = @_;
265 1004 ▶ if (!$self->{dateSort}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dateSort"}) 0 1004 1004
266 0 confess "Cannot account prior purchase when transactions have not been sorted by date.\n";
267 }
268 1004 my $accountTransactions = $self->{accountTransactions};
269 1004 my $divestment = $accountTransactions->[$index];
270 1004 my $actionString = $divestment->actionString();
271 1004 my $realization = Finance::StockAccount::Realization->new({
272 stock => $divestment->stock(),
273 divestment => $divestment,
274 });
275
276 1004 my @priorPurchases = sort { $self->cmpPrice($a, $b) } grep { $_->possiblePurchase($actionString) } @{$accountTransactions}[0 .. $index];
277 1004 foreach my $priorPurchase (@priorPurchases) {
278 1894 my $sharesDivested = $divestment->available();
279 1894 ▶ last unless $sharesDivested;
Branch: 1 branch
BranchTrueFalseTotal
unless $sharesDivested 394 1500 1894
280 1500 my $accounted = $priorPurchase->accountShares($sharesDivested);
281 1500 ▶ if ($accounted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accounted) 1500 0 1500
282 1500 my $acquisition = Finance::StockAccount::Acquisition->new($priorPurchase, $accounted);
283 1500 my $dateLimitPortion = $self->dateLimitPortion($divestment, $acquisition);
284 1500 $realization->addAcquisition($acquisition, $dateLimitPortion);
285 1500 $divestment->accountShares($accounted);
286 }
287 }
288  
289 1004 ▶ if ($realization->acquisitionCount() and ($realization->costBasis() or $realization->revenue())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realization->acquisitionCount and $realization->costBasis || $realization->revenue) { } 387 617 1004
Condition83%5/6
$realization->acquisitionCount and $realization->costBasis || $realization->revenue
!ll&&!rl&&r
114503387
$realization->costBasis or $realization->revenue
l!l&&r!l&&!r
3870503
MC/DC66%2/3
$realization->acquisitionCount and $realization->costBasis || $realization->revenue
$realization->acquisitionCount $realization->costBasis $realization->revenue
Truth table75%3/4
A and B or C
A= $realization->acquisitionCountB= $realization->costBasisC= $realization->revenue
ABCresult
0XX0
1000
11X1
1011
290 387 push(@{$self->{realizations}}, $realization);
291 387 $self->startDate($realization->startDate());
292 387 $self->endDate($realization->endDate());
293 387 my $stats = $self->{stats};
294 387 $stats->{profit} += $realization->realized();
295 387 $stats->{totalOutlays} += $realization->costBasis();
296 387 $stats->{totalRevenues} += $realization->revenue();
297 387 $stats->{commissions} += $realization->commissions();
298 387 $stats->{regulatoryFees} += $realization->regulatoryFees();
299 387 $stats->{otherFees} += $realization->otherFees();
300 387 $stats->{success} = 1;
301 387 return 1;
302 }
303 else {
304 617 my $symbol = $divestment->symbol();
305 617 ▶ $self->{verbose} and print "[Info] Unable to account for sold shares of symbol $symbol at index $index. There is no acquisition that matches this divestment.\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and print "[Info] Unable to account for sold shares of symbol $symbol at index $index. There is no acquisition that matches this divestment.\n" 0 617 617
306 617 return 0;
307 }
308 }
309  
310 446 ▶sub accountSales {
Subroutine accountSales: called CC=6 SCAR=18.0
Pod documented
311 446 my $self = shift;
312 446 $self->clearPastAccounting();
313 446 ▶ if (!$self->{dateSort}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dateSort"}) 44 402 446
314 44 $self->dateSort();
315 }
316 446 my $accountTransactions = $self->{accountTransactions};
317 446 my $status = 0;
318 446 ▶ for (my $x=0; $x<scalar(@$accountTransactions); $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < scalar @$accountTransactions) 2612 446 3058
319 2612 my $at = $accountTransactions->[$x];
320 2612 ▶ if ($at->sell() or $at->short()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at->sell or $at->short) 1004 1608 2612
Condition66%2/3
$at->sell or $at->short
l!l&&r!l&&!r
100401608
MC/DC50%1/2
$at->sell or $at->short
$at->sell $at->short
Truth table66%2/3
A or B
A= $at->sellB= $at->short
ABresult
1X1
011
000
321 1004 ▶ if ($at->available()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at->available) 1004 0 1004
322 1004 $status += $self->accountPriorPurchase($x);
323 }
324 }
325 }
326 446 $self->stale(0);
327 446 return $status;
328 }
329  
330 460 ▶sub startDate {
Subroutine startDate: called CC=4 SCAR=13.9
Pod documented
331 460 my ($self, $tm) = @_;
332 460 my $startDate = $self->{stats}{startDate};
333 460 ▶ if ($tm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tm) { } 387 73 460
334 387 ▶ if (!$startDate) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $startDate) { } 179 208 387
elsif ($tm < $startDate) { } 57 151 208
335 179 $self->{stats}{startDate} = $tm;
336 179 return 1;
337 }
338 elsif ($tm < $startDate) {
339 57 $self->{stats}{startDate} = $tm;
340 57 return 1;
341 }
342 else {
343 151 return 0;
344 }
345 }
346 else {
347 73 return $startDate;
348 }
349 }
350  
351 460 ▶sub endDate {
Subroutine endDate: called CC=4 SCAR=13.9
Pod documented
352 460 my ($self, $tm) = @_;
353 460 my $endDate = $self->{stats}{endDate};
354 460 ▶ if ($tm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tm) { } 387 73 460
355 387 ▶ if (!$endDate) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $endDate) { } 179 208 387
elsif ($tm > $endDate) { } 181 27 208
356 179 $self->{stats}{endDate} = $tm;
357 179 return 1;
358 }
359 elsif ($tm > $endDate) {
360 181 $self->{stats}{endDate} = $tm;
361 181 return 1;
362 }
363 else {
364 27 return 0;
365 }
366 }
367 else {
368 73 return $endDate;
369 }
370 }
371  
372 1303 ▶sub checkStats {
Subroutine checkStats: called CC=2 SCAR=6.9
Pod documented
373 1303 my $self = shift;
374 1303 ▶ if ($self->{stats}{stale}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"stats"}{"stale"}) 13 1290 1303
375 13 $self->accountSales();
376 }
377 1303 return 1;
378 }
379  
380 2 ▶sub profitOverOutlays {
Subroutine profitOverOutlays: called CC=1 SCAR=0.0
Pod documented
381 2 my $self = shift;
382 2 $self->checkStats();
383 2 my $stats = $self->{stats};
384 2 return $stats->{profit} / $stats->{totalOutlays};
385 }
386  
387 185 ▶sub profit {
Subroutine profit: called CC=1 SCAR=0.0
Pod documented
388 185 my $self = shift;
389 185 $self->checkStats();
390 185 return $self->{stats}{profit};
391 }
392  
393 172 ▶sub totalOutlays {
Subroutine totalOutlays: called CC=1 SCAR=0.0
Pod documented
394 172 my $self = shift;
395 172 $self->checkStats();
396 172 return $self->{stats}{totalOutlays};
397 }
398  
399 172 ▶sub totalRevenues {
Subroutine totalRevenues: called CC=1 SCAR=0.0
Pod documented
400 172 my $self = shift;
401 172 $self->checkStats();
402 172 return $self->{stats}{totalRevenues};
403 }
404  
405 170 ▶sub commissions {
Subroutine commissions: called CC=1 SCAR=0.0
Pod documented
406 170 my $self = shift;
407 170 $self->checkStats();
408 170 return $self->{stats}{commissions};
409 }
410  
411 170 ▶sub regulatoryFees {
Subroutine regulatoryFees: called CC=1 SCAR=0.0
Pod documented
412 170 my $self = shift;
413 170 $self->checkStats();
414 170 return $self->{stats}{regulatoryFees};
415 }
416  
417 170 ▶sub otherFees {
Subroutine otherFees: called CC=1 SCAR=0.0
Pod documented
418 170 my $self = shift;
419 170 $self->checkStats();
420 170 return $self->{stats}{otherFees};
421 }
422  
423 72 ▶sub success {
Subroutine success: called CC=1 SCAR=0.0
Pod documented
424 72 my $self = shift;
425 72 $self->checkStats();
426 72 return $self->{stats}{success};
427 }
428  
429 190 ▶sub realizations {
Subroutine realizations: called CC=1 SCAR=0.0
Pod documented
430 190 my $self = shift;
431 190 $self->checkStats();
432 190 return $self->{realizations};
433 }
434  
435 20 ▶sub realizationsString {
Subroutine realizationsString: called CC=2 SCAR=6.9
Pod documented
436 20 my $self = shift;
437 20 my $string;
438 20 foreach my $realization (@{$self->realizations()}) {
439 53 $string .= '='x94 . "\n" . $realization->string() . "\n";
440 }
441 20 return $string;
442 }
443  
444 1 ▶sub oneLinerSpacer {
Subroutine oneLinerSpacer: called CC=1 SCAR=0.0
Pod undocumented
445 1 return '-'x80 . "\n";
446 }
447  
448 1 ▶sub oneLinerHeader {
Subroutine oneLinerHeader: called CC=1 SCAR=0.0
Pod undocumented
449 1 my $self = shift;
450 1 return sprintf("%-6s %7s %12s %12s %39s\n", qw(Symbol ROI Outlays Revenues Profit));
451 }
452  
453 1 ▶sub oneLiner {
Subroutine oneLiner: called CC=1 SCAR=0.0
Pod undocumented
454 1 my $self = shift;
455 1 return sprintf("%-6s %7.2f %12.2f %12.2f %39.2f\n", $self->symbol(), $self->profitOverOutlays(), $self->totalOutlays(), $self->totalRevenues(), $self->profit());
456 }
457  
458  
459 6 1;
460  
461  
462 __END__
« StockAccount/Import/OptionsXpress.pm ↑ Summary StockAccount/Stock.pm »