Skip to content

Instantly share code, notes, and snippets.

@tchakravarty
Created September 15, 2019 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tchakravarty/aa4e3064bcec2989c045ccd9619e5fa0 to your computer and use it in GitHub Desktop.
Save tchakravarty/aa4e3064bcec2989c045ccd9619e5fa0 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(FinancialMath)
library(FinCal)
library(writexl)
# loan parameters
loan_amount = 4.8e6
roi_0 = 0.0925
tenure_0 = 48
# EMI of the loan
emi_0 = FinCal::pmt(roi_0/12, 48, -loan_amount, 0, type = 0)
# get the amortization schedule
m_amort = FinancialMath::amort.table(
Loan = loan_amount, n = 48, i = roi_0/12
)$Schedule %>% as_tibble()
# compute the impact of the rescheduling
df_amort = m_amort %>%
mutate(
`Payment Dates` =
seq.Date(from = as.Date("2018-05-05"), as.Date("2022-04-05"), by = "month"),
Rate = case_when(
`Payment Dates` < as.Date("2018-07-05") ~ 0.0947,
`Payment Dates` < as.Date("2018-09-05") ~ 0.099,
`Payment Dates` < as.Date("2018-11-05") ~ 0.1015,
TRUE ~ 0.1065
),
`Pre-Payment Balance` = `Principal Paid` + Balance,
`Payment Required` = `Pre-Payment Balance`*Rate/12,
`Remaining Periods` = seq(48, 1, -1),
`EMI (PIT)` = pmt(r = Rate/12, n = `Remaining Periods`, pv = -`Pre-Payment Balance`, 0),
Difference = `EMI (PIT)` - Payment
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment