public Home(string name, DateTime purchasedAt, decimal purchasePrice, decimal downPayment, IMortgage mortgage, decimal monthlyMaintenanceFees = 0.00M) : base(name, purchasePrice) { Financing = mortgage; PurchasedAt = new DateTime(purchasedAt.Year, purchasedAt.Month, purchasedAt.Day); DownPayment = downPayment; MonthlyMaintenanceFees = monthlyMaintenanceFees; }
public Payment(IMortgage mortgage, DateTime at, decimal previousBalance, decimal interest, decimal principal) { Mortgage = mortgage; At = at; Interest = decimal.Round(interest, 2); Principal = decimal.Round(principal, 2); Balance = decimal.Round(previousBalance - Principal, 2); }
public InsuredMortgage(IMortgage baseMortgage, decimal downPayment) { var rate = downPayment / (downPayment + baseMortgage.InitialValue); ValidateInsuranceRate(rate); BaseMortgage = baseMortgage; Calculator = BaseMortgage.Calculator; InsuranceRate = downPayment / (downPayment + baseMortgage.InitialValue); Insurance = GetInsurance(baseMortgage.InitialValue, downPayment); }
public IEnumerable <Payment> GetMonthlyPayments(IMortgage mortgage, DateTime endAt) { if (endAt < mortgage.InitiatedAt) { yield break; } yield return(new Payment(mortgage, mortgage.InitiatedAt, mortgage.InitialValue, 0, 0)); var monthlyPayment = Convert.ToDecimal(mortgage.MonthlyPayment); decimal balance = mortgage.InitialValue; var interestRate = mortgage.PeriodicAnnualInterestRate; var i = mortgage.InitiatedAt; for (; balance > 0 && i < endAt; i = i.AddDays(1)) { if (mortgage.IsMonthlyPayment(i)) { var interestPayment = balance * interestRate / 12; var principalPayment = monthlyPayment - interestPayment; principalPayment = principalPayment > balance ? balance : principalPayment; yield return(new Payment(mortgage, i, balance, interestPayment, principalPayment)); balance -= principalPayment; } if (balance == 0) { yield break; } var extraPayment = mortgage.GetPrincipalOnlyPayments(i.Year, i.Month, i.Day) .Sum(); if (extraPayment != 0) { extraPayment = extraPayment > balance ? balance : extraPayment; yield return(new Payment(mortgage, i, balance, 0, extraPayment)); balance -= extraPayment; } } }
private static IMortgage ConvertToInsuredMortgageIfInsurable(IMortgage mortgage, decimal downPayment) { var downPaymentRate = downPayment / (mortgage.InitialValue + downPayment); var insuranceTypeRequired = InsuredMortgage.IsInsurable(downPaymentRate); switch (insuranceTypeRequired) { case InsuranceTypes.DownPaymentLow: throw new InvalidDownPaymentRateException(downPaymentRate); case InsuranceTypes.Insurable: return(new InsuredMortgage(mortgage, downPayment)); case InsuranceTypes.NotRequired: default: return(mortgage); } }
public IEnumerable <Payment> GetMonthlyPayments(IMortgage mortgage) { return(GetMonthlyPayments(mortgage, DateTime.MaxValue)); }
public PrepayableMortgageBuilder(IMortgage baseMortgage, decimal maximumAllowedPrepaymentPercentage = 0.10M) { Mortgage = baseMortgage; MaximumAllowedPrepaymentPercentage = maximumAllowedPrepaymentPercentage; }
public PrepayableMortgage(IMortgage baseMortgage, decimal maximumAllowedPrepaymentPercentage = 0.10M) { BaseMortgage = baseMortgage; Calculator = new MonthlyPaymentCalculator(); Prepayments = new CappedPayments(InitialValue * maximumAllowedPrepaymentPercentage); }