Skip to content

Instantly share code, notes, and snippets.

@perryqh
Created May 17, 2010 13:55
Show Gist options
  • Save perryqh/403782 to your computer and use it in GitHub Desktop.
Save perryqh/403782 to your computer and use it in GitHub Desktop.
def assert_monthly_apr_payment_matches(loan_amount, rate, period, fee, points)
mortgage_util = MortgageUtil.new(loan_amount, rate, period, fee, points)
monthly_payment_with_fees = mortgage_util.monthly_payment_with_fees
monthly_payment_from_apr = MortgageUtil.new(loan_amount, mortgage_util.apr, period, 0, 0).monthly_payment
monthly_payment_with_fees.should be_close(monthly_payment_from_apr, 0.01)
end
it "should calculate original monthly payment from APR" do
assert_monthly_apr_payment_matches(300000, 6.5, 360, 1200, 1.25)
assert_monthly_apr_payment_matches(300000, 6.5, 360, 0, 0)
assert_monthly_apr_payment_matches(400000, 1.1, 180, 1200, 1.25)
assert_monthly_apr_payment_matches(300000, 6.5, 360, 0, 7.25)
assert_monthly_apr_payment_matches(300000, 6.5, 360, 10000, 7.25)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment