Similar to my previous article, here are some formulas that can help you estimate how much you need to save for your kid's college tuition or what your monthly mortgage payment will look like if you buy that house.

Loans

class Loan {
    payments(PV, IR, NP){
        var PMT = (PV * IR) / (1 - Math.pow(1 + IR, -NP))
            // Make the Payments Monthly
            PMT = PMT / 12
        return PMT
    }

    balance(PMT, IR, NP){
        var PV = PMT * (1 - Math.pow(1 + IR, -NP)) / IR;
        return PV;
    }
}

// Convert floating numbers to currency.
class Format {
    static get formatter(){
        return new Intl.NumberFormat('en-US', { 
            style: "currency",  
            currency: "USD",
            minimumFractionDigits: 2
        })
    }
    static toCash(number){
        let f = this.formatter;
        return f.format(number);
    }
}

// Mo payments on a 30 year loan with an APR of 0.0385
const loan = new Loan();
var mortgage = { amount: 380000, rate: 0.0385, years: 30 }
var monthlyPayment = loan.payments(mortgage.amount, mortgage.rate, mortgage.years);
console.log("Mortgage Payment: ", Format.toCash(monthlyPayment));

College Savings

How much I will need to save yearly to send my kid to USC?

class Savings {
    college(FV, IR, NP=18){
        var PMT = FV * IR / (Math.pow(1 + IR, NP) - 1);
        return PMT;
    }
}

// Convert floating numbers to currency.
class Format {
    static get formatter(){
        return new Intl.NumberFormat('en-US', { 
            style: "currency",  
            currency: "USD",
            minimumFractionDigits: 2
        })
    }
    static toCash(number){
        let f = this.formatter;
        return f.format(number);
    }
}

const savings = new Savings();
var USC = { cost: { today: 583213 } };
var investment = { rate: 0.08 , periods: 18 };
var monthlySavings = savings.college(USC.cost.today, investment.rate, investment.periods );
console.log("Yearly College Savings Deposit: ", Format.toCash(monthlySavings));

Resources