Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Periods to retirement
  2. // rate: interest rate per period on savings
  3. // payment: amount invested per period
  4. // target: desired dividend per period
  5. // returns: minimum periods until period return on savings is greater than target
  6. function PTR(rate, payment, target, period) {
  7.   var periods = 0;
  8.   var savings = 0;
  9.  
  10.   if(!period) {
  11.     period = 1;
  12.   }
  13.  
  14.   while(savings * rate < target) {
  15.     periods += period;
  16.     savings += rate * savings + payment;
  17.   }
  18.   return periods;
  19. }
  20.  
  21. // Savings at retirement
  22. // rate: interest rate per period on savings
  23. // payment: amount invested per period
  24. // target: desired dividend per period
  25. // returns: minimum savings for dividend to be greater than target
  26. function SAR(rate, payment, target) {
  27.   var savings = 0;
  28.   while(savings * rate < target) {
  29.     savings += rate * savings + payment;
  30.   }
  31.   return savings;
  32. }
  33.  
  34. // Periods to accrue
  35. // rate: interest rate per period on savings
  36. // payment: amount invested per period
  37. // target: desired dividend per period
  38. // returns: minimum number of periods before target return per period is met
  39. function PTA(rate, payment, target) {
  40.   var periods = 0;
  41.   var savings = 0;
  42.   while(savings < target) {
  43.     periods++;
  44.     savings += rate * savings + payment;
  45.   }
  46.   return periods;
  47. }
  48.  
  49. // Federal tax
  50. // gross: gross income
  51. // status: "single"/"married"/"separate"
  52. // allowances: number of allowances you have
  53. function FT(gross, status, allowances) {
  54.   var tax_rates = {
  55.     "single" : [[0, 9225, .1], [9225, 37450, .15], [37450, 90750, .25], [90750, 189300, .28], [189300, 411500, .33]],
  56.     "married" : [[0, 18450, .1], [18450, 74900, .15], [74900, 151200, .25], [151200, 230450, .28], [230450, 441500, .33]],
  57.     "separate" : [[0, 9225, .1], [9225, 37450, .15], [37450, 75600, .25], [75600, 115225, .28], [115225, 205750, .33]]
  58.   }[status];
  59.  
  60.   gross = gross - allowances * 4050 - tax_rates[0][1];
  61.  
  62.   var total_tax = 0;
  63.   for(i in tax_rates) {
  64.     if(gross > tax_rates[i][0]) {
  65.       if(gross <= tax_rates[i][1]) {
  66.         total_tax += tax_rates[i][2] * (gross - tax_rates[i][0]);
  67.       } else {
  68.         total_tax += tax_rates[i][2] * (tax_rates[i][1] - tax_rates[i][0]);
  69.       }
  70.     } else {
  71.       break;
  72.     }
  73.   }
  74.  
  75.   return total_tax ;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement