moneyfunx 0.0.19 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -5
- package/package.json +1 -1
- package/src/lib/payments.js +18 -17
package/README.md
CHANGED
|
@@ -2,8 +2,3 @@
|
|
|
2
2
|
[](https://circleci.com/gh/Kylep342/moneyfunx/tree/main)
|
|
3
3
|
|
|
4
4
|
MoneyFunx is a small library of functions for financial computations, with a focus on personal finance
|
|
5
|
-
|
|
6
|
-
## TODO
|
|
7
|
-
- Fix interest calculation/accrual for the `lifetimeInterest` attribute from the `payLoans` function
|
|
8
|
-
- Add tests
|
|
9
|
-
- Figure out how imports/exports work in JavaScript
|
package/package.json
CHANGED
package/src/lib/payments.js
CHANGED
|
@@ -22,6 +22,11 @@ export function amortizePayments (loan, payment, numPayments, startPeriod) {
|
|
|
22
22
|
period<numPayments;
|
|
23
23
|
period++
|
|
24
24
|
) {
|
|
25
|
+
let principalRemaining = loan.principalRemaining(
|
|
26
|
+
period + 1,
|
|
27
|
+
payment,
|
|
28
|
+
loan.principalRemaining(startPeriod)
|
|
29
|
+
);
|
|
25
30
|
let interestThisPeriod = loan.accrueInterest(
|
|
26
31
|
loan.principalRemaining(
|
|
27
32
|
period,
|
|
@@ -42,11 +47,7 @@ export function amortizePayments (loan, payment, numPayments, startPeriod) {
|
|
|
42
47
|
period: startPeriod + period + 1,
|
|
43
48
|
principal: principalThisPeriod,
|
|
44
49
|
interest: interestThisPeriod,
|
|
45
|
-
principalRemaining:
|
|
46
|
-
period + 1,
|
|
47
|
-
payment,
|
|
48
|
-
loan.principalRemaining(startPeriod)
|
|
49
|
-
)
|
|
50
|
+
principalRemaining: principalRemaining,
|
|
50
51
|
}
|
|
51
52
|
);
|
|
52
53
|
}
|
|
@@ -54,10 +55,10 @@ export function amortizePayments (loan, payment, numPayments, startPeriod) {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export function payLoans (loans, payment) {
|
|
57
|
-
let
|
|
58
|
+
let paymentData = {};
|
|
58
59
|
loans.map(
|
|
59
60
|
(loan) => {
|
|
60
|
-
|
|
61
|
+
paymentData[loan.id] = {lifetimeInterest: 0, amortizationSchedule: []};
|
|
61
62
|
}
|
|
62
63
|
);
|
|
63
64
|
|
|
@@ -82,27 +83,27 @@ export function payLoans (loans, payment) {
|
|
|
82
83
|
firstLoanPayment,
|
|
83
84
|
firstLoan.principalRemaining(periodsElapsed)
|
|
84
85
|
);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
...
|
|
86
|
+
paymentData[firstLoan.id].lifetimeInterest += firstLoanInterestPaid;
|
|
87
|
+
paymentData[firstLoan.id].amortizationSchedule = [
|
|
88
|
+
...paymentData[firstLoan.id].amortizationSchedule,
|
|
88
89
|
...amortizePayments(firstLoan, firstLoanPayment, periodsToPay, periodsElapsed)
|
|
89
90
|
];
|
|
90
91
|
paidLoans += 1;
|
|
91
|
-
totalInterest +=
|
|
92
|
+
totalInterest += paymentData[firstLoan.id].lifetimeInterest;
|
|
92
93
|
loans.slice(paidLoans).map((loan) => {
|
|
93
|
-
|
|
94
|
+
paymentData[loan.id].lifetimeInterest += loan.interestPaid(
|
|
94
95
|
periodsToPay,
|
|
95
96
|
loan.minPayment,
|
|
96
97
|
loan.principalRemaining(periodsElapsed)
|
|
97
98
|
);
|
|
98
|
-
|
|
99
|
-
...
|
|
99
|
+
paymentData[loan.id].amortizationSchedule = [
|
|
100
|
+
...paymentData[loan.id].amortizationSchedule,
|
|
100
101
|
...amortizePayments(loan, loan.minPayment, periodsToPay, periodsElapsed)
|
|
101
102
|
];
|
|
102
103
|
});
|
|
103
104
|
periodsElapsed += periodsToPay;
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
106
|
+
paymentData["totalInterest"] = totalInterest;
|
|
107
|
+
paymentData["totalPayments"] = periodsElapsed;
|
|
108
|
+
return paymentData;
|
|
108
109
|
}
|