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