rent <- seq(2300, 4000, by = 100)
foo <- function(house_value, rent){
ans <- monthly_cost(house_value = house_value,
house_assessed_value = house_value * 0.8,
mil_rate = 0.025,
monthly_hoa_fee = 250,
monthly_home_insurance = 150,
monthly_utility_fee = 0,
closing_fee = house_value * 0.07,
one_time_fee = 0,
year = 10,
saving_rate = 0.04,
down_payment = 0.3,
mortgage_rate = 5.75/100,
morrgage_year = 30)
return(ans - rent)
}
ans <- lapply(rent,
function(x){return(uniroot(foo, rent = x, interval = c(1e5, 1e6))$root)})
ans <- do.call(rbind, ans) %>%
as.data.frame() %>%
mutate(rent = rent) %>%
rename(`house value` = V1) %>%
select(`house value`, rent)
ans %>%
gt() %>%
tab_header(title = "The equivlance between renting and owning")
house value |
rent |
272010.4 |
2300 |
286327.6 |
2400 |
300644.3 |
2500 |
314960.1 |
2600 |
329275.9 |
2700 |
343593.1 |
2800 |
357909.8 |
2900 |
372225.5 |
3000 |
386541.4 |
3100 |
400858.6 |
3200 |
415175.2 |
3300 |
429491.0 |
3400 |
443806.9 |
3500 |
458124.1 |
3600 |
472440.7 |
3700 |
486756.5 |
3800 |
501072.4 |
3900 |
515389.7 |
4000 |
rate1 <- 5/100/12
rate2 <- 8/100/12
house_value <- ans$`house value`
out <- lapply(house_value,
function(x){
a1 <- repayment(x * 0.8, beta = rate1, m = 30*12)
a2 <- repayment(x * 0.8, beta = rate2, m = 30*12)
return(c(a1*30*12, a2*30*12, (a2 - a1)*30*12))})
do.call(rbind, out) %>%
as.data.frame() %>%
mutate(`house value` = house_value) %>%
rename(`lower rate` = V1,
`high rate` = V2,
diff = V3) %>%
select(`house value`, `lower rate`, `high rate`, diff) %>%
gt() %>%
tab_header(title = "The difference between lower/high rate")
house value |
lower rate |
high rate |
diff |
272010.4 |
420541.2 |
574822.8 |
154281.6 |
286327.6 |
442674.0 |
605080.8 |
162406.8 |
300644.3 |
464810.4 |
635335.2 |
170524.8 |
314960.1 |
486943.2 |
665586.0 |
178642.8 |
329275.9 |
509076.0 |
695840.4 |
186764.4 |
343593.1 |
531212.4 |
726094.8 |
194882.4 |
357909.8 |
553345.2 |
756349.2 |
203004.0 |
372225.5 |
575478.0 |
786603.6 |
211125.6 |
386541.4 |
597610.8 |
816854.4 |
219243.6 |
400858.6 |
619747.2 |
847112.4 |
227365.2 |
415175.2 |
641880.0 |
877366.8 |
235486.8 |
429491.0 |
664012.8 |
907617.6 |
243604.8 |
443806.9 |
686145.6 |
937872.0 |
251726.4 |
458124.1 |
708282.0 |
968126.4 |
259844.4 |
472440.7 |
730414.8 |
998380.8 |
267966.0 |
486756.5 |
752547.6 |
1028635.2 |
276087.6 |
501072.4 |
774680.4 |
1058886.0 |
284205.6 |
515389.7 |
796816.8 |
1089144.0 |
292327.2 |