1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.nickokiss.investor.calc;
22
23 import java.math.BigDecimal;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class SimpleInterestCalc {
42
43 private MathCalc mathCalc = new MathCalc();
44
45
46
47
48 public BigDecimal getFutureValue(BigDecimal presentValue, BigDecimal interestRate, BigDecimal time) {
49
50 BigDecimal scaledInterestRate = interestRate.multiply(time);
51 BigDecimal growth = scaledInterestRate.add(mathCalc.ONE);
52 BigDecimal futureValue = growth.multiply(presentValue);
53 return futureValue;
54 }
55
56
57
58
59
60
61
62
63
64 public BigDecimal getPresentValue(BigDecimal futureValue, BigDecimal interestRate, BigDecimal time) {
65
66
67 BigDecimal scaledInterestRate = interestRate.multiply(time);
68
69 BigDecimal growth = scaledInterestRate.add(mathCalc.ONE);
70 BigDecimal presentValue = mathCalc.div(futureValue, growth);
71 return presentValue;
72 }
73
74
75
76
77
78
79
80
81
82
83
84 public BigDecimal getInterestRate(BigDecimal presentValue, BigDecimal futureValue, BigDecimal time) {
85
86 BigDecimal growth = mathCalc.div(futureValue, presentValue);
87 BigDecimal scaledInterestRate = growth.subtract(mathCalc.ONE);
88 BigDecimal interestRate = mathCalc.div(scaledInterestRate, time);
89 return interestRate;
90 }
91
92
93
94
95
96
97
98
99
100
101
102 public BigDecimal getTime(BigDecimal presentValue, BigDecimal futureValue, BigDecimal interestRate) {
103
104 BigDecimal growth = mathCalc.div(futureValue, presentValue);
105 BigDecimal scaledInterestRate = growth.subtract(mathCalc.ONE);
106 BigDecimal time = mathCalc.div(scaledInterestRate, interestRate);
107 return time;
108 }
109
110 }