| 1 | package Finance::StockAccount::Realization; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Time::Moment; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Finance::StockAccount::AccountTransaction; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Finance::StockAccount::Acquisition; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # qw(Symbol ROI Outlays Revenues Profit) | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | my $summaryPattern = "%-6s %7.4f %12.2f %12.2f %53.2f\n"; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1006 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1006 | my ($class, $init) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1006 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 20 | stock => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | divestment => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | acquisitions => [], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | costBasis => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | revenue => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | realized => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | commissions => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | regulatoryFees => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | otherFees => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 1006 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1006 | ▶ | $init and $self->set($init); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1006 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1504 | ▶ | sub addAcquisition { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addAcquisition: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1504 | my ($self, $acquisition, $dateLimitPortion) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1504 | ▶ | if (!defined($dateLimitPortion)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | $dateLimitPortion = 1; # Assume no date limit restriction if none specified, i.e., none by default | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1504 | my $shares = $acquisition->shares(); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1504 | my $divestment = $self->{divestment}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 1504 | my $divQuantity = $divestment->quantity(); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1504 | my $divestedPortion; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1504 | ▶ | if ($divQuantity) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1504 | $divestedPortion = $shares / $divQuantity; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | croak "No shares divested in transaction, cannot proceed with realization."; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1504 | my $divCommission += $divestedPortion * $divestment->commission(); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1504 | my $divRegulatoryFees += $divestedPortion * $divestment->regulatoryFees(); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1504 | my $divOtherFees += $divestedPortion * $divestment->otherFees(); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1504 | my $costBasis = 0 - $dateLimitPortion * $acquisition->cashEffect(); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1504 | my $revenue = $dateLimitPortion * $divestedPortion * $divestment->cashEffect(); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1504 | $self->{costBasis} += $costBasis; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 1504 | $self->{revenue} += $revenue; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 1504 | $self->{realized} += $revenue - $costBasis; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 1504 | $self->{commissions} += $dateLimitPortion * ($acquisition->commission() + $divCommission ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 1504 | $self->{regulatoryFees} += $dateLimitPortion * ($acquisition->regulatoryFees() + $divRegulatoryFees); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 1504 | $self->{otherFees} += $dateLimitPortion * ($acquisition->otherFees() + $divOtherFees ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1504 | push(@{$self->{acquisitions}}, $acquisition); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1504 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1006 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=7 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1006 | my ($self, $init) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1006 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1006 | foreach my $key (keys %{$init}) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 2012 | ▶ | if (exists($self->{$key})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2012 | ▶ | if ($key eq 'divestment') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1006 | my $divestment = $init->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1006 | ▶ | if ($divestment and ref($divestment)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$divestment and ref $divestment
MC/DC0%0/2
$divestment and ref $divestment
$divestment
ref $divestment
Truth table33%1/3
A and B
A= $divestmentB= ref $divestment
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1006 | $self->{divestment} = $divestment; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $status = 0; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | warn "Invalid divestment value in Realization intialization hash.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | elsif ($key eq 'stock') { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 1006 | $self->{$key} = $init->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $status = 0; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | warn "Unable to initialize Realization object with $key parameter.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $status = 0; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | warn "Tried to set $key in Realization object, but that's not a known key.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 1006 | return $status; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 54 | ▶ | sub ROI { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ROI: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 54 | my $costBasis = $self->{costBasis}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 54 | ▶ | if ($costBasis) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 54 | return $self->{realized} / $costBasis; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | warn "Realize method finds no cost basis upon which to compute ROI.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1005 | ▶ | sub acquisitionCount { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acquisitionCount: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1005 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 1005 | return scalar(@{$self->{acquisitions}}); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 387 | ▶ | sub startDate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startDate: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 387 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 387 | my $startDate; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 387 | foreach my $acquisition (@{$self->{acquisitions}}) { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 667 | ▶ | if (!$startDate) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 387 | $startDate = $acquisition->tm(); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 280 | my $tm = $acquisition->tm(); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 280 | ▶ | if ($tm < $startDate) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 186 | $startDate = $tm; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 387 | return $startDate; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 387 | ▶ | sub endDate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
endDate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 387 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 387 | my $divestment = $self->{divestment}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 387 | return $divestment->tm(); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 378 | ▶ | sub divestment { return shift->{divestment}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
divestment: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 378 | ▶ | sub acquisitions { return shift->{acquisitions}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acquisitions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 1277 | ▶ | sub costBasis { return shift->{costBasis}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
costBasis: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 890 | ▶ | sub revenue { return shift->{revenue}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
revenue: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 389 | ▶ | sub realized { return shift->{realized}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
realized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 387 | ▶ | sub commissions { return shift->{commissions}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commissions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 387 | ▶ | sub regulatoryFees { return shift->{regulatoryFees}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regulatoryFees: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 387 | ▶ | sub otherFees { return shift->{otherFees}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
otherFees: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | sub headerString { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headerString: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | return Finance::StockAccount::Transaction->lineFormatHeader() . '-'x94 . "\n" . | |||||||||||||||||||||||||||||||||||||||||
| 151 | sprintf("%-6s %7s %12s %12s %53s\n", qw(Symbol ROI Outlays Revenues Profit)); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 54 | ▶ | sub divestmentLineFormatString { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
divestmentLineFormatString: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 54 | my $divestment = $self->{divestment}; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 54 | my $proportion = $divestment->accounted() / $divestment->quantity(); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 54 | my $lineFormatValues = $divestment->lineFormatValues(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 54 | $lineFormatValues->[5] *= $proportion; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 54 | $lineFormatValues->[6] *= $proportion; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 54 | $lineFormatValues->[7] *= $proportion; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 54 | return sprintf(Finance::StockAccount::Transaction->lineFormatPattern(), @$lineFormatValues); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 54 | ▶ | sub string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 54 | my $divestment = $self->{divestment}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 54 | my $string; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 54 | foreach my $acquisition (@{$self->{acquisitions}}) { | |||||||||||||||||||||||||||||||||||||||||
| 170 | 93 | $string .= $acquisition->lineFormatString(); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | $string .= $self->divestmentLineFormatString . '-'x94 . "\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 54 | ▶ | sprintf($summaryPattern, $divestment->symbol(), $self->ROI() || 0, (0 - $self->{costBasis}) || 0, $self->{revenue} || 0, $self->{realized} || 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$self->ROI || 0
0 - $self->{'costBasis'} || 0
$self->{'revenue'} || 0
$self->{'realized'} || 0
MC/DC0%0/1
$self->ROI || 0
$self->ROI
MC/DC0%0/1
0 - $self->{'costBasis'} || 0
0 - $self->{'costBasis'}
MC/DC0%0/1
$self->{'revenue'} || 0
$self->{'revenue'}
MC/DC0%0/1
$self->{'realized'} || 0
$self->{'realized'}
Truth table50%1/2
A
A= $self->ROI
Truth table50%1/2
A
A= 0 - $self->{'costBasis'}
Truth table50%1/2
A
A= $self->{'revenue'}
Truth table50%1/2
A
A= $self->{'realized'}
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 54 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||