This Gist was automatically created by Carbide, a free online programming environment.
Last active
September 7, 2016 15:47
-
-
Save alexchinco/25e89da53982d819cb1cadffb21bbab6 to your computer and use it in GitHub Desktop.
Refinancing Decision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function AnnuityValue(R,T){ return (1/R) * (1 - 1/((1+R)**T)); } | |
/// ################################ | |
/// ################################ | |
var InitialBalance = 500; ///++InitialBalance:++ **Amount you borrow** from the bank (in $1000s). | |
var R = 0.06/12; ///++R:++ Monthly **mortgage rate** when you take out the mortggae. | |
var T = 30*12; ///++T:++ **How long** it takes **until you to pay off principal** you owe if you keep on making the **same monthly payments**? a.k.a., amortization period. | |
var A = AnnuityValue(R,T); ///++A:++ **Present value** of a **T-month $1 annuity** if the **monthly interest rate is R**. | |
var MonthlyPayment = InitialBalance/A; ///++MonthlyPayment:++ **Amount you pay** each month (in $1000s) for **next T months** if you **borrow InitialBalance** from the bank when the monthly **mortgage rate is R**. | |
/// ################################ | |
/// ################################ | |
var RemainingT = 10*12; ///++RemainingT:++ **Number of months left** on mortgage. | |
var RemainingA = AnnuityValue(R,RemainingT); ///++RemainingA:++ **Present value** of a **RemainingT-month $1 annuity** if the **monthly interest rate is R**. | |
var RemainingPaymentsPV = MonthlyPayment * RemainingA; ///++RemainingPaymentsPV:++ **Present value** of your **remaining monthly payments** for the **next RemainingT months** if the **mortgage rate is R** (in $1000s). | |
/// ################################ | |
/// ################################ | |
var NewR = 0.054/12; ///++NewR:++ **New mortgage rate** that suddenly comes into effect **as of RemainingT months left** in your loan. | |
var NewRemainingA = AnnuityValue(NewR,RemainingT); ///++NewRemainingA:++ **Present value** of a **RemainingT-month $1 annuity** if the **monthly interest rate is NewR**. | |
var NewRemainingPaymentsPV = NewRemainingA * MonthlyPayment; ///++NewRemainingPaymentsPV:++ **Present value** of your **remaining monthly payments** for the **next RemainingT months** if the **mortgage rate is NewR** (in $1000s). | |
var MonthlyPaymentIfRefi = RemainingPaymentsPV / NewRemainingA; ///++MonthlyPaymentIfRefi:++ **Amount you would pay** each month (in $1000s) **if you refinance at NewR**. | |
/// ################################ | |
/// ################################ | |
var PrepaymentPenalty = 0.02; ///++PrepaymentPenalty:++ **Fraction of remaining balance** that **you pay** as fee to the bank **if you refinance**. | |
var CostOfPrepayment = PrepaymentPenalty * RemainingPaymentsPV; ///++CostOfPrepayment:++ **Amount of money** (in $1000s) that **you pay** as fee to the bank **if you refinance**. | |
var CostOfRateChange = (NewRemainingPaymentsPV - RemainingPaymentsPV); ///++CostOfRateChange:++ **Increase in present value of monthly payments** you still owe to the bank **due to mortgage rate change**. | |
if (CostOfRateChange > CostOfPrepayment){ ///**Question:** Should you refinance? | |
var Decision = 'Refinance'; | |
} else { | |
var Decision = 'Wait'; | |
} | |
Decision |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment