-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParentSimulator.java
More file actions
89 lines (70 loc) · 2.89 KB
/
Copy pathParentSimulator.java
File metadata and controls
89 lines (70 loc) · 2.89 KB
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
package symposium;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class ParentSimulator {
double stockBalance;
double fixedBalance;
double startAlloc;
double endAlloc;
double allocation;
double annualIncrease;
double fixedYield;
double dividend = 0.02;
YearMonth currentDate;
YearMonth endDate;
StockData stockData;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/yyyy");
List<YearMonth> dates = new ArrayList<>();
List<Double> stockBalances = new ArrayList<>();
List<Double> fixedBalances = new ArrayList<>();
int totalMonths;
int currentMonth = 0;
public ParentSimulator(double startAmount, double startAlloc, double endAlloc,
double fixedYield, double annualIncrease, YearMonth startDate, YearMonth endDate) {
this.startAlloc = startAlloc;
this.endAlloc = endAlloc;
this.stockBalance = startAmount * startAlloc;
this.fixedBalance = startAmount * (1 - startAlloc);
this.allocation = startAlloc; // Initial allocation for the first month
this.annualIncrease = annualIncrease;
this.fixedYield = fixedYield;
this.currentDate = startDate;
this.endDate = endDate;
this.totalMonths = (endDate.getYear() - currentDate.getYear()) * 12 + endDate.getMonthValue() - currentDate.getMonthValue();
this.stockData = new StockData();
}
// Increment month
public void nextMonth() {
currentDate = currentDate.plusMonths(1);
currentMonth++;
}
// Add stock market change
public void applyStockMarket(double percentChange) {
stockBalance *= (1 + percentChange / 100);
}
// Add dividend when current month is March, June, September, or December
public void dividend() {
if (currentDate.getMonthValue() == 3 || currentDate.getMonthValue() == 6 ||
currentDate.getMonthValue() == 9 || currentDate.getMonthValue() == 12) {
stockBalance *= (1 + dividend / 4); // Quarterly dividend
}
}
// Increase fixed income based on interest rate
public void applyFixedIncomeYield() {
fixedBalance *= (1 + (fixedYield / 12 / 100));
}
// Adjust allocation
public void adjustAllocation() {
double progress = (double) currentMonth / totalMonths;
allocation = startAlloc + progress * (endAlloc - startAlloc);
}
// Rebalance fixed income and investments according to current allocation
public void rebalance() {
double total = stockBalance + fixedBalance;
stockBalance = total * allocation;
fixedBalance = total * (1 - allocation);
System.out.println("Rebalanced at " + currentDate.format(formatter));
}
}