1. Mortgage Parameters

2. Amortization Schedule Function

generate_schedule <- function(apply_extra = FALSE) {
  bal <- loan_amount
  schedule <- data.frame(
    Month     = integer(),
    Payment   = numeric(),
    Principal = numeric(),
    Interest  = numeric(),
    Extra     = numeric(),
    Balance   = numeric()
  )
  for (i in 1:n_months) {
    interest  <- bal * monthly_rate
    principal <- pmt - interest
    extra     <- 0
    if (apply_extra && i %% 12 == 0 && i <= extra_years * 12) {
      extra <- extra_ann
    }
    bal <- bal - principal - extra
    if (bal < 1e-8) bal <- 0
    schedule <- rbind(schedule, data.frame(
      Month     = i,
      Payment   = pmt,
      Principal = principal,
      Interest  = interest,
      Extra     = extra,
      Balance   = bal
    ))
    if (bal <= 0) break
  }
  schedule
}

3. Scenario A: No Early Prepayment

sch_no <- generate_schedule(FALSE)
knitr::kable(head(sch_no, 12), caption = "First 12 Months - No Prepayment")
First 12 Months - No Prepayment
Month Payment Principal Interest Extra Balance
1 3144.385 1298.552 1845.833 0 498701.4
2 3144.385 1303.346 1841.040 0 497398.1
3 3144.385 1308.157 1836.228 0 496089.9
4 3144.385 1312.987 1831.399 0 494777.0
5 3144.385 1317.834 1826.552 0 493459.1
6 3144.385 1322.699 1821.687 0 492136.4
7 3144.385 1327.582 1816.804 0 490808.8
8 3144.385 1332.483 1811.903 0 489476.4
9 3144.385 1337.402 1806.984 0 488139.0
10 3144.385 1342.339 1802.046 0 486796.6
11 3144.385 1347.295 1797.091 0 485449.3
12 3144.385 1352.268 1792.117 0 484097.1

4. Scenario B: Annual Prepayment

sch_extra <- generate_schedule(TRUE)
knitr::kable(head(sch_extra, 12), caption = "First 12 Months - With Annual Prepayment")
First 12 Months - With Annual Prepayment
Month Payment Principal Interest Extra Balance
1 3144.385 1298.552 1845.833 0 498701.4
2 3144.385 1303.346 1841.040 0 497398.1
3 3144.385 1308.157 1836.228 0 496089.9
4 3144.385 1312.987 1831.399 0 494777.0
5 3144.385 1317.834 1826.552 0 493459.1
6 3144.385 1322.699 1821.687 0 492136.4
7 3144.385 1327.582 1816.804 0 490808.8
8 3144.385 1332.483 1811.903 0 489476.4
9 3144.385 1337.402 1806.984 0 488139.0
10 3144.385 1342.339 1802.046 0 486796.6
11 3144.385 1347.295 1797.091 0 485449.3
12 3144.385 1352.268 1792.117 50000 434097.1

5. Summary of Interest Paid

total_interest_no    <- sum(sch_no$Interest)
total_interest_extra <- sum(sch_extra$Interest)
interest_df <- data.frame(
  Scenario       = c("No Prepayment", "With Prepayment"),
  Total_Interest = round(c(total_interest_no, total_interest_extra), 2),
  Interest_Saved = round(total_interest_no - total_interest_extra, 2)
)
knitr::kable(interest_df, caption = "Interest Summary")
Interest Summary
Scenario Total_Interest Interest_Saved
No Prepayment 254652.49 163584.2
With Prepayment 91068.28 163584.2

6. Plot: Remaining Balance Over Time

sch_no$Scenario    <- "No Prepayment"
sch_extra$Scenario <- "With Prepayment"
plot_df <- rbind(
  sch_no[, c("Month", "Balance", "Scenario")],
  sch_extra[, c("Month", "Balance", "Scenario")]
)

ggplot(plot_df, aes(x = Month, y = Balance, color = Scenario)) +
  geom_line(size = 1) +
  labs(
    title = "Remaining Loan Balance Over Time",
    x = "Month",
    y = "Balance (USD)"
  ) +
  scale_y_continuous(labels = dollar)

7. Plot: Principal vs. Interest Payment Breakdown

break_no <- sch_no
break_no$Scenario <- "No Prepayment"
break_extra <- sch_extra
break_extra$Scenario <- "With Prepayment"
break_df <- rbind(
  break_no[, c("Month", "Principal", "Interest", "Scenario")],
  break_extra[, c("Month", "Principal", "Interest", "Scenario")]
)

# melt for stacked area
library(reshape2)
area_df <- melt(break_df, id.vars=c("Month","Scenario"),
                measure.vars=c("Principal","Interest"),
                variable.name="Component", value.name="Amount")

ggplot(area_df, aes(x=Month, y=Amount, fill=Component)) +
  geom_area(alpha=0.6) +
  facet_wrap(~Scenario) +
  labs(
    title = "Monthly Principal and Interest Payments",
    x = "Month",
    y = "Amount (USD)"
  ) +
  scale_y_continuous(labels = dollar)

8. Plot: Annual Extra Payments

# yearly extras
yearly <- sch_extra[sch_extra$Extra>0, ]
yearly$Year <- yearly$Month/12
extra_df <- data.frame(
  Year = yearly$Year,
  Extra = yearly$Extra
)

ggplot(extra_df, aes(x=factor(Year), y=Extra)) +
  geom_col() +
  labs(
    title = "Annual Extra Payments",
    x = "Year",
    y = "Extra Payment (USD)"
  ) +
  scale_y_continuous(labels = dollar)

9. Full Amortization Tables

##     Month  Payment Principal   Interest Extra    Balance      Scenario
## 1       1 3144.385  1298.552 1845.83333     0 498701.448 No Prepayment
## 2       2 3144.385  1303.346 1841.03951     0 497398.102 No Prepayment
## 3       3 3144.385  1308.157 1836.22799     0 496089.945 No Prepayment
## 4       4 3144.385  1312.987 1831.39871     0 494776.958 No Prepayment
## 5       5 3144.385  1317.834 1826.55160     0 493459.124 No Prepayment
## 6       6 3144.385  1322.699 1821.68660     0 492136.425 No Prepayment
## 7       7 3144.385  1327.582 1816.80364     0 490808.844 No Prepayment
## 8       8 3144.385  1332.483 1811.90265     0 489476.361 No Prepayment
## 9       9 3144.385  1337.402 1806.98357     0 488138.959 No Prepayment
## 10     10 3144.385  1342.339 1802.04632     0 486796.620 No Prepayment
## 11     11 3144.385  1347.295 1797.09086     0 485449.325 No Prepayment
## 12     12 3144.385  1352.268 1792.11709     0 484097.057 No Prepayment
## 13     13 3144.385  1357.260 1787.12497     0 482739.797 No Prepayment
## 14     14 3144.385  1362.271 1782.11442     0 481377.526 No Prepayment
## 15     15 3144.385  1367.300 1777.08537     0 480010.226 No Prepayment
## 16     16 3144.385  1372.348 1772.03775     0 478637.878 No Prepayment
## 17     17 3144.385  1377.414 1766.97150     0 477260.464 No Prepayment
## 18     18 3144.385  1382.499 1761.88655     0 475877.965 No Prepayment
## 19     19 3144.385  1387.603 1756.78282     0 474490.363 No Prepayment
## 20     20 3144.385  1392.725 1751.66026     0 473097.638 No Prepayment
## 21     21 3144.385  1397.867 1746.51878     0 471699.771 No Prepayment
## 22     22 3144.385  1403.027 1741.35832     0 470296.744 No Prepayment
## 23     23 3144.385  1408.207 1736.17881     0 468888.537 No Prepayment
## 24     24 3144.385  1413.405 1730.98018     0 467475.132 No Prepayment
## 25     25 3144.385  1418.623 1725.76236     0 466056.509 No Prepayment
## 26     26 3144.385  1423.860 1720.52528     0 464632.649 No Prepayment
## 27     27 3144.385  1429.117 1715.26886     0 463203.533 No Prepayment
## 28     28 3144.385  1434.392 1709.99304     0 461769.140 No Prepayment
## 29     29 3144.385  1439.688 1704.69774     0 460329.453 No Prepayment
## 30     30 3144.385  1445.002 1699.38290     0 458884.450 No Prepayment
## 31     31 3144.385  1450.337 1694.04843     0 457434.113 No Prepayment
## 32     32 3144.385  1455.691 1688.69427     0 455978.422 No Prepayment
## 33     33 3144.385  1461.065 1683.32034     0 454517.357 No Prepayment
## 34     34 3144.385  1466.459 1677.92658     0 453050.898 No Prepayment
## 35     35 3144.385  1471.872 1672.51290     0 451579.026 No Prepayment
## 36     36 3144.385  1477.306 1667.07924     0 450101.720 No Prepayment
## 37     37 3144.385  1482.760 1661.62551     0 448618.960 No Prepayment
## 38     38 3144.385  1488.234 1656.15166     0 447130.726 No Prepayment
## 39     39 3144.385  1493.728 1650.65760     0 445636.998 No Prepayment
## 40     40 3144.385  1499.242 1645.14325     0 444137.756 No Prepayment
## 41     41 3144.385  1504.777 1639.60855     0 442632.979 No Prepayment
## 42     42 3144.385  1510.332 1634.05341     0 441122.647 No Prepayment
## 43     43 3144.385  1515.908 1628.47777     0 439606.740 No Prepayment
## 44     44 3144.385  1521.504 1622.88155     0 438085.236 No Prepayment
## 45     45 3144.385  1527.121 1617.26466     0 436558.115 No Prepayment
## 46     46 3144.385  1532.758 1611.62704     0 435025.357 No Prepayment
## 47     47 3144.385  1538.417 1605.96861     0 433486.940 No Prepayment
## 48     48 3144.385  1544.096 1600.28929     0 431942.844 No Prepayment
## 49     49 3144.385  1549.796 1594.58900     0 430393.047 No Prepayment
## 50     50 3144.385  1555.518 1588.86767     0 428837.530 No Prepayment
## 51     51 3144.385  1561.260 1583.12521     0 427276.269 No Prepayment
## 52     52 3144.385  1567.024 1577.36156     0 425709.246 No Prepayment
## 53     53 3144.385  1572.809 1571.57663     0 424136.437 No Prepayment
## 54     54 3144.385  1578.615 1565.77035     0 422557.822 No Prepayment
## 55     55 3144.385  1584.443 1559.94263     0 420973.379 No Prepayment
## 56     56 3144.385  1590.292 1554.09339     0 419383.087 No Prepayment
## 57     57 3144.385  1596.163 1548.22256     0 417786.924 No Prepayment
## 58     58 3144.385  1602.055 1542.33006     0 416184.869 No Prepayment
## 59     59 3144.385  1607.970 1536.41581     0 414576.899 No Prepayment
## 60     60 3144.385  1613.906 1530.47972     0 412962.994 No Prepayment
## 61     61 3144.385  1619.864 1524.52172     0 411343.130 No Prepayment
## 62     62 3144.385  1625.844 1518.54172     0 409717.286 No Prepayment
## 63     63 3144.385  1631.846 1512.53965     0 408085.441 No Prepayment
## 64     64 3144.385  1637.870 1506.51542     0 406447.571 No Prepayment
## 65     65 3144.385  1643.916 1500.46895     0 404803.654 No Prepayment
## 66     66 3144.385  1649.985 1494.40016     0 403153.669 No Prepayment
## 67     67 3144.385  1656.076 1488.30896     0 401497.592 No Prepayment
## 68     68 3144.385  1662.190 1482.19528     0 399835.402 No Prepayment
## 69     69 3144.385  1668.326 1476.05903     0 398167.076 No Prepayment
## 70     70 3144.385  1674.485 1469.90012     0 396492.591 No Prepayment
## 71     71 3144.385  1680.667 1463.71848     0 394811.924 No Prepayment
## 72     72 3144.385  1686.871 1457.51402     0 393125.052 No Prepayment
## 73     73 3144.385  1693.099 1451.28665     0 391431.954 No Prepayment
## 74     74 3144.385  1699.349 1445.03630     0 389732.605 No Prepayment
## 75     75 3144.385  1705.623 1438.76287     0 388026.982 No Prepayment
## 76     76 3144.385  1711.919 1432.46628     0 386315.063 No Prepayment
## 77     77 3144.385  1718.239 1426.14644     0 384596.824 No Prepayment
## 78     78 3144.385  1724.582 1419.80328     0 382872.242 No Prepayment
## 79     79 3144.385  1730.949 1413.43669     0 381141.293 No Prepayment
## 80     80 3144.385  1737.339 1407.04661     0 379403.954 No Prepayment
## 81     81 3144.385  1743.752 1400.63293     0 377660.202 No Prepayment
## 82     82 3144.385  1750.190 1394.19558     0 375910.012 No Prepayment
## 83     83 3144.385  1756.651 1387.73446     0 374153.361 No Prepayment
## 84     84 3144.385  1763.136 1381.24949     0 372390.225 No Prepayment
## 85     85 3144.385  1769.645 1374.74058     0 370620.581 No Prepayment
## 86     86 3144.385  1776.178 1368.20764     0 368844.403 No Prepayment
## 87     87 3144.385  1782.735 1361.65059     0 367061.668 No Prepayment
## 88     88 3144.385  1789.316 1355.06932     0 365272.352 No Prepayment
## 89     89 3144.385  1795.922 1348.46377     0 363476.430 No Prepayment
## 90     90 3144.385  1802.552 1341.83382     0 361673.879 No Prepayment
## 91     91 3144.385  1809.206 1335.17940     0 359864.673 No Prepayment
## 92     92 3144.385  1815.885 1328.50042     0 358048.788 No Prepayment
## 93     93 3144.385  1822.589 1321.79677     0 356226.199 No Prepayment
## 94     94 3144.385  1829.317 1315.06839     0 354396.882 No Prepayment
## 95     95 3144.385  1836.070 1308.31516     0 352560.812 No Prepayment
## 96     96 3144.385  1842.848 1301.53700     0 350717.964 No Prepayment
## 97     97 3144.385  1849.652 1294.73382     0 348868.312 No Prepayment
## 98     98 3144.385  1856.480 1287.90552     0 347011.832 No Prepayment
## 99     99 3144.385  1863.333 1281.05201     0 345148.499 No Prepayment
## 100   100 3144.385  1870.212 1274.17321     0 343278.287 No Prepayment
## 101   101 3144.385  1877.116 1267.26901     0 341401.170 No Prepayment
## 102   102 3144.385  1884.046 1260.33932     0 339517.124 No Prepayment
## 103   103 3144.385  1891.001 1253.38405     0 337626.123 No Prepayment
## 104   104 3144.385  1897.982 1246.40310     0 335728.140 No Prepayment
## 105   105 3144.385  1904.989 1239.39639     0 333823.151 No Prepayment
## 106   106 3144.385  1912.022 1232.36380     0 331911.130 No Prepayment
## 107   107 3144.385  1919.080 1225.30525     0 329992.050 No Prepayment
## 108   108 3144.385  1926.165 1218.22065     0 328065.885 No Prepayment
## 109   109 3144.385  1933.275 1211.10989     0 326132.609 No Prepayment
## 110   110 3144.385  1940.413 1203.97288     0 324192.197 No Prepayment
## 111   111 3144.385  1947.576 1196.80953     0 322244.621 No Prepayment
## 112   112 3144.385  1954.766 1189.61973     0 320289.855 No Prepayment
## 113   113 3144.385  1961.982 1182.40338     0 318327.873 No Prepayment
## 114   114 3144.385  1969.225 1175.16040     0 316358.648 No Prepayment
## 115   115 3144.385  1976.495 1167.89068     0 314382.154 No Prepayment
## 116   116 3144.385  1983.791 1160.59412     0 312398.362 No Prepayment
## 117   117 3144.385  1991.115 1153.27062     0 310407.248 No Prepayment
## 118   118 3144.385  1998.465 1145.92009     0 308408.782 No Prepayment
## 119   119 3144.385  2005.843 1138.54242     0 306402.939 No Prepayment
## 120   120 3144.385  2013.248 1131.13752     0 304389.692 No Prepayment
## 121   121 3144.385  2020.680 1123.70528     0 302369.011 No Prepayment
## 122   122 3144.385  2028.140 1116.24560     0 300340.872 No Prepayment
## 123   123 3144.385  2035.627 1108.75838     0 298305.245 No Prepayment
## 124   124 3144.385  2043.142 1101.24353     0 296262.103 No Prepayment
## 125   125 3144.385  2050.684 1093.70093     0 294211.418 No Prepayment
## 126   126 3144.385  2058.255 1086.13049     0 292153.163 No Prepayment
## 127   127 3144.385  2065.853 1078.53209     0 290087.310 No Prepayment
## 128   128 3144.385  2073.480 1070.90565     0 288013.830 No Prepayment
## 129   129 3144.385  2081.134 1063.25106     0 285932.696 No Prepayment
## 130   130 3144.385  2088.817 1055.56820     0 283843.879 No Prepayment
## 131   131 3144.385  2096.528 1047.85699     0 281747.350 No Prepayment
## 132   132 3144.385  2104.268 1040.11730     0 279643.082 No Prepayment
## 133   133 3144.385  2112.036 1032.34905     0 277531.046 No Prepayment
## 134   134 3144.385  2119.833 1024.55211     0 275411.213 No Prepayment
## 135   135 3144.385  2127.659 1016.72639     0 273283.554 No Prepayment
## 136   136 3144.385  2135.514 1008.87179     0 271148.040 No Prepayment
## 137   137 3144.385  2143.397 1000.98818     0 269004.643 No Prepayment
## 138   138 3144.385  2151.310  993.07547     0 266853.333 No Prepayment
## 139   139 3144.385  2159.252  985.13355     0 264694.081 No Prepayment
## 140   140 3144.385  2167.223  977.16232     0 262526.858 No Prepayment
## 141   141 3144.385  2175.224  969.16165     0 260351.634 No Prepayment
## 142   142 3144.385  2183.254  961.13145     0 258168.380 No Prepayment
## 143   143 3144.385  2191.314  953.07160     0 255977.067 No Prepayment
## 144   144 3144.385  2199.403  944.98200     0 253777.663 No Prepayment
## 145   145 3144.385  2207.523  936.86254     0 251570.140 No Prepayment
## 146   146 3144.385  2215.672  928.71310     0 249354.468 No Prepayment
## 147   147 3144.385  2223.852  920.53358     0 247130.616 No Prepayment
## 148   148 3144.385  2232.062  912.32386     0 244898.555 No Prepayment
## 149   149 3144.385  2240.302  904.08383     0 242658.253 No Prepayment
## 150   150 3144.385  2248.572  895.81338     0 240409.681 No Prepayment
## 151   151 3144.385  2256.873  887.51241     0 238152.808 No Prepayment
## 152   152 3144.385  2265.205  879.18078     0 235887.604 No Prepayment
## 153   153 3144.385  2273.567  870.81840     0 233614.037 No Prepayment
## 154   154 3144.385  2281.960  862.42515     0 231332.076 No Prepayment
## 155   155 3144.385  2290.384  854.00092     0 229041.692 No Prepayment
## 156   156 3144.385  2298.840  845.54558     0 226742.852 No Prepayment
## 157   157 3144.385  2307.326  837.05903     0 224435.526 No Prepayment
## 158   158 3144.385  2315.844  828.54115     0 222119.682 No Prepayment
## 159   159 3144.385  2324.394  819.99182     0 219795.288 No Prepayment
## 160   160 3144.385  2332.974  811.41094     0 217462.314 No Prepayment
## 161   161 3144.385  2341.587  802.79837     0 215120.726 No Prepayment
## 162   162 3144.385  2350.231  794.15402     0 212770.495 No Prepayment
## 163   163 3144.385  2358.908  785.47774     0 210411.587 No Prepayment
## 164   164 3144.385  2367.616  776.76944     0 208043.972 No Prepayment
## 165   165 3144.385  2376.356  768.02899     0 205667.615 No Prepayment
## 166   166 3144.385  2385.129  759.25628     0 203282.486 No Prepayment
## 167   167 3144.385  2393.934  750.45118     0 200888.552 No Prepayment
## 168   168 3144.385  2402.772  741.61357     0 198485.780 No Prepayment
## 169   169 3144.385  2411.642  732.74334     0 196074.138 No Prepayment
## 170   170 3144.385  2420.545  723.84036     0 193653.593 No Prepayment
## 171   171 3144.385  2429.481  714.90451     0 191224.112 No Prepayment
## 172   172 3144.385  2438.450  705.93568     0 188785.662 No Prepayment
## 173   173 3144.385  2447.452  696.93374     0 186338.211 No Prepayment
## 174   174 3144.385  2456.487  687.89856     0 183881.724 No Prepayment
## 175   175 3144.385  2465.555  678.83003     0 181416.168 No Prepayment
## 176   176 3144.385  2474.657  669.72802     0 178941.511 No Prepayment
## 177   177 3144.385  2483.793  660.59241     0 176457.718 No Prepayment
## 178   178 3144.385  2492.962  651.42308     0 173964.756 No Prepayment
## 179   179 3144.385  2502.165  642.21989     0 171462.590 No Prepayment
## 180   180 3144.385  2511.403  632.98273     0 168951.188 No Prepayment
## 181   181 3144.385  2520.674  623.71147     0 166430.514 No Prepayment
## 182   182 3144.385  2529.979  614.40598     0 163900.534 No Prepayment
## 183   183 3144.385  2539.319  605.06614     0 161361.215 No Prepayment
## 184   184 3144.385  2548.694  595.69182     0 158812.522 No Prepayment
## 185   185 3144.385  2558.102  586.28289     0 156254.419 No Prepayment
## 186   186 3144.385  2567.546  576.83923     0 153686.873 No Prepayment
## 187   187 3144.385  2577.025  567.36071     0 151109.848 No Prepayment
## 188   188 3144.385  2586.538  557.84719     0 148523.310 No Prepayment
## 189   189 3144.385  2596.087  548.29855     0 145927.223 No Prepayment
## 190   190 3144.385  2605.671  538.71467     0 143321.552 No Prepayment
## 191   191 3144.385  2615.290  529.09540     0 140706.262 No Prepayment
## 192   192 3144.385  2624.945  519.44062     0 138081.318 No Prepayment
## 193   193 3144.385  2634.635  509.75020     0 135446.682 No Prepayment
## 194   194 3144.385  2644.361  500.02400     0 132802.321 No Prepayment
## 195   195 3144.385  2654.123  490.26190     0 130148.198 No Prepayment
## 196   196 3144.385  2663.922  480.46376     0 127484.276 No Prepayment
## 197   197 3144.385  2673.756  470.62945     0 124810.520 No Prepayment
## 198   198 3144.385  2683.627  460.75884     0 122126.893 No Prepayment
## 199   199 3144.385  2693.534  450.85178     0 119433.360 No Prepayment
## 200   200 3144.385  2703.477  440.90815     0 116729.883 No Prepayment
## 201   201 3144.385  2713.458  430.92782     0 114016.425 No Prepayment
## 202   202 3144.385  2723.475  420.91064     0 111292.950 No Prepayment
## 203   203 3144.385  2733.529  410.85647     0 108559.421 No Prepayment
## 204   204 3144.385  2743.620  400.76520     0 105815.801 No Prepayment
## 205   205 3144.385  2753.749  390.63667     0 103062.052 No Prepayment
## 206   206 3144.385  2763.915  380.47074     0 100298.138 No Prepayment
## 207   207 3144.385  2774.118  370.26729     0  97524.020 No Prepayment
## 208   208 3144.385  2784.359  360.02617     0  94739.660 No Prepayment
## 209   209 3144.385  2794.638  349.74725     0  91945.022 No Prepayment
## 210   210 3144.385  2804.955  339.43037     0  89140.067 No Prepayment
## 211   211 3144.385  2815.310  329.07542     0  86324.757 No Prepayment
## 212   212 3144.385  2825.703  318.68223     0  83499.054 No Prepayment
## 213   213 3144.385  2836.135  308.25068     0  80662.919 No Prepayment
## 214   214 3144.385  2846.605  297.78061     0  77816.315 No Prepayment
## 215   215 3144.385  2857.113  287.27190     0  74959.201 No Prepayment
## 216   216 3144.385  2867.661  276.72438     0  72091.540 No Prepayment
## 217   217 3144.385  2878.247  266.13794     0  69213.293 No Prepayment
## 218   218 3144.385  2888.873  255.51241     0  66324.420 No Prepayment
## 219   219 3144.385  2899.538  244.84765     0  63424.882 No Prepayment
## 220   220 3144.385  2910.242  234.14352     0  60514.640 No Prepayment
## 221   221 3144.385  2920.986  223.39988     0  57593.655 No Prepayment
## 222   222 3144.385  2931.769  212.61658     0  54661.886 No Prepayment
## 223   223 3144.385  2942.592  201.79346     0  51719.294 No Prepayment
## 224   224 3144.385  2953.455  190.93039     0  48765.839 No Prepayment
## 225   225 3144.385  2964.358  180.02722     0  45801.481 No Prepayment
## 226   226 3144.385  2975.302  169.08380     0  42826.179 No Prepayment
## 227   227 3144.385  2986.285  158.09998     0  39839.894 No Prepayment
## 228   228 3144.385  2997.310  147.07561     0  36842.584 No Prepayment
## 229   229 3144.385  3008.375  136.01054     0  33834.209 No Prepayment
## 230   230 3144.385  3019.481  124.90462     0  30814.728 No Prepayment
## 231   231 3144.385  3030.628  113.75771     0  27784.101 No Prepayment
## 232   232 3144.385  3041.816  102.56964     0  24742.285 No Prepayment
## 233   233 3144.385  3053.045   91.34027     0  21689.240 No Prepayment
## 234   234 3144.385  3064.316   80.06944     0  18624.924 No Prepayment
## 235   235 3144.385  3075.628   68.75701     0  15549.295 No Prepayment
## 236   236 3144.385  3086.983   57.40282     0  12462.313 No Prepayment
## 237   237 3144.385  3098.379   46.00671     0   9363.934 No Prepayment
## 238   238 3144.385  3109.817   34.56852     0   6254.117 No Prepayment
## 239   239 3144.385  3121.297   23.08812     0   3132.820 No Prepayment
## 240   240 3144.385  3132.820   11.56533     0      0.000 No Prepayment
##     Month  Payment Principal    Interest Extra    Balance        Scenario
## 1       1 3144.385  1298.552 1845.833333     0 498701.448 With Prepayment
## 2       2 3144.385  1303.346 1841.039512     0 497398.102 With Prepayment
## 3       3 3144.385  1308.157 1836.227993     0 496089.945 With Prepayment
## 4       4 3144.385  1312.987 1831.398712     0 494776.958 With Prepayment
## 5       5 3144.385  1317.834 1826.551603     0 493459.124 With Prepayment
## 6       6 3144.385  1322.699 1821.686600     0 492136.425 With Prepayment
## 7       7 3144.385  1327.582 1816.803637     0 490808.844 With Prepayment
## 8       8 3144.385  1332.483 1811.902648     0 489476.361 With Prepayment
## 9       9 3144.385  1337.402 1806.983566     0 488138.959 With Prepayment
## 10     10 3144.385  1342.339 1802.046324     0 486796.620 With Prepayment
## 11     11 3144.385  1347.295 1797.090856     0 485449.325 With Prepayment
## 12     12 3144.385  1352.268 1792.117093 50000 434097.057 With Prepayment
## 13     13 3144.385  1541.844 1602.541636     0 432555.213 With Prepayment
## 14     14 3144.385  1547.536 1596.849663     0 431007.678 With Prepayment
## 15     15 3144.385  1553.249 1591.136677     0 429454.429 With Prepayment
## 16     16 3144.385  1558.983 1585.402600     0 427895.446 With Prepayment
## 17     17 3144.385  1564.738 1579.647356     0 426330.708 With Prepayment
## 18     18 3144.385  1570.515 1573.870864     0 424760.194 With Prepayment
## 19     19 3144.385  1576.312 1568.073048     0 423183.881 With Prepayment
## 20     20 3144.385  1582.132 1562.253829     0 421601.750 With Prepayment
## 21     21 3144.385  1587.972 1556.413126     0 420013.777 With Prepayment
## 22     22 3144.385  1593.835 1550.550862     0 418419.943 With Prepayment
## 23     23 3144.385  1599.718 1544.666956     0 416820.225 With Prepayment
## 24     24 3144.385  1605.624 1538.761329 50000 365214.600 With Prepayment
## 25     25 3144.385  1796.135 1348.250567     0 363418.466 With Prepayment
## 26     26 3144.385  1802.766 1341.619836     0 361615.700 With Prepayment
## 27     27 3144.385  1809.421 1334.964626     0 359806.279 With Prepayment
## 28     28 3144.385  1816.101 1328.284848     0 357990.179 With Prepayment
## 29     29 3144.385  1822.805 1321.580410     0 356167.374 With Prepayment
## 30     30 3144.385  1829.534 1314.851222     0 354337.840 With Prepayment
## 31     31 3144.385  1836.288 1308.097191     0 352501.551 With Prepayment
## 32     32 3144.385  1843.067 1301.318227     0 350658.484 With Prepayment
## 33     33 3144.385  1849.871 1294.514238     0 348808.613 With Prepayment
## 34     34 3144.385  1856.700 1287.685130     0 346951.913 With Prepayment
## 35     35 3144.385  1863.555 1280.830812     0 345088.358 With Prepayment
## 36     36 3144.385  1870.434 1273.951189 50000 293217.924 With Prepayment
## 37     37 3144.385  2061.923 1082.462836     0 291156.002 With Prepayment
## 38     38 3144.385  2069.534 1074.850906     0 289086.467 With Prepayment
## 39     39 3144.385  2077.175 1067.210874     0 287009.293 With Prepayment
## 40     40 3144.385  2084.843 1059.542638     0 284924.450 With Prepayment
## 41     41 3144.385  2092.539 1051.846094     0 282831.910 With Prepayment
## 42     42 3144.385  2100.264 1044.121136     0 280731.646 With Prepayment
## 43     43 3144.385  2108.018 1036.367661     0 278623.629 With Prepayment
## 44     44 3144.385  2115.800 1028.585562     0 276507.829 With Prepayment
## 45     45 3144.385  2123.611 1020.774734     0 274384.218 With Prepayment
## 46     46 3144.385  2131.450 1012.935072     0 272252.768 With Prepayment
## 47     47 3144.385  2139.319 1005.066467     0 270113.449 With Prepayment
## 48     48 3144.385  2147.217  997.168815 50000 217966.232 With Prepayment
## 49     49 3144.385  2339.727  804.658674     0 215626.505 With Prepayment
## 50     50 3144.385  2348.364  796.021183     0 213278.141 With Prepayment
## 51     51 3144.385  2357.034  787.351805     0 210921.108 With Prepayment
## 52     52 3144.385  2365.735  778.650423     0 208555.373 With Prepayment
## 53     53 3144.385  2374.468  769.916918     0 206180.904 With Prepayment
## 54     54 3144.385  2383.234  761.151172     0 203797.670 With Prepayment
## 55     55 3144.385  2392.032  752.353065     0 201405.638 With Prepayment
## 56     56 3144.385  2400.863  743.522479     0 199004.775 With Prepayment
## 57     57 3144.385  2409.726  734.659294     0 196595.049 With Prepayment
## 58     58 3144.385  2418.622  725.763388     0 194176.427 With Prepayment
## 59     59 3144.385  2427.551  716.834642     0 191748.876 With Prepayment
## 60     60 3144.385  2436.512  707.872934 50000 139312.364 With Prepayment
## 61     61 3144.385  2630.091  514.294809     0 136682.273 With Prepayment
## 62     62 3144.385  2639.800  504.585391     0 134042.473 With Prepayment
## 63     63 3144.385  2649.545  494.840129     0 131392.928 With Prepayment
## 64     64 3144.385  2659.326  485.058891     0 128733.601 With Prepayment
## 65     65 3144.385  2669.144  475.241544     0 126064.457 With Prepayment
## 66     66 3144.385  2678.997  465.387955     0 123385.460 With Prepayment
## 67     67 3144.385  2688.887  455.497989     0 120696.572 With Prepayment
## 68     68 3144.385  2698.814  445.571513     0 117997.759 With Prepayment
## 69     69 3144.385  2708.777  435.608392     0 115288.982 With Prepayment
## 70     70 3144.385  2718.777  425.608490     0 112570.205 With Prepayment
## 71     71 3144.385  2728.814  415.571672     0 109841.391 With Prepayment
## 72     72 3144.385  2738.888  405.497802     0 107102.503 With Prepayment
## 73     73 3144.385  2748.999  395.386742     0 104353.505 With Prepayment
## 74     74 3144.385  2759.147  385.238355     0 101594.358 With Prepayment
## 75     75 3144.385  2769.333  375.052504     0  98825.025 With Prepayment
## 76     76 3144.385  2779.556  364.829050     0  96045.468 With Prepayment
## 77     77 3144.385  2789.818  354.567855     0  93255.651 With Prepayment
## 78     78 3144.385  2800.117  344.268778     0  90455.534 With Prepayment
## 79     79 3144.385  2810.454  333.931681     0  87645.081 With Prepayment
## 80     80 3144.385  2820.829  323.556423     0  84824.252 With Prepayment
## 81     81 3144.385  2831.243  313.142862     0  81993.009 With Prepayment
## 82     82 3144.385  2841.695  302.690859     0  79151.315 With Prepayment
## 83     83 3144.385  2852.185  292.200270     0  76299.129 With Prepayment
## 84     84 3144.385  2862.714  281.670953     0  73436.415 With Prepayment
## 85     85 3144.385  2873.283  271.102766     0  70563.132 With Prepayment
## 86     86 3144.385  2883.890  260.495564     0  67679.243 With Prepayment
## 87     87 3144.385  2894.536  249.849204     0  64784.706 With Prepayment
## 88     88 3144.385  2905.222  239.163541     0  61879.485 With Prepayment
## 89     89 3144.385  2915.947  228.438431     0  58963.538 With Prepayment
## 90     90 3144.385  2926.712  217.673726     0  56036.826 With Prepayment
## 91     91 3144.385  2937.516  206.869282     0  53099.310 With Prepayment
## 92     92 3144.385  2948.360  196.024952     0  50150.949 With Prepayment
## 93     93 3144.385  2959.245  185.140588     0  47191.705 With Prepayment
## 94     94 3144.385  2970.169  174.216043     0  44221.535 With Prepayment
## 95     95 3144.385  2981.134  163.251168     0  41240.401 With Prepayment
## 96     96 3144.385  2992.140  152.245814     0  38248.261 With Prepayment
## 97     97 3144.385  3003.186  141.199832     0  35245.076 With Prepayment
## 98     98 3144.385  3014.272  130.113072     0  32230.804 With Prepayment
## 99     99 3144.385  3025.400  118.985383     0  29205.404 With Prepayment
## 100   100 3144.385  3036.569  107.816615     0  26168.835 With Prepayment
## 101   101 3144.385  3047.779   96.606615     0  23121.056 With Prepayment
## 102   102 3144.385  3059.030   85.355232     0  20062.026 With Prepayment
## 103   103 3144.385  3070.323   74.062312     0  16991.703 With Prepayment
## 104   104 3144.385  3081.658   62.727703     0  13910.045 With Prepayment
## 105   105 3144.385  3093.034   51.351250     0  10817.011 With Prepayment
## 106   106 3144.385  3104.453   39.932799     0   7712.558 With Prepayment
## 107   107 3144.385  3115.913   28.472195     0   4596.645 With Prepayment
## 108   108 3144.385  3127.416   16.969282     0   1469.229 With Prepayment
## 109   109 3144.385  3138.961    5.423904     0      0.000 With Prepayment

10. Export Schedules to Excel

library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, "No Prepayment")
addWorksheet(wb, "With Prepayment")
writeData(wb, "No Prepayment", sch_no)
writeData(wb, "With Prepayment", sch_extra)

# Save to file in working directory
saveWorkbook(wb, file = "mortgage_schedule.xlsx", overwrite = TRUE)
cat("Excel file 'mortgage_schedule.xlsx' has been created in your working directory.")
## Excel file 'mortgage_schedule.xlsx' has been created in your working directory.