Last active
May 12, 2021 17:27
-
-
Save theosp/6239287 to your computer and use it in GitHub Desktop.
Pension Calculator
This file contains 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
var _ = require("underscore"); | |
var percent = function (i) { | |
return i / 100; | |
} | |
var pensionSumCalculator = function (params) { | |
var default_params = { | |
current_savings_in_pensions_funds: 0, | |
gross_salary: 7500, | |
employer_provision: 5, // percent | |
worker_provision: 5, // percent | |
severance_pay_provisions: true, // does the employer put to the fund severance pay provisions | |
estimated_yield: 4, // percent | |
yearly_management_fee: 1.25, // percent | |
deposits_fee: 0, // percent | |
age_years: 25, | |
age_months: 2, | |
pension_age: 67 | |
}; | |
p = _.extend({}, default_params, params); | |
var months_until_pension = | |
(p.pension_age * 12) - (p.age_years * 12) - p.age_months; | |
var monthly_provision_percent = | |
percent(p.employer_provision) + | |
percent(p.worker_provision) + | |
percent(p.severance_pay_provisions ? 100 / 12 : 0), | |
monthly_provision = monthly_provision_percent * p.gross_salary, | |
monthly_provision_after_deposits_fee = monthly_provision * (1 - percent(p.deposits_fee)); | |
var pension_sum = p.current_savings_in_pensions_funds; | |
for (var i = 0; i < months_until_pension; i++) { | |
pension_sum *= ( | |
1 + | |
Math.pow(1 + percent(p.estimated_yield), 1/12) - | |
Math.pow(1 + percent(p.yearly_management_fee), 1/12) | |
); | |
pension_sum += monthly_provision_after_deposits_fee; | |
} | |
return parseInt(pension_sum); | |
}; | |
total_fees = function (params) { | |
return pensionSumCalculator(_.extend({}, params, {deposits_fee: 0, yearly_management_fee: 0})) - pensionSumCalculator(params); | |
}; | |
console.log(total_fees()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment