以 Node.js 寫一個簡單腳本,模擬每月繳納 1,800 元社保費(年化 18,000),連繳 15 年後停繳,資金以年化 4.16%(約 1.16%/月,模擬餘額寶收益)複利滾存至 65 歲,比較「繳社保」與「自行投資」的終值差異。
function fuckShebao(req, res, next) {
var day = 1800 / 30; // 日繳費(近似)
var full_days = 365 * 15; // 繳費總天數
var old_days = 365 * 35; // 到退休總天數
var i = 0, p = 0, total = 0;
// 繳費期:每天加入日繳費並計算複利
while (i < full_days) {
total += day;
total += total * 1.16 / 10000; // 日複利
i++;
}
var year15 = total; // 15 年後累積
// 停繳後繼續複利增長
while (p < (old_days - full_days)) {
total += total * 1.16 / 10000;
p++;
}
var all = (total + "").toMoney(); // 需自行定義 toMoney() 格式化
year15 = (year15 + "").toMoney();
res.json({ all: all, year15: year15 });
}
/* 模擬結果:
{ "all": "1070226.48", "year15": "458919.44" }
*/