Understanding interest with d3js

08 Dec 2015

There was a discussion at Gravitate about an investor wanting to calculate the Institutional Rate of Return of a startup.

Whether you are a startup wanting to know how long it will take an investor to break even, or a prospective home buyer wondering how long it would take to pay off a mortgage, the calculation is the same.

Scroll down to the bottom of the page to see the interactive chart.

We used some Haskell and d3js to visualize how long it takes to pay off a $200,000 investment at around 3.5% annual interest. Take particular notice of the left side of the curve. Hustling to get an early cashflow, or making double payments on your mortgage early on really helps.

Happy holidays from DataCulture!

monthsToZero :: Float -> Float -> Float  -> Int
monthsToZero principal rateMonthly payMonthly | principal <= 0  = 0
                                              | principal > 0 =  1 + monthsToZero ((principal - payMonthly)+ (principal - payMonthly)*rateMonthly) rateMonthly payMonthly

monthsOnSTDMortgage :: Float -> Int
monthsOnSTDMortgage payMonthly = (monthsToZero 200000 0.002871 payMonthly)

payments = take 9101 $ iterate (+1) (900 :: Float)

paybacks = map monthsOnSTDMortgage payments

pairs = zip payments paybacks

pairToCSV (a,b) = show a ++ "," ++ show b ++ "\n" 

csv = unlines $ map pairToCSV pairs

main = do
	    putStrLn "Payment,PaybackPeriod"
	    putStrLn csv