social-security-calculator 1.0.2 → 1.0.3
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/README.md +133 -8
- package/lib/constants.d.ts +4 -3
- package/lib/constants.js +4 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +7 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,139 @@
|
|
|
1
|
-
#
|
|
2
|
-
TypeScript to calculate estimated Social Security Benefits
|
|
1
|
+
# Social Security Benefits Calculator
|
|
3
2
|
|
|
3
|
+
A TypeScript library for calculating Social Security retirement benefits based on official SSA formulas. This calculator handles Average Indexed Monthly Earnings (AIME), Primary Insurance Amount (PIA), and adjustments for early or delayed retirement.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
from Social Security given your annual earnings
|
|
5
|
+
## Credits
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
This project is forked from [Ryan Antkowiak's SocialSecurityCalculator](https://github.com/antkowiak/SocialSecurityCalculator) python implementation. The original implementation has been refactored with COLA adjustments to bring it into alignment with SSA's Quick Calculator.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
Security eligible earnings in that particular year
|
|
9
|
+
## Features
|
|
12
10
|
|
|
11
|
+
- Calculate Average Indexed Monthly Earnings (AIME) based on earnings history
|
|
12
|
+
- Determine Primary Insurance Amount (PIA) using current bend points
|
|
13
|
+
- Apply Cost of Living Adjustments (COLA)
|
|
14
|
+
- Handle early retirement reductions
|
|
15
|
+
- Calculate delayed retirement credits
|
|
16
|
+
- Full TypeScript support with comprehensive type definitions
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install social-security-calculator
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { calc } from 'social-security-calculator';
|
|
30
|
+
|
|
31
|
+
const result = calc(
|
|
32
|
+
new Date(1960, 0, 15), // Birthday: January 15, 1960
|
|
33
|
+
new Date(2027, 0, 15), // Retirement: January 15, 2027
|
|
34
|
+
[
|
|
35
|
+
{ year: 1982, earnings: 12000 },
|
|
36
|
+
{ year: 1983, earnings: 15000 },
|
|
37
|
+
// ... add more years of earnings
|
|
38
|
+
{ year: 2025, earnings: 87000 }
|
|
39
|
+
]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.log(`Monthly benefit: ${result.NormalMonthlyBenefit}`);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Early Retirement Example
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const birthDate = new Date(1965, 5, 1); // June 1, 1965
|
|
49
|
+
const earlyRetirement = new Date(2027, 5, 1); // June 1, 2027 (at age 62)
|
|
50
|
+
|
|
51
|
+
const result = calc(birthDate, earlyRetirement, earnings);
|
|
52
|
+
// Benefits will be reduced for early retirement
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Delayed Retirement Example
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const birthDate = new Date(1955, 2, 15); // March 15, 1955
|
|
59
|
+
const delayedRetirement = new Date(2025, 2, 15); // March 15, 2025 (at age 70)
|
|
60
|
+
|
|
61
|
+
const result = calc(birthDate, delayedRetirement, earnings);
|
|
62
|
+
// Benefits will include delayed retirement credits
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### Main Functions
|
|
68
|
+
|
|
69
|
+
#### `calc(birthday: Date, retirementDate: Date, earnings: Earnings): BenefitCalculationResult`
|
|
70
|
+
|
|
71
|
+
Calculates Social Security retirement benefits.
|
|
72
|
+
|
|
73
|
+
**Parameters:**
|
|
74
|
+
- `birthday`: Date of birth
|
|
75
|
+
- `retirementDate`: Planned retirement date
|
|
76
|
+
- `earnings`: Array of yearly earnings records
|
|
77
|
+
|
|
78
|
+
**Returns:**
|
|
79
|
+
- `BenefitCalculationResult` object containing:
|
|
80
|
+
- `AIME`: Average Indexed Monthly Earnings
|
|
81
|
+
- `NormalMonthlyBenefit`: Monthly benefit amount (in dollars)
|
|
82
|
+
|
|
83
|
+
#### `calculatePIA(AIME: number, baseYear?: number): number`
|
|
84
|
+
|
|
85
|
+
Calculates the Primary Insurance Amount based on AIME.
|
|
86
|
+
|
|
87
|
+
**Parameters:**
|
|
88
|
+
- `AIME`: Average Indexed Monthly Earnings
|
|
89
|
+
- `baseYear`: Optional base year for calculations (defaults to 2023)
|
|
90
|
+
|
|
91
|
+
#### `calculateAIME(earnings: Earnings, baseYear?: number): number`
|
|
92
|
+
|
|
93
|
+
Calculates Average Indexed Monthly Earnings from earnings history.
|
|
94
|
+
|
|
95
|
+
**Parameters:**
|
|
96
|
+
- `earnings`: Array of yearly earnings
|
|
97
|
+
- `baseYear`: Optional base year for wage indexing
|
|
98
|
+
|
|
99
|
+
### Type Definitions
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
interface Wage {
|
|
103
|
+
year: number;
|
|
104
|
+
earnings: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type Earnings = Wage[];
|
|
108
|
+
|
|
109
|
+
interface BenefitCalculationResult {
|
|
110
|
+
AIME: number;
|
|
111
|
+
NormalMonthlyBenefit: number;
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## How It Works
|
|
116
|
+
|
|
117
|
+
1. **AIME Calculation**: The calculator indexes historical earnings to account for wage inflation, selects the highest 35 years of indexed earnings, and computes the monthly average.
|
|
118
|
+
|
|
119
|
+
2. **PIA Calculation**: Applies SSA bend points to determine the Primary Insurance Amount from the AIME.
|
|
120
|
+
|
|
121
|
+
3. **Retirement Age Adjustments**:
|
|
122
|
+
- Early retirement (age 62-66): Benefits are reduced by 5/9 of 1% for each of the first 36 months and 5/12 of 1% for additional months
|
|
123
|
+
- Delayed retirement (age 67-70): Benefits increase by 2/3 of 1% per month (8% per year) for those born after 1943
|
|
124
|
+
|
|
125
|
+
4. **COLA Adjustments**: Annual Cost of Living Adjustments are applied starting at age 62.
|
|
126
|
+
|
|
127
|
+
## Important Notes
|
|
128
|
+
|
|
129
|
+
- The calculator uses the most recent wage indexes as published by the SSA as of 2025
|
|
130
|
+
- It is designed and tested to exactly align with the [SSA Quick Calculator](https://www.ssa.gov/OACT/quickcalc/index.html)
|
|
131
|
+
- It always uses current dollar value, and does not predict future inflation amounts
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
Contributions are welcome! Please feel free to submit issues or pull requests.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
This project maintains the same license as the original repository. Please refer to the LICENSE file for details.
|
package/lib/constants.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export declare const PIA_PERCENTAGES: {
|
|
|
10
10
|
readonly SECOND_BRACKET: 0.32;
|
|
11
11
|
readonly THIRD_BRACKET: 0.15;
|
|
12
12
|
};
|
|
13
|
-
export declare const
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
13
|
+
export declare const EARLY_RETIREMENT_REDUCTION: {
|
|
14
|
+
readonly FIRST_MONTHS: 36;
|
|
15
|
+
readonly FIRST_MONTHS_RATE: number;
|
|
16
|
+
readonly ADDITIONAL_MONTHS_RATE: number;
|
|
16
17
|
};
|
package/lib/constants.js
CHANGED
|
@@ -11,7 +11,8 @@ export const PIA_PERCENTAGES = {
|
|
|
11
11
|
SECOND_BRACKET: 0.32,
|
|
12
12
|
THIRD_BRACKET: 0.15
|
|
13
13
|
};
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export const EARLY_RETIREMENT_REDUCTION = {
|
|
15
|
+
FIRST_MONTHS: 36,
|
|
16
|
+
FIRST_MONTHS_RATE: 5 / 9 * 0.01,
|
|
17
|
+
ADDITIONAL_MONTHS_RATE: 5 / 12 * 0.01 // 5/12 of 1%
|
|
17
18
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BenefitCalculationResult, Earnings } from './model';
|
|
2
2
|
export declare function calc(birthday: Date, retirementDate: Date, earnings: Earnings): BenefitCalculationResult;
|
|
3
|
-
export declare function calcRetirementBenefit(birthday: Date,
|
|
3
|
+
export declare function calcRetirementBenefit(birthday: Date, retirementDate: Date, AIME: number): BenefitCalculationResult;
|
|
4
4
|
export declare function calculatePIA(AIME: number, baseYear?: number): number;
|
|
5
5
|
export declare function calculateAIME(earnings: Earnings, baseYear?: number): number;
|
|
6
6
|
export declare function getEnglishCommonLawDate(date: Date): Date;
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { wageIndex } from './wage-index';
|
|
2
|
-
import { EARLY_RETIREMENT_AGE, WAGE_INDEX_CUTOFF, MAX_RETIREMENT_AGE, LOOKBACK_YEARS, BEND_POINT_DIVISOR, FIRST_BEND_POINT_MULTIPLIER, SECOND_BEND_POINT_MULTIPLIER, PIA_PERCENTAGES,
|
|
2
|
+
import { EARLY_RETIREMENT_AGE, WAGE_INDEX_CUTOFF, MAX_RETIREMENT_AGE, LOOKBACK_YEARS, BEND_POINT_DIVISOR, FIRST_BEND_POINT_MULTIPLIER, SECOND_BEND_POINT_MULTIPLIER, PIA_PERCENTAGES, EARLY_RETIREMENT_REDUCTION } from './constants';
|
|
3
3
|
// Main calculation function
|
|
4
4
|
export function calc(birthday, retirementDate, earnings) {
|
|
5
5
|
// Validation
|
|
@@ -12,15 +12,12 @@ export function calc(birthday, retirementDate, earnings) {
|
|
|
12
12
|
if (retirementDate < birthday) {
|
|
13
13
|
throw new Error('Retirement date cannot be before birthday');
|
|
14
14
|
}
|
|
15
|
-
const lastYearEarnings = earnings
|
|
16
|
-
.filter(wage => wage.earnings > 0)
|
|
17
|
-
.reduce((max, wage) => Math.max(max, wage.year), 0);
|
|
18
15
|
const yearAge60 = birthday.getFullYear() + 60;
|
|
19
16
|
const averageIndexedMonthlyEarnings = calculateAIME(earnings, yearAge60);
|
|
20
|
-
const results = calcRetirementBenefit(birthday,
|
|
17
|
+
const results = calcRetirementBenefit(birthday, retirementDate, averageIndexedMonthlyEarnings);
|
|
21
18
|
return results;
|
|
22
19
|
}
|
|
23
|
-
export function calcRetirementBenefit(birthday,
|
|
20
|
+
export function calcRetirementBenefit(birthday, retirementDate, AIME) {
|
|
24
21
|
const dates = calculateRetirementDates(birthday, retirementDate);
|
|
25
22
|
const age60Year = dates.eclBirthDate.getFullYear() + 60;
|
|
26
23
|
const primaryInsuranceAmount = calculatePIA(AIME, age60Year);
|
|
@@ -130,13 +127,13 @@ function calculateEarlyRetirementReduction(amount, months) {
|
|
|
130
127
|
if (months <= 0)
|
|
131
128
|
return amount;
|
|
132
129
|
let reduction;
|
|
133
|
-
if (months <=
|
|
134
|
-
reduction = months *
|
|
130
|
+
if (months <= EARLY_RETIREMENT_REDUCTION.FIRST_MONTHS) {
|
|
131
|
+
reduction = months * EARLY_RETIREMENT_REDUCTION.FIRST_MONTHS_RATE;
|
|
135
132
|
}
|
|
136
133
|
else {
|
|
137
134
|
reduction =
|
|
138
|
-
|
|
139
|
-
(months -
|
|
135
|
+
EARLY_RETIREMENT_REDUCTION.FIRST_MONTHS * EARLY_RETIREMENT_REDUCTION.FIRST_MONTHS_RATE +
|
|
136
|
+
(months - EARLY_RETIREMENT_REDUCTION.FIRST_MONTHS) * EARLY_RETIREMENT_REDUCTION.ADDITIONAL_MONTHS_RATE;
|
|
140
137
|
}
|
|
141
138
|
return amount * (1 - reduction);
|
|
142
139
|
}
|