1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FinanCalc\Calculators { |
4
|
|
|
|
5
|
|
|
use FinanCalc\Interfaces\Calculator\CalculatorAbstract; |
6
|
|
|
use FinanCalc\Utils\Lambdas; |
7
|
|
|
use FinanCalc\Utils\MathFuncs; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class StockInvestmentRatiosCalculator |
11
|
|
|
* @package FinanCalc\Calculators |
12
|
|
|
*/ |
13
|
|
|
class StockInvestmentRatiosCalculator extends CalculatorAbstract |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
// sum of dividends per a period |
17
|
|
|
protected $totalDividends; |
18
|
|
|
// amount earned after taxes |
19
|
|
|
protected $earningsAfterTaxes; |
20
|
|
|
// number of stocks (total if constant, average if fluctuating) |
21
|
|
|
protected $noOfStocks; |
22
|
|
|
|
23
|
|
|
// props returned by the getResultAsArray method by default |
24
|
|
|
protected $propResultArray = [ |
25
|
|
|
"totalDividends", |
26
|
|
|
"earningsAfterTaxes", |
27
|
|
|
"noOfStocks", |
28
|
|
|
"dividendPerStock", |
29
|
|
|
"earningsPerStock", |
30
|
|
|
"payoutRatio", |
31
|
|
|
"dividendRatio", |
32
|
|
|
"retentionRatio" |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param $totalDividends |
37
|
|
|
* @param $earningsAfterTaxes |
38
|
|
|
* @param $noOfStocks |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
$totalDividends, |
42
|
|
|
$earningsAfterTaxes, |
43
|
|
|
$noOfStocks |
44
|
|
|
) { |
45
|
|
|
$this->setTotalDividends($totalDividends); |
46
|
|
|
$this->setEarningsAfterTaxes($earningsAfterTaxes); |
47
|
|
|
$this->setNoOfStocks($noOfStocks); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $totalDividends |
52
|
|
|
*/ |
53
|
|
|
public function setTotalDividends($totalDividends) |
54
|
|
|
{ |
55
|
|
|
$this->setProperty("totalDividends", $totalDividends, Lambdas::checkIfPositive()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param $earningsAfterTaxes |
60
|
|
|
*/ |
61
|
|
|
public function setEarningsAfterTaxes($earningsAfterTaxes) |
62
|
|
|
{ |
63
|
|
|
$this->setProperty("earningsAfterTaxes", $earningsAfterTaxes, Lambdas::checkIfPositive()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $noOfStocks |
68
|
|
|
*/ |
69
|
|
|
public function setNoOfStocks($noOfStocks) |
70
|
|
|
{ |
71
|
|
|
$this->setProperty("noOfStocks", $noOfStocks, Lambdas::checkIfPositive()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
public function getTotalDividends() |
78
|
|
|
{ |
79
|
|
|
return $this->totalDividends; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return mixed |
84
|
|
|
*/ |
85
|
|
|
public function getEarningsAfterTaxes() |
86
|
|
|
{ |
87
|
|
|
return $this->earningsAfterTaxes; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function getNoOfStocks() |
94
|
|
|
{ |
95
|
|
|
return $this->noOfStocks; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getDividendPerStock() |
102
|
|
|
{ |
103
|
|
|
return MathFuncs::div( |
104
|
|
|
$this->totalDividends, |
105
|
|
|
$this->noOfStocks |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getEarningsPerStock() |
113
|
|
|
{ |
114
|
|
|
return MathFuncs::div( |
115
|
|
|
$this->earningsAfterTaxes, |
116
|
|
|
$this->noOfStocks |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getPayoutRatio() |
124
|
|
|
{ |
125
|
|
|
return MathFuncs::div( |
126
|
|
|
$this->getDividendPerStock(), |
127
|
|
|
$this->getEarningsPerStock() |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getDividendRatio() |
135
|
|
|
{ |
136
|
|
|
return MathFuncs::div( |
137
|
|
|
$this->getEarningsPerStock(), |
138
|
|
|
$this->getDividendPerStock() |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getRetentionRatio() |
146
|
|
|
{ |
147
|
|
|
return MathFuncs::sub( |
148
|
|
|
1, |
149
|
|
|
$this->getPayoutRatio() |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|