# Calculating Present and Future Value using ES6

I'm currently enrolled as a USC Marshall EMBA student aiming to graduate in 2020. One of the first classes I'm taking is Finance and this week we're learning about "Present Value", "Net Present Value", "Discount Rate", "Future Value" and a few other money fundamentals. While working through a few practice problems using Microsoft Excel, I started to think about what a few of these concepts would look like if I were to write them in ES6.

Below are a few key concepts written using Node and ES6. They are simple by design so that everyone can quickly grasp the algebraic expressions.

If anyone has any helpful hints or suggestions, please share.

```
// Finance Calculator
class Finance {
//
// Present Value = Tommorrow's Cash / (1 + Rate of Return)
// PMT = the sum after investing over a period of times
// IR = Rate of Return / Interest Rate
// NP = Number of Periods (usually years)
PV(PMT, IR, NP=1){
var PV = PMT * (1 - Math.pow(1 + IR, -NP)) / IR
return PV;
}
//
// Future Value = Todays Cash x (1 + Rate of Return)^ Number of Periods
// PMT = the sum after investing over a period of times
// IR = Rate of Return / Interest Rate
// NP = Number of Periods (usually years)
FV(PMT, IR, NP=1){
var FV = PMT * (Math.pow(1 + IR, NP) )
return FV;
}
}
// 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);
}
}
// B. Create a new Finance Object
const finance = new Finance();
// If I am calculating present value, I need future promise + rate.
var futureCash = 11000
var rate = 0.10
var presentValue = finance.PV(futureCash, rate, 1);
console.log("Present Value: ", Format.toCash(presentValue));
// If I am calculating future value, I need current cash + rate.
var currentCash = 10000;
var futureValue = finance.FV(currentCash, rate)
console.log("Future Value: ", Format.toCash(futureValue));
```

# Why Does This Matter?

Suppose you had `$10,000`

and you wanted to make an investment. Your two options are:

- Invest in a low-cost index fund such as
`Vanguard 500 Index Fund Admiral Class (NASDAQMUTFUND:VFIAX)`

which requires a $10k minimum investment but provides an expected return (after taxes of) 10%. - Invest in your friend who promises to give you $10,800 next year.

## Which investment should you make?

You should invest in the stock market because you will earn $11k instad of $10,800. A $200 difference.

```
const finance = new Finance();
var currentCash = 10000;
var rate = 0.10;
var periods = 1;
// Get the Present Value based on your future cash promise.
var friendPromise = 10800
var friendROI = finance.PV(friendPromise, rate, 1) - currentCash;
// Get the Future Value based on your current cash.
var stockROI = finance.FV(currentCash, rate) - currentCash;
console.log("One year from now, my results will look like this:")
console.log("Friend ROI: ", Format.toCash(friendROI), " | ", "Stock ROI:", Format.toCash(stockROI))
```