Skip to content

Commit 79cb5c8

Browse files
authored
Merge pull request #39 from GiuseppeDM98/claude/monte-carlo-retirement-01QRmv91gmAWYoofbf7hcy6s
Add bulk dummy data deletion and fix Monte Carlo simulation parameters
2 parents 0b19039 + 228618e commit 79cb5c8

File tree

18 files changed

+2754
-78
lines changed

18 files changed

+2754
-78
lines changed

.env.local.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ NEXT_PUBLIC_REGISTRATION_WHITELIST_ENABLED=false
3131
# Comma-separated list of email addresses allowed to register when whitelist is enabled
3232
# Example: user1@example.com,user2@example.com,admin@example.com
3333
NEXT_PUBLIC_REGISTRATION_WHITELIST=
34+
35+
# Development Features
36+
# Set to 'true' to enable test snapshot generation feature in Settings page
37+
# WARNING: Test snapshots are saved to the same Firebase collection as real data
38+
# You can delete all dummy data using the "Elimina Tutti i Dati Dummy" button in Settings
39+
# or manually from Firebase Console
40+
NEXT_PUBLIC_ENABLE_TEST_SNAPSHOTS=false

README.md

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ Built with Next.js, Firebase, and TypeScript. Designed to replace spreadsheet-ba
8585
- **Years of expenses** coverage tracker
8686
- **Historical evolution** charts of income, expenses, and sustainable withdrawal
8787

88+
### 🎲 **Monte Carlo Retirement Simulations**
89+
- **Probabilistic retirement planning** with thousands of simulations
90+
- **Success rate calculation** to assess plan sustainability
91+
- **Market vs Historical parameters**: Use standard market assumptions or your own historical returns
92+
- **Flexible portfolio selection**: Total net worth, liquid assets only, or custom amount
93+
- **Interactive visualizations**:
94+
- Fan chart showing percentile distributions (10th, 25th, 50th, 75th, 90th)
95+
- Distribution histogram of final portfolio values
96+
- Failure analysis with median and average depletion years
97+
- **Configurable parameters**: Retirement duration, asset allocation, withdrawal rates, inflation
98+
- **Automatic data integration**: Pre-populates with your current portfolio and expense data
99+
88100
### 🏆 **Hall of Fame Rankings**
89101
- **Personal financial records** across all time
90102
- **Best/Worst months** by net worth growth, income, and expenses (Top 20)
@@ -256,6 +268,132 @@ See [SETUP.md](./SETUP.md#registration-control) for details.
256268

257269
---
258270

271+
## 🧪 Development Features
272+
273+
### Test Snapshot Generator
274+
275+
For development and testing purposes, the application includes a **bulk test snapshot generator** that creates realistic historical data to test charts, statistics, and UI components.
276+
277+
#### How to Enable
278+
279+
1. **Set environment variable** in your `.env.local`:
280+
```bash
281+
NEXT_PUBLIC_ENABLE_TEST_SNAPSHOTS=true
282+
```
283+
284+
2. **Navigate to Settings page** in the application
285+
286+
3. **Scroll to "Funzionalità di Sviluppo"** section (only visible when enabled)
287+
288+
4. **Click "Genera Snapshot di Test"** button
289+
290+
#### What It Does
291+
292+
The test data generator creates:
293+
294+
**1. Historical Monthly Snapshots** (going back N months, configurable up to 120)
295+
- Initial net worth: Configurable (default: €50,000)
296+
- Monthly growth rate: Configurable average portfolio growth (default: 0.8% → ~10% annual)
297+
- Asset allocation: 85% liquid / 15% illiquid
298+
- Asset class distribution: 60% equity, 25% bonds, 8% crypto, 5% real estate, 2% cash
299+
- **Realistic asset class returns** with different volatilities:
300+
- **Equity** (60%): ~1.0% monthly (~12% annual), volatility ~5% annual
301+
- **Bonds** (25%): ~0.4% monthly (~5% annual), volatility ~1.5% annual
302+
- **Crypto** (8%): ~1.2% monthly (~15% annual), volatility ~10% annual (high risk)
303+
- **Real Estate** (5%): ~0.6% monthly (~7% annual), volatility ~1% annual
304+
- **Cash** (2%): ~0.2% monthly (~2.4% annual, inflation), minimal volatility
305+
- 10 dummy assets: AAPL, GOOGL, MSFT, TSLA, BTC, ETH, US Treasury, Corporate Bonds, Real Estate Fund, Cash EUR
306+
- Random but realistic price variations using normal distribution (Box-Muller transform)
307+
308+
**Technical Implementation:**
309+
- Each asset class grows **independently** with its own return rate and volatility
310+
- Equity, bonds, crypto, real estate, and cash are tracked separately month-by-month
311+
- Portfolio value is recalculated as sum of all asset classes each month
312+
- This creates realistic correlation and diversification effects
313+
- Asset allocation percentages vary over time based on performance (e.g., if equity outperforms, its percentage increases)
314+
- **Perfect for testing Monte Carlo simulations** with historical data that has proper equity/bonds differentiation
315+
316+
**2. Expenses & Income Data** (optional, enabled by default)
317+
- **Income entries**: 1-2 per month with ±8% variation
318+
- Categories: Stipendio, Freelance, Investimenti, Altro
319+
- **Fixed expenses**: Constant with ±3% variation (35% of total expenses)
320+
- Categories: Affitto, Utenze, Abbonamenti
321+
- **Variable expenses**: 8-15 entries per month with ±40% variation (50% of total expenses)
322+
- Categories: Spesa, Trasporti, Svago, Shopping
323+
- **Debts**: Nearly constant with ±1% variation (15% of total expenses)
324+
- Categories: Mutuo, Prestito Auto
325+
- Realistic date distribution throughout each month
326+
327+
#### Parameters
328+
329+
When you click the button, a modal allows you to configure:
330+
331+
**Patrimonio (Net Worth):**
332+
- **Patrimonio Iniziale** (Initial Net Worth): Starting amount in EUR (default: €50,000)
333+
- **Tasso di Crescita Mensile** (Monthly Growth Rate): Average monthly portfolio growth percentage (default: 0.8% → ~10% annual). Realistic range: 0.5-1.0% for typical portfolios
334+
- **Numero di Mesi** (Number of Months): How many months to generate (1-120, default: 24)
335+
336+
**Spese ed Entrate (optional toggle):**
337+
- **Entrate Mensili Medie** (Average Monthly Income): Mean monthly income in EUR (default: €3,000)
338+
- **Spese Mensili Medie** (Average Monthly Expenses): Mean monthly expenses in EUR (default: €2,500)
339+
340+
#### 🏷️ Dummy Data Identification
341+
342+
All test data generated by this feature is marked with special identifiers for easy management:
343+
344+
- **Snapshots**: Have `isDummy: true` field in the database
345+
- **Expenses**: Have IDs starting with `dummy-` (e.g., `dummy-income-...`, `dummy-fixed-...`)
346+
- **Categories**: Have IDs starting with `dummy-category-` (e.g., `dummy-category-income-stipendio`)
347+
348+
This naming convention allows you to identify and remove all test data at once.
349+
350+
#### ⚠️ Important Warning
351+
352+
**Test data is saved to the same Firebase collections as real data:**
353+
- Snapshots → `monthly-snapshots` collection (with `isDummy: true`)
354+
- Expenses → `expenses` collection (with IDs starting with `dummy-`)
355+
- Categories → `expenseCategories` collection (with IDs starting with `dummy-category-`)
356+
357+
All test data will appear in your charts, statistics, and Hall of Fame alongside real data.
358+
359+
#### 🗑️ Removing Test Data
360+
361+
You have two options to remove test data:
362+
363+
**Option 1: Use the Built-in Delete Button (Recommended)**
364+
1. Navigate to **Settings** page in the application
365+
2. Scroll to **"Funzionalità di Sviluppo"** section
366+
3. Click **"Elimina Tutti i Dati Dummy"** button
367+
4. Review the count of items to be deleted
368+
5. Confirm deletion
369+
370+
This will remove all dummy snapshots, expenses, and categories in one operation.
371+
372+
**Option 2: Manual Firebase Console Deletion**
373+
1. Open [Firebase Console](https://console.firebase.google.com/)
374+
2. Navigate to Firestore Database
375+
3. Select your project
376+
4. Delete test documents from these collections:
377+
- `monthly-snapshots`: Documents with `isDummy: true` field
378+
- `expenses`: Documents with IDs starting with `dummy-`
379+
- `expenseCategories`: Documents with IDs starting with `dummy-category-`
380+
381+
**Recommendation**: Only use this feature in a development/test environment or in a separate Firebase project to avoid mixing test data with real financial data.
382+
383+
#### Use Cases
384+
385+
- **Testing charts** with historical data without waiting months for real snapshots
386+
- **Hall of Fame testing** with realistic income/expense variations to see best/worst months and years
387+
- **FIRE calculator testing** with actual expense data to validate sustainable withdrawal calculations
388+
- **Monte Carlo simulation testing** with realistic equity/bonds returns and volatilities that differ appropriately (equity higher return/volatility, bonds lower)
389+
- **Expense analytics testing** to verify category breakdowns, trends, and monthly comparisons
390+
- **UI development** to see how components handle different data scales and edge cases
391+
- **Performance testing** with large datasets (up to 120 months of data)
392+
- **Demo purposes** to showcase the application's full capabilities
393+
- **Development** of new features requiring historical portfolio and expense data
394+
395+
---
396+
259397
## 🔄 Price Data Providers
260398

261399
This project uses **Yahoo Finance** by default (free, no API key required).
@@ -449,6 +587,7 @@ See the [LICENSE](./LICENSE) file for the full license text.
449587
- ✅ Hall of Fame personal financial rankings
450588
- ✅ Registration control system
451589
- ✅ Cost basis tracking with unrealized gains and tax estimation
590+
- ✅ Monte Carlo retirement simulations
452591

453592
### Future Enhancements (Planned 🔜)
454593
- 🔜 PDF export of portfolio reports
@@ -463,7 +602,6 @@ See the [LICENSE](./LICENSE) file for the full license text.
463602
- 🚀 CSV/Excel import for bulk asset additions
464603
- 🚀 Risk analysis (volatility, max drawdown, correlation)
465604
- 🚀 Backtesting allocation strategies
466-
- 🚀 Monte Carlo retirement simulations
467605
- 🚀 AI-powered rebalancing suggestions
468606
- 🚀 Dividend tracking
469607
- 🚀 Tax reporting (capital gains, dividends)

SETUP.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,16 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
200200
NEXT_PUBLIC_REGISTRATIONS_ENABLED=true
201201
NEXT_PUBLIC_REGISTRATION_WHITELIST_ENABLED=false
202202
NEXT_PUBLIC_REGISTRATION_WHITELIST=
203+
204+
# Development Features (optional - for testing/demo)
205+
NEXT_PUBLIC_ENABLE_TEST_SNAPSHOTS=false
203206
```
204207

205208
**How to get the values:**
206209
- Firebase Client SDK values: From Firebase Console → Project Settings → Your apps
207210
- `FIREBASE_SERVICE_ACCOUNT_KEY`: Paste the entire content of the downloaded JSON file
208211
- `CRON_SECRET`: Generate a random string (e.g., use `openssl rand -hex 32`)
212+
- `NEXT_PUBLIC_ENABLE_TEST_SNAPSHOTS`: Set to `true` to enable dummy data generation in Settings page (for development, testing, or demo purposes). **Warning**: Test data is saved to the same Firebase collections as real data. You can delete all dummy data using the "Elimina Tutti i Dati Dummy" button in Settings. See [README.md](./README.md) for full feature documentation. **Recommended**: Keep `false` in production environments.
209213

210214
**For detailed Firebase Admin SDK configuration on Vercel, see [VERCEL_SETUP.md](./VERCEL_SETUP.md)**
211215

0 commit comments

Comments
 (0)