social-security-calculator 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +15 -0
- package/index.js +49 -0
- package/package.json +4 -4
- package/wage-index.js +122 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export = calc;
|
|
2
|
+
declare function calc(earnings: any): {
|
|
3
|
+
Top35YearsEarnings: any;
|
|
4
|
+
AIME: string;
|
|
5
|
+
FirstBendPoint: string;
|
|
6
|
+
SecondBendPoint: string;
|
|
7
|
+
NormalMonthlyBenefit: string;
|
|
8
|
+
NormalAnnualBenefit: string;
|
|
9
|
+
ReducedMonthlyBenefit: string;
|
|
10
|
+
ReducedAnnualBenefit: string;
|
|
11
|
+
};
|
|
12
|
+
declare namespace calc {
|
|
13
|
+
export { __esModule };
|
|
14
|
+
}
|
|
15
|
+
declare const __esModule: boolean;
|
package/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const wage_index_1 = require("./wage-index");
|
|
4
|
+
function calc(earnings) {
|
|
5
|
+
const lookbackYears = 35;
|
|
6
|
+
const futureYearsFactor = 1;
|
|
7
|
+
const bendPointDivisor = 9779.44;
|
|
8
|
+
const firstBendPointMultiplier = 180.0;
|
|
9
|
+
const secondBendPointMultiplier = 1085.0;
|
|
10
|
+
const averageWageLastYear = Math.max(...Object.keys(wage_index_1.wageIndex).map(val => parseInt(val)));
|
|
11
|
+
const firstBendPoint = Math.round(firstBendPointMultiplier * wage_index_1.wageIndex[averageWageLastYear] / bendPointDivisor);
|
|
12
|
+
const secondBendPoint = Math.round(secondBendPointMultiplier * wage_index_1.wageIndex[averageWageLastYear] / bendPointDivisor);
|
|
13
|
+
const wageIndexFactors = Object.entries(wage_index_1.wageIndex).reduce((acc, [i, val]) => ((acc[i] = 1 + (wage_index_1.wageIndex[averageWageLastYear] - val) / val) && acc), {});
|
|
14
|
+
const adjustedEarnings = Object.entries(earnings).reduce((acc, [i, val]) => ((acc[i] = val * (wageIndexFactors[i] || futureYearsFactor)) && acc), {});
|
|
15
|
+
const top35YearsEarnings = Object.values(adjustedEarnings)
|
|
16
|
+
.sort((a, b) => b - a) // sort the earnings from highest to lowest amount
|
|
17
|
+
.slice(0, lookbackYears) // grab the highest 35 earnings years
|
|
18
|
+
.reduce((partialSum, a) => partialSum + a, 0); // and finally sum them
|
|
19
|
+
const AIME = top35YearsEarnings / (12 * lookbackYears);
|
|
20
|
+
const normalMonthlyBenefit = (() => {
|
|
21
|
+
let monthlyBenefit = 0;
|
|
22
|
+
if (AIME <= firstBendPoint) {
|
|
23
|
+
monthlyBenefit = 0.9 * AIME;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (AIME > firstBendPoint && AIME <= secondBendPoint) {
|
|
27
|
+
monthlyBenefit = 0.9 * firstBendPoint + 0.32 * (AIME - firstBendPoint);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
monthlyBenefit = 0.9 * firstBendPoint + 0.32 * (secondBendPoint - firstBendPoint) + 0.15 * (AIME - secondBendPoint);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Math.floor(monthlyBenefit * 10.0) / 10.0;
|
|
34
|
+
;
|
|
35
|
+
})();
|
|
36
|
+
const reducedMonthlyBenefit = Math.floor(((0.7 * normalMonthlyBenefit) * 10) / 10);
|
|
37
|
+
const results = {
|
|
38
|
+
"Top35YearsEarnings": top35YearsEarnings.toFixed(2),
|
|
39
|
+
"AIME": AIME.toFixed(2),
|
|
40
|
+
"FirstBendPoint": firstBendPoint.toFixed(2),
|
|
41
|
+
"SecondBendPoint": secondBendPoint.toFixed(2),
|
|
42
|
+
"NormalMonthlyBenefit": normalMonthlyBenefit.toFixed(2),
|
|
43
|
+
"NormalAnnualBenefit": (normalMonthlyBenefit * 12).toFixed(2),
|
|
44
|
+
"ReducedMonthlyBenefit": reducedMonthlyBenefit.toFixed(2),
|
|
45
|
+
"ReducedAnnualBenefit": (reducedMonthlyBenefit * 12).toFixed(2),
|
|
46
|
+
};
|
|
47
|
+
return results;
|
|
48
|
+
}
|
|
49
|
+
module.exports = calc;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "social-security-calculator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Calculate estimated Social Security Benefits",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
8
|
+
"**/*"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
package/wage-index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wageIndex = void 0;
|
|
4
|
+
const compound = require('compound-calc');
|
|
5
|
+
exports.wageIndex = {
|
|
6
|
+
1951: 2799.16,
|
|
7
|
+
1952: 2973.32,
|
|
8
|
+
1953: 3139.44,
|
|
9
|
+
1954: 3155.64,
|
|
10
|
+
1955: 3301.44,
|
|
11
|
+
1956: 3532.36,
|
|
12
|
+
1957: 3641.72,
|
|
13
|
+
1958: 3673.8,
|
|
14
|
+
1959: 3855.8,
|
|
15
|
+
1960: 4007.12,
|
|
16
|
+
1961: 4086.76,
|
|
17
|
+
1962: 4291.4,
|
|
18
|
+
1963: 4396.64,
|
|
19
|
+
1964: 4576.32,
|
|
20
|
+
1965: 4658.72,
|
|
21
|
+
1966: 4938.36,
|
|
22
|
+
1967: 5213.44,
|
|
23
|
+
1968: 5571.76,
|
|
24
|
+
1969: 5893.76,
|
|
25
|
+
1970: 6186.24,
|
|
26
|
+
1971: 6497.08,
|
|
27
|
+
1972: 7133.8,
|
|
28
|
+
1973: 7580.16,
|
|
29
|
+
1974: 8030.76,
|
|
30
|
+
1975: 8630.92,
|
|
31
|
+
1976: 9226.48,
|
|
32
|
+
1977: 9779.44,
|
|
33
|
+
1978: 10556.03,
|
|
34
|
+
1979: 11479.46,
|
|
35
|
+
1980: 12513.46,
|
|
36
|
+
1981: 13773.1,
|
|
37
|
+
1982: 14531.34,
|
|
38
|
+
1983: 15239.24,
|
|
39
|
+
1984: 16135.07,
|
|
40
|
+
1985: 16822.51,
|
|
41
|
+
1986: 17321.82,
|
|
42
|
+
1987: 18426.51,
|
|
43
|
+
1988: 19334.04,
|
|
44
|
+
1989: 20099.55,
|
|
45
|
+
1990: 21027.98,
|
|
46
|
+
1991: 21811.6,
|
|
47
|
+
1992: 22935.42,
|
|
48
|
+
1993: 23132.67,
|
|
49
|
+
1994: 23753.53,
|
|
50
|
+
1995: 24705.66,
|
|
51
|
+
1996: 25913.9,
|
|
52
|
+
1997: 27426.0,
|
|
53
|
+
1998: 28861.44,
|
|
54
|
+
1999: 30469.84,
|
|
55
|
+
2000: 32154.82,
|
|
56
|
+
2001: 32921.92,
|
|
57
|
+
2002: 33252.09,
|
|
58
|
+
2003: 34064.95,
|
|
59
|
+
2004: 35648.55,
|
|
60
|
+
2005: 36952.94,
|
|
61
|
+
2006: 38651.41,
|
|
62
|
+
2007: 40405.48,
|
|
63
|
+
2008: 41334.97,
|
|
64
|
+
2009: 40711.61,
|
|
65
|
+
2010: 41673.83,
|
|
66
|
+
2011: 42979.61,
|
|
67
|
+
2012: 44321.67,
|
|
68
|
+
2013: 44888.16,
|
|
69
|
+
2014: 46481.52,
|
|
70
|
+
2015: 48098.63,
|
|
71
|
+
2016: 48642.15,
|
|
72
|
+
2017: 50321.89,
|
|
73
|
+
2018: 52145.8,
|
|
74
|
+
2019: 54099.99,
|
|
75
|
+
2020: 55628.6,
|
|
76
|
+
};
|
|
77
|
+
const shortRangeIntermediate = {
|
|
78
|
+
2021: 58743.07,
|
|
79
|
+
2022: 62583.15,
|
|
80
|
+
2023: 65571.72,
|
|
81
|
+
2024: 68371.79,
|
|
82
|
+
2025: 71147.65,
|
|
83
|
+
2026: 73980.60,
|
|
84
|
+
2027: 76857.74,
|
|
85
|
+
2028: 79761.29,
|
|
86
|
+
2029: 82702.63,
|
|
87
|
+
2030: 85713.03,
|
|
88
|
+
2031: 88836.46,
|
|
89
|
+
};
|
|
90
|
+
const longRangeIntermediate = {
|
|
91
|
+
2035: 102530.83,
|
|
92
|
+
2040: 122417.01,
|
|
93
|
+
2045: 145582.26,
|
|
94
|
+
2050: 172887.64,
|
|
95
|
+
2055: 205634.94,
|
|
96
|
+
2060: 244870.78,
|
|
97
|
+
2065: 291767.28,
|
|
98
|
+
2070: 347552.77,
|
|
99
|
+
2075: 413851.91,
|
|
100
|
+
2080: 492391.60,
|
|
101
|
+
2085: 585488.00,
|
|
102
|
+
2090: 696610.41,
|
|
103
|
+
2095: 829710.10,
|
|
104
|
+
2100: 988243.75,
|
|
105
|
+
};
|
|
106
|
+
const fillBlanks = (vals) => Object.entries(vals).reduce((acc, [year, P], index, arr) => {
|
|
107
|
+
let thing;
|
|
108
|
+
if (arr[index + 1]) {
|
|
109
|
+
const [nextYear, A] = arr[index + 1];
|
|
110
|
+
const t = parseInt(nextYear) - parseInt(year);
|
|
111
|
+
const r = Math.pow((A / P), (1 / t)) - 1;
|
|
112
|
+
const vals = compound(P, 0, t, r).result.slice(0, -1);
|
|
113
|
+
const ret = vals.reduce((accx, cur, i) => ((accx[(parseInt(year) + i).toString()] = cur) && accx), {});
|
|
114
|
+
thing = Object.assign(Object.assign({}, acc), ret);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
thing = Object.assign(Object.assign({}, acc), { [year]: P });
|
|
118
|
+
}
|
|
119
|
+
return thing;
|
|
120
|
+
}, {});
|
|
121
|
+
// console.log(fillBlanks(longRangeIntermediate));
|
|
122
|
+
console.log(fillBlanks({ 2000: 38915, 2021: 108494 }));
|