# robertgreiner/LoanGeek

Added purchase price and down payment amount

robertgreiner committed Feb 4, 2011
1 parent 96f2225 commit 57cc72dd9c191dc19d1ebca978136b0d06328634
 @@ -17,55 +17,61 @@ public class TestLoanData { Assert.AreEqual(0.19d, num); } + [Test] + public void TestPrincipalCalculation() { + LoanData loanData = new LoanData(200000.00, 50, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + Assert.AreEqual(100000.00, Math.Round(loanData.Principal, 2)); + } + [Test] public void TestTotalMonthlyPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); Assert.AreEqual(1674.57, Math.Round(loanData.MonthlyPayment, 2)); } [Test] public void TestMonthlyInterestPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); Assert.AreEqual(687.50d, Math.Round(loanData.InterestOnlyMonthly, 2)); } [Test] public void TestMonthlyPrincipalPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); double principalMonthly = Math.Round(loanData.PrincipalOnlyMonthly, 2); Assert.AreEqual(281.80d, principalMonthly); } [Test] public void TestMonthlyPrincipalAndInterestPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); double principalAndInterest = loanData.InterestOnlyMonthly + loanData.PrincipalOnlyMonthly; Assert.AreEqual(969.30d, Math.Round(principalAndInterest, 2)); } [Test] public void TestMonthlyPropertyTaxPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); Assert.AreEqual(460.00, Math.Round(loanData.MonthlyPropertyTaxPayment, 2)); } [Test] public void TestMonthlyPmiPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); Assert.AreEqual(133.33d, Math.Round(loanData.MonthlyPmiPayment, 2)); } [Test] public void TestMonthlyHoaPayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27); double monthlyHoa = loanData.HoaDuesYearly / 12; monthlyHoa = Math.Round(monthlyHoa, 2); Assert.AreEqual(50.00d, monthlyHoa); } [Test] public void TestMonthlyInsurancePayment() { - LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27); + LoanData loanData = new LoanData(400000.00, 50, 4.125, 30, 2.76, 0.8, 600.00, 743.27); double monthlyInsurance = loanData.InsuranceYearly / 12; monthlyInsurance = Math.Round(monthlyInsurance); Assert.AreEqual(62.00d, monthlyInsurance);
Binary file not shown.
 @@ -1,11 +1,11 @@ - [0-1010]D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll + [0-1011]D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll [0-1000]UnitTests.TestLoanData false - - + +
Binary file not shown.
Binary file not shown.
Binary file not shown.
 @@ -1,23 +1,24 @@ - - + + - + - + - + - + - + - + + - +
Binary file not shown.
 @@ -1,6 +1,5 @@ D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.pdb -D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\nunit.framework.dll D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\nunit.framework.xml D:\projects\LoanGeek\LoanGeek.Tests\obj\Release\ResolveAssemblyReference.cache D:\projects\LoanGeek\LoanGeek.Tests\obj\Release\LoanGeek.Tests.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
 @@ -7,8 +7,11 @@ namespace LoanGeek.Models { public class LoanData { - [Required(ErrorMessage = "Please enter your the total loan amount.")] - public double Principal { get; set; } + [Required(ErrorMessage = "Please enter your the purchase price for your new home.")] + public double PurchasePrice { get; set; } + + [Required(ErrorMessage = "Please enter the downpayment amount.")] + public double DownPayment { get; set; } [Required(ErrorMessage = "Please enter the interest rate.")] public double InterestRate { get; set; } @@ -28,6 +31,8 @@ public class LoanData { [Required(ErrorMessage = "Please enter your yearly insurance premium.")] public double InsuranceYearly { get; set; } + public double Principal { get; set; } + public double MonthlyInterestMultiplier { get; private set; } public int AmortizedMonths { get; private set; } public double InterestOnlyMonthly { get; private set; } @@ -37,8 +42,9 @@ public class LoanData { public double MonthlyPropertyTaxPayment { get; private set; } public double MonthlyPmiPayment { get; private set; } - public LoanData(double principal, double interest, int term, double tax, double pmi, double hoa, double insurance) { - Principal = principal; + public LoanData(double purchasePrice, double downPayment, double interest, int term, double tax, double pmi, double hoa, double insurance) { + PurchasePrice = purchasePrice; + DownPayment = downPayment; InterestRate = interest; LoanTerm = term; PropertyTaxPercent = tax; @@ -50,7 +56,8 @@ public class LoanData { } public LoanData() { - Principal = 200000; + PurchasePrice = 200000; + DownPayment = 7.5; InterestRate = 4.5; LoanTerm = 30; PropertyTaxPercent = 3.0; @@ -92,8 +99,9 @@ public class LoanData { return principalAndInterest; } + //Property tax is based on the appraisal value of the home. Usually, this is the same as the purchase price. private double CalculatePropertyTax() { - MonthlyPropertyTaxPayment = (Principal * (PropertyTaxPercent / 100)) / 12; + MonthlyPropertyTaxPayment = (PurchasePrice * (PropertyTaxPercent / 100)) / 12; return MonthlyPropertyTaxPayment; } @@ -102,7 +110,12 @@ public class LoanData { return MonthlyPmiPayment; } + private void CalculatePrincipal() { + Principal = PurchasePrice - (PurchasePrice * (DownPayment / 100)); + } + public void CalculateTotalMonthlyPayment() { + CalculatePrincipal(); MonthlyPayment = CalculatePrincipalAndInterest(); MonthlyPayment += CalculatePropertyTax(); MonthlyPayment += CalculatePmi();
 @@ -26,13 +26,15 @@ <% using (Html.BeginForm()) { %> <%: Html.ValidationSummary() %> -

Loan Amount (\$)

<%: Html.TextBoxFor(x => x.Principal)%>
-

Loan Term (years)

<%: Html.TextBoxFor(x => x.LoanTerm)%>
-

Interest Rate (%)

<%: Html.TextBoxFor(x => x.InterestRate)%>
-

Property Tax (%)

<%: Html.TextBoxFor(x => x.PropertyTaxPercent)%>
-

PMI (%)

<%: Html.TextBoxFor(x => x.PmiPercent)%>
-

HOA (\$/year)

-

Insurance (\$/year)

<%: Html.TextBoxFor(x => x.InsuranceYearly)%>
+

Purchase Price (\$)

<%: Html.TextBoxFor(x => x.PurchasePrice) %>
+

Down Payment (%)

<%: Html.TextBoxFor(x => x.DownPayment) %>
+

Loan Amount (\$)

<%: Html.TextBox("principal") %>
+

Loan Term (years)

<%: Html.TextBoxFor(x => x.LoanTerm) %>
+

Interest Rate (%)

<%: Html.TextBoxFor(x => x.InterestRate) %>
+

Property Tax (%)

<%: Html.TextBoxFor(x => x.PropertyTaxPercent) %>
+

PMI (%)

<%: Html.TextBoxFor(x => x.PmiPercent) %>
+

HOA (\$/year)

+

Insurance (\$/year)

<%: Html.TextBoxFor(x => x.InsuranceYearly) %>
<% } %>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.