|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Investform module for webcms2. |
|
5
|
|
|
* Copyright (c) @see LICENSE |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace WebCMS\InvestformModule\Common; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
*/ |
|
13
|
|
|
class FutureValueOfAnnuityCalculator |
|
14
|
|
|
{ |
|
15
|
|
|
private $amount; |
|
16
|
|
|
|
|
17
|
|
|
private $length; |
|
18
|
|
|
|
|
19
|
|
|
private $rates; |
|
20
|
|
|
|
|
21
|
|
|
private $rate; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct($amount, $length) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->amount = $amount; |
|
26
|
|
|
$this->length = $length; |
|
27
|
|
|
|
|
28
|
|
|
$this->rates = array( |
|
29
|
|
|
3 => new Rate(3, 0.07, 1.02), |
|
30
|
|
|
5 => new Rate(5, 0.07, 1.03) |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
if ($this->length > 3) { |
|
34
|
|
|
$this->rate = $this->rates[5]; |
|
35
|
|
|
} else { |
|
36
|
|
|
$this->rate = $this->rates[3]; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getProfit($length = null) |
|
41
|
|
|
{ |
|
42
|
|
|
if (!$length) { |
|
43
|
|
|
$length = $this->length; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$rate = 1 + $this->rate->getRate(); |
|
47
|
|
|
return $this->amount * pow($rate, $length) - $this->amount; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getProfitsByYear() |
|
51
|
|
|
{ |
|
52
|
|
|
$profits = array(); |
|
53
|
|
|
for ($i=1; $i < $this->length; $i++) { |
|
54
|
|
|
$profits[$i] = $this->getProfit($i) - $this->getProfit($i) * 0.15; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $profits; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getTotalProfit() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->amount + $this->getNetIncome(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getNetIncome() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getProfit() - $this->getProfitVat(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getEffectiveEvaluation() |
|
71
|
|
|
{ |
|
72
|
|
|
if ($this->getPurchaseAmount() > 0) { |
|
73
|
|
|
return (pow(($this->getNetIncome() + $this->getAmount()) / $this->getPurchaseAmount(), 1/$this->length) - 1) * 100; |
|
74
|
|
|
} else { |
|
75
|
|
|
return 0; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getTotalAmount() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->amount + $this->getProfit(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getPurchaseAmount() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->amount + $this->getCharge(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getProfitVat() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->getProfit() * 0.15; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getCharge() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->amount * ($this->rate->getCharge() - 1); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Gets the value of amount. |
|
101
|
|
|
* |
|
102
|
|
|
* @return mixed |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getAmount() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->amount; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Sets the value of amount. |
|
111
|
|
|
* |
|
112
|
|
|
* @param mixed $amount the amount |
|
113
|
|
|
* |
|
114
|
|
|
* @return self |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setAmount($amount) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->amount = $amount; |
|
119
|
|
|
|
|
120
|
|
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Gets the value of length. |
|
125
|
|
|
* |
|
126
|
|
|
* @return mixed |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getLength() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->length; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Sets the value of length. |
|
135
|
|
|
* |
|
136
|
|
|
* @param mixed $length the length |
|
137
|
|
|
* |
|
138
|
|
|
* @return self |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setLength($length) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->length = $length; |
|
143
|
|
|
|
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Gets the value of rates. |
|
149
|
|
|
* |
|
150
|
|
|
* @return mixed |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getRates() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->rates; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Sets the value of rates. |
|
159
|
|
|
* |
|
160
|
|
|
* @param mixed $rates the rates |
|
161
|
|
|
* |
|
162
|
|
|
* @return self |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setRates($rates) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->rates = $rates; |
|
167
|
|
|
|
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Gets the value of rate. |
|
173
|
|
|
* |
|
174
|
|
|
* @return mixed |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getRate() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->rate; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Sets the value of rate. |
|
183
|
|
|
* |
|
184
|
|
|
* @param mixed $rate the rate |
|
185
|
|
|
* |
|
186
|
|
|
* @return self |
|
187
|
|
|
*/ |
|
188
|
|
|
public function setRate($rate) |
|
189
|
|
|
{ |
|
190
|
|
|
$this->rate = $rate; |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|