Skip to content

Commit 1e9bba0

Browse files
authored
Update financial.js
1 parent 35eac41 commit 1e9bba0

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

adv-math/src/financial/financial.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
class Financial {
22
// Method to calculate the future value of an investment with compound interest
33
static futureValue(principal, rate, time) {
4-
const compoundInterest = principal * Math.pow(1 + rate, time);
5-
return compoundInterest;
4+
return principal * Math.pow(1 + rate, time);
65
}
76

87
// Method to calculate the compound interest earned on an investment
@@ -14,6 +13,72 @@ class Financial {
1413
static presentValue(futureValue, rate, time) {
1514
return futureValue / Math.pow(1 + rate, time);
1615
}
16+
17+
// Method to calculate the loan amortization schedule
18+
static loanAmortization(principal, rate, time) {
19+
const monthlyRate = rate / 12 / 100; // Monthly interest rate
20+
const numPayments = time * 12; // Number of monthly payments
21+
const monthlyPayment = (principal * monthlyRate) / (1 - Math.pow(1 + monthlyRate, -numPayments));
22+
23+
const amortizationSchedule = [];
24+
let remainingBalance = principal;
25+
26+
for (let month = 1; month <= numPayments; month++) {
27+
const interestPayment = remainingBalance * monthlyRate;
28+
const principalPayment = monthlyPayment - interestPayment;
29+
remainingBalance -= principalPayment;
30+
31+
amortizationSchedule.push({
32+
month,
33+
monthlyPayment,
34+
principalPayment,
35+
interestPayment,
36+
remainingBalance,
37+
});
38+
}
39+
40+
return amortizationSchedule;
41+
}
42+
43+
// Method to calculate the effective interest rate
44+
static effectiveInterestRate(principal, futureValue, time) {
45+
return Math.pow(futureValue / principal, 1 / time) - 1;
46+
}
47+
48+
// Method to convert annual interest rates to monthly
49+
static annualToMonthlyInterestRate(annualRate) {
50+
return (Math.pow(1 + annualRate, 1 / 12) - 1) * 100;
51+
}
52+
53+
// Method to calculate the net present value (NPV) of cash flows
54+
static netPresentValue(cashFlows, discountRate) {
55+
let npv = 0;
56+
for (let i = 0; i < cashFlows.length; i++) {
57+
npv += cashFlows[i] / Math.pow(1 + discountRate, i);
58+
}
59+
return npv;
60+
}
61+
62+
// Method to adjust a value for inflation
63+
static adjustForInflation(value, inflationRate, years) {
64+
return value / Math.pow(1 + inflationRate, years);
65+
}
66+
67+
// Method to calculate the periodic payment needed to reach a future value goal
68+
static calculateRequiredPaymentForFutureValue(futureValue, rate, time) {
69+
return futureValue / ((Math.pow(1 + rate, time) - 1) / rate);
70+
}
71+
72+
// Method to calculate asset depreciation
73+
static calculateDepreciation(initialValue, salvageValue, usefulLife) {
74+
return (initialValue - salvageValue) / usefulLife;
75+
}
76+
77+
// Method to calculate the total return on an investment
78+
static totalReturn(initialInvestment, finalValue, additionalInvestments) {
79+
return (finalValue - initialInvestment + additionalInvestments) / initialInvestment;
80+
}
1781
}
1882

1983
module.exports = Financial;
84+

0 commit comments

Comments
 (0)