Skip to content

Commit 488e314

Browse files
Merge pull request #6 from introvertedspud/feature/v1.1.0-enhanced-examples-glidepaths
Release v1.1.0: Enhanced examples, dynamic glidepaths, and comprehens…
2 parents 804b411 + dc4ad33 commit 488e314

File tree

108 files changed

+6781
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+6781
-324
lines changed

.eslintrc.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es2021": true
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
'standard-with-typescript',
8+
'plugin:prettier/recommended',
9+
'plugin:jest/recommended',
10+
],
11+
overrides: [
12+
{
13+
env: {
14+
node: true,
15+
},
16+
files: ['.eslintrc.{js,cjs}'],
17+
parserOptions: {
18+
sourceType: 'script',
19+
},
520
},
6-
"extends": ["standard-with-typescript",
7-
"plugin:prettier/recommended",
8-
"plugin:jest/recommended"
9-
],
10-
"overrides": [
11-
{
12-
"env": {
13-
"node": true
14-
},
15-
"files": [
16-
".eslintrc.{js,cjs}"
17-
],
18-
"parserOptions": {
19-
"sourceType": "script"
20-
}
21-
}
22-
],
23-
"parserOptions": {
24-
"ecmaVersion": "latest",
25-
"sourceType": "module"
26-
},
27-
"plugins": [
28-
// other plugins
29-
"jest"
30-
],
31-
"rules": {
32-
}
33-
}
21+
],
22+
parserOptions: {
23+
ecmaVersion: 'latest',
24+
sourceType: 'module',
25+
},
26+
plugins: [
27+
// other plugins
28+
'jest',
29+
],
30+
ignorePatterns: ['dist/', 'node_modules/', 'examples/', '*.js'],
31+
rules: {
32+
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
33+
},
34+
};

README.md

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ To address these challenges, I started developing the Retirement Calculator pack
2929
- **Contribution Calculation**: Determine monthly contributions needed to reach your desired retirement balance.
3030
- **Withdrawal Estimation**: Understand how much you can safely spend from your retirement savings each year.
3131
- **Inflation Adjustment**: Take into account the impact of inflation on your retirement savings and planning.
32+
- **Dynamic Interest Glidepaths**: Age-aware return calculations with three powerful strategies:
33+
- **Fixed Return Glidepath**: Linear decline from aggressive to conservative returns
34+
- **Allocation-Based Glidepath**: Target-date fund style with equity/bond blending
35+
- **Custom Waypoints**: Flexible strategies with user-defined age/return targets
3236

3337

3438
## Usage
@@ -54,30 +58,114 @@ const contributionsNeeded = getContributionNeededForDesiredBalance(1000,10000,10
5458
const balance = calculator.getCompoundInterestWithAdditionalContributions(1000, contributionsNeeded.contributionNeededPerPeriod, 10, .1, 12, 12);
5559
```
5660

61+
### Dynamic Interest Glidepath Calculations
62+
63+
**NEW**: Age-aware retirement calculations with sophisticated glidepath strategies.
64+
65+
#### Fixed Return Glidepath
66+
Perfect for modeling target-date funds or declining return assumptions:
67+
68+
```typescript
69+
const calculator = new RetirementCalculator();
70+
const result = calculator.getCompoundInterestWithGlidepath(
71+
25000, // Starting balance
72+
1000, // Monthly contribution
73+
25, // Starting age
74+
65, // Retirement age
75+
{
76+
mode: 'fixed-return',
77+
startReturn: 0.10, // 10% returns at age 25
78+
endReturn: 0.055 // 5.5% returns at age 65
79+
}
80+
);
81+
82+
console.log(`Final balance: $${calculator.formatNumberWithCommas(result.finalBalance)}`);
83+
console.log(`Effective annual return: ${(result.effectiveAnnualReturn * 100).toFixed(2)}%`);
84+
```
85+
86+
#### Allocation-Based Glidepath
87+
Model target-date funds with changing equity/bond allocations:
88+
89+
```typescript
90+
const targetDateResult = calculator.getCompoundInterestWithGlidepath(
91+
50000, 1500, 30, 65,
92+
{
93+
mode: 'allocation-based',
94+
startEquityWeight: 0.90, // 90% stocks at 30
95+
endEquityWeight: 0.30, // 30% stocks at 65
96+
equityReturn: 0.12, // 12% stock returns
97+
bondReturn: 0.04 // 4% bond returns
98+
}
99+
);
100+
```
101+
102+
#### Custom Waypoints Glidepath
103+
Create sophisticated strategies with precise control:
104+
105+
```typescript
106+
const customResult = calculator.getCompoundInterestWithGlidepath(
107+
15000, 800, 25, 65,
108+
{
109+
mode: 'custom-waypoints',
110+
valueType: 'equityWeight',
111+
waypoints: [
112+
{ age: 25, value: 1.0 }, // 100% equity at 25
113+
{ age: 35, value: 0.85 }, // 85% equity at 35
114+
{ age: 45, value: 0.70 }, // 70% equity at 45
115+
{ age: 55, value: 0.50 }, // 50% equity at 55
116+
{ age: 65, value: 0.25 } // 25% equity at 65
117+
],
118+
equityReturn: 0.11,
119+
bondReturn: 0.035
120+
}
121+
);
122+
123+
// Rich timeline data for visualization
124+
console.log(`Timeline entries: ${customResult.monthlyTimeline.length}`);
125+
customResult.monthlyTimeline.forEach(entry => {
126+
console.log(`Age ${entry.age.toFixed(1)}: ${(entry.currentAnnualReturn * 100).toFixed(2)}% return`);
127+
});
128+
```
129+
57130
### Example Scenarios
58-
I have made a couple example scenarios that can be found [here](examples). This may give inspiration on how to best use this tool to plan for retirement. There is a lot more to retirement than simply plugging numbers into a compounding interest calculator.
131+
I have created example scenarios that can be found [here](examples). These demonstrate both traditional and dynamic glidepath approaches to retirement planning.
59132

60-
#### Scenario 1
61-
Perhaps you have a starting balance in your retirement account, and want to get to the "prized" goal of $1,000,000. Calculate how well you are doing now, and where you need to be in order to achieve your goal. Also, potentially plan with inflation as this could severely impact your results. To run, use ts-node in your console.
133+
#### Basic Retirement Gap Analysis
134+
Perfect for when you have a specific retirement balance goal (like "$1 million") and want to see if your current savings rate is sufficient. This example shows you how to calculate your "retirement gap" and demonstrates the power of compound interest and why inflation matters for long-term planning.
62135

63-
Running the script will output the following:
136+
```bash
137+
npx ts-node examples/basic-retirement-gap-analysis.ts
138+
```
64139

65-
![Results from scenario 1](images/example1.png)
140+
#### Lifestyle-Based Retirement Planning
141+
Ideal for people who think in terms of "I want to spend $X per year in retirement" rather than accumulating a lump sum. This example works backwards from your desired lifestyle to required savings and shows how the 4% withdrawal rule works in practice.
66142

67-
#### Scenario 2
68-
Perhaps you don't know how much you want to have in retirement. Instead, you would like to be able to spend $80,000 a year in retirement and not run out of money in 30 years based on the 4% rule. You could also see what that would mean if you included inflation and wanted your $80,000 a year to go as far in 25 years as it does now. To run, use ts-node in your console.
143+
```bash
144+
npx ts-node examples/lifestyle-based-retirement-planning.ts
145+
```
146+
147+
#### Advanced Dynamic Investment Strategies ✨ **NEW**
148+
For advanced users who want to model changing investment strategies over time (like target-date funds) and compare sophisticated approaches. This comprehensive example demonstrates all glidepath modes with detailed comparisons and educational insights.
69149

70-
Running the script will output the following:
150+
```bash
151+
npx ts-node examples/advanced-dynamic-investment-strategies.ts
152+
```
71153

72-
![Results from scenario 2](images/example2.png)
154+
This example showcases:
155+
- **Fixed return glidepaths** for declining return assumptions
156+
- **Allocation-based strategies** mimicking target-date funds
157+
- **Custom waypoint strategies** for precise control
158+
- **Performance comparisons** between traditional and dynamic approaches
159+
- **Timeline data usage** for creating charts and visualizations
160+
- **Educational insights** about why different strategies work
73161

74-
More scenarios will be added as I add planned capabilities in the future.
162+
More scenarios will be added as I continue to enhance the calculator's capabilities.
75163

76164
## Planned Enhancements
77-
- **Detailed Periodic Reporting**: Provide a detailed breakdown of investments and interest accrued over each period, ideal for visualization.
78165
- **Fee Management**: Include functionality to account for management fees and their long-term impact.
79-
- **Dynamic Interest Rates**: Adapt to changing interest rates to reflect different stages of financial planning.
80166
- **Loan and Withdrawal Impact**: Assess the effect of loans or withdrawals on your retirement savings.
167+
- **Monte Carlo Simulations**: Probabilistic modeling for market volatility and uncertainty.
168+
- **Tax-Advantaged Account Modeling**: Support for 401(k), IRA, Roth IRA contribution limits and tax implications.
81169

82170
## Upcoming Integration
83171
- **Interactive UI**: Developing an intuitive interface for easy retirement planning.

docs/assets/highlight.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
--dark-hl-7: #B5CEA8;
1818
--light-hl-8: #008000;
1919
--dark-hl-8: #6A9955;
20+
--light-hl-9: #000000FF;
21+
--dark-hl-9: #D4D4D4;
22+
--light-hl-10: #267F99;
23+
--dark-hl-10: #4EC9B0;
2024
--light-code-background: #FFFFFF;
2125
--dark-code-background: #1E1E1E;
2226
}
@@ -31,6 +35,8 @@
3135
--hl-6: var(--light-hl-6);
3236
--hl-7: var(--light-hl-7);
3337
--hl-8: var(--light-hl-8);
38+
--hl-9: var(--light-hl-9);
39+
--hl-10: var(--light-hl-10);
3440
--code-background: var(--light-code-background);
3541
} }
3642

@@ -44,6 +50,8 @@
4450
--hl-6: var(--dark-hl-6);
4551
--hl-7: var(--dark-hl-7);
4652
--hl-8: var(--dark-hl-8);
53+
--hl-9: var(--dark-hl-9);
54+
--hl-10: var(--dark-hl-10);
4755
--code-background: var(--dark-code-background);
4856
} }
4957

@@ -57,6 +65,8 @@
5765
--hl-6: var(--light-hl-6);
5866
--hl-7: var(--light-hl-7);
5967
--hl-8: var(--light-hl-8);
68+
--hl-9: var(--light-hl-9);
69+
--hl-10: var(--light-hl-10);
6070
--code-background: var(--light-code-background);
6171
}
6272

@@ -70,6 +80,8 @@
7080
--hl-6: var(--dark-hl-6);
7181
--hl-7: var(--dark-hl-7);
7282
--hl-8: var(--dark-hl-8);
83+
--hl-9: var(--dark-hl-9);
84+
--hl-10: var(--dark-hl-10);
7385
--code-background: var(--dark-code-background);
7486
}
7587

@@ -82,4 +94,6 @@
8294
.hl-6 { color: var(--hl-6); }
8395
.hl-7 { color: var(--hl-7); }
8496
.hl-8 { color: var(--hl-8); }
97+
.hl-9 { color: var(--hl-9); }
98+
.hl-10 { color: var(--hl-10); }
8599
pre, code { background: var(--code-background); }

docs/assets/navigation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)