Last active
August 29, 2015 14:02
-
-
Save jpiccari/027e83ca507a06515e41 to your computer and use it in GitHub Desktop.
Created this function to help determine how much to contribute (annually) to my 401(k) to retire a decamillionaire.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculate the annual contributions required to reach a desired future value. | |
* @param {number} P - Current principle value. | |
* @param {number} FV - Desired future value. | |
* @param {number} r - Rate of return. | |
* @param {number} Y - Years of growth. | |
* @returns {number} Annual contribution. | |
*/ | |
function annualContributions(P, FV, r, Y) { | |
var z = 1 + r; | |
return -(P * Math.pow(z, Y) - FV) / ((Math.pow(z, Y + 1) - z) / r); | |
} | |
// To become a millionaire by retirement with 40 years to contribute | |
annualContributions(0, 1e6, 0.12, 40); // 1163.9514133216733 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment