見出し画像

FIRE試算用エクセル2024.11

■条件など
・AIに相談しながら作った
・投信成長率年10%、インフレ率年3%想定
・FIRE開始直後に回復まで72ヶ月の暴落が発生してもいい現金を確保
・FIRE前のリバランス後、月初生活費取崩し→月次利回り分上昇(年10%換算)→月次インフレ調整後生活費(年3%換算)取崩しの繰り返しを想定
・各%の小数点以下3桁を安全側に調整
・譲渡益課税がかかる割合についてはスタート時の元本割合を反映
・60年後に枯渇しなければ成功

■各式
=D2 * (B2 / E2)
=E2 - ((C2 - F2) / (1 - J2 * (1 - (2040 / E2))))
=ROUNDDOWN(SUMPRODUCT(G2*POWER(1 + (1 + 3%)^(1/12) - 1, ROW(INDIRECT("1:72"))-1)),0)+1
=ROUNDDOWN((1 + 3%)^(1/12) - 1,5)+0.00001
=ROUNDDOWN((1 + 10%)^(1/12) - 1,5)-0.00001
=0.20135+0.00001

■JavaScript
エクセルの計算式だけのやり方は分からなかったため使用

function calculateLongTermWithdrawals720Months() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  // 各セルからパラメータを取得
  const inflationRate = sheet.getRange("H2").getValue(); // 月次インフレ率
  const monthlyGrowthRate = sheet.getRange("I2").getValue(); // 投資信託の月次成長率
  const taxRate = sheet.getRange("J2").getValue(); // 譲渡益課税率

  // 設定項目
  const months = 720; // 720ヶ月分(60年)実行
  let currentPrincipal = sheet.getRange("A2").getValue(); // 初期元本
  let currentValue = sheet.getRange("B2").getValue(); // 初期評価額
  let desiredAmount = sheet.getRange("G2").getValue(); // 初月の税引後に受け取りたい額

  // 結果を出力する開始行
  let outputRow = 5;

  for (let i = 0; i < months; i++) {
    let sellRate = 0.001; // 売却割合の初期値
    const tolerance = desiredAmount * 0.01; // 目標額の1%以内の許容範囲

    // 年と月を計算
    const years = Math.floor(i / 12); // 年数を計算
    const month = (i % 12) + 1; // 月数を計算(1~12)

    while (sellRate <= 1) {
      // 売却割合に基づいた計算
      const preTaxAmount = currentValue * sellRate; // 税引前取崩し額
      const principalPart = currentPrincipal * sellRate; // 元本部分
      const profitPart = preTaxAmount - principalPart; // 利益部分
      const tax = profitPart * taxRate; // 税額
      const postTaxAmount = preTaxAmount - tax; // 税引後取崩し額

      // 税引後取崩し額が目標額に1%以内に収まる場合に出力
      if (postTaxAmount >= desiredAmount && Math.abs(postTaxAmount - desiredAmount) <= tolerance) {
        // 出力
        sheet.getRange(outputRow, 1).setValue(`${years.toString().padStart(2, '0')}${month.toString().padStart(2, '0')}ヶ月`);
        sheet.getRange(outputRow, 2).setValue(currentValue);
        sheet.getRange(outputRow, 3).setValue(preTaxAmount);
        sheet.getRange(outputRow, 4).setValue(principalPart);
        sheet.getRange(outputRow, 5).setValue(profitPart);
        sheet.getRange(outputRow, 6).setValue(tax);
        sheet.getRange(outputRow, 7).setValue(postTaxAmount);
        sheet.getRange(outputRow, 8).setValue(desiredAmount);

        // 次月の値更新
        currentValue = (currentValue - preTaxAmount) * (1 + monthlyGrowthRate);
        currentPrincipal = currentPrincipal - principalPart;
        desiredAmount = desiredAmount * (1 + inflationRate);
        outputRow++; // 次の行に移動
        break;
      }

      // 売却割合を微細に増加させる
      sellRate += 0.00001; // より細かい調整
    }
  }
}

いいなと思ったら応援しよう!