Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions adv-math/src/financial/financial.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Financial {
// Method to calculate the future value of an investment with compound interest
static futureValue(principal, rate, time) {
const compoundInterest = principal * Math.pow(1 + rate, time);
return compoundInterest;
return principal * Math.pow(1 + rate, time);
}

// Method to calculate the compound interest earned on an investment
Expand All @@ -14,6 +13,72 @@ class Financial {
static presentValue(futureValue, rate, time) {
return futureValue / Math.pow(1 + rate, time);
}

// Method to calculate the loan amortization schedule
static loanAmortization(principal, rate, time) {
const monthlyRate = rate / 12 / 100; // Monthly interest rate
const numPayments = time * 12; // Number of monthly payments
const monthlyPayment = (principal * monthlyRate) / (1 - Math.pow(1 + monthlyRate, -numPayments));

const amortizationSchedule = [];
let remainingBalance = principal;

for (let month = 1; month <= numPayments; month++) {
const interestPayment = remainingBalance * monthlyRate;
const principalPayment = monthlyPayment - interestPayment;
remainingBalance -= principalPayment;

amortizationSchedule.push({
month,
monthlyPayment,
principalPayment,
interestPayment,
remainingBalance,
});
}

return amortizationSchedule;
}

// Method to calculate the effective interest rate
static effectiveInterestRate(principal, futureValue, time) {
return Math.pow(futureValue / principal, 1 / time) - 1;
}

// Method to convert annual interest rates to monthly
static annualToMonthlyInterestRate(annualRate) {
return (Math.pow(1 + annualRate, 1 / 12) - 1) * 100;
}

// Method to calculate the net present value (NPV) of cash flows
static netPresentValue(cashFlows, discountRate) {
let npv = 0;
for (let i = 0; i < cashFlows.length; i++) {
npv += cashFlows[i] / Math.pow(1 + discountRate, i);
}
return npv;
}

// Method to adjust a value for inflation
static adjustForInflation(value, inflationRate, years) {
return value / Math.pow(1 + inflationRate, years);
}

// Method to calculate the periodic payment needed to reach a future value goal
static calculateRequiredPaymentForFutureValue(futureValue, rate, time) {
return futureValue / ((Math.pow(1 + rate, time) - 1) / rate);
}

// Method to calculate asset depreciation
static calculateDepreciation(initialValue, salvageValue, usefulLife) {
return (initialValue - salvageValue) / usefulLife;
}

// Method to calculate the total return on an investment
static totalReturn(initialInvestment, finalValue, additionalInvestments) {
return (finalValue - initialInvestment + additionalInvestments) / initialInvestment;
}
}

module.exports = Financial;