コード例 #1
0
ファイル: Home.cs プロジェクト: ofer987/Financier
 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;
 }
コード例 #2
0
ファイル: Payment.cs プロジェクト: ofer987/Financier
        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);
        }
コード例 #3
0
ファイル: InsuredMortgage.cs プロジェクト: ofer987/Financier
        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);
        }
コード例 #4
0
        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;
                }
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
 public IEnumerable <Payment> GetMonthlyPayments(IMortgage mortgage)
 {
     return(GetMonthlyPayments(mortgage, DateTime.MaxValue));
 }
コード例 #7
0
 public PrepayableMortgageBuilder(IMortgage baseMortgage, decimal maximumAllowedPrepaymentPercentage = 0.10M)
 {
     Mortgage = baseMortgage;
     MaximumAllowedPrepaymentPercentage = maximumAllowedPrepaymentPercentage;
 }
コード例 #8
0
 public PrepayableMortgage(IMortgage baseMortgage, decimal maximumAllowedPrepaymentPercentage = 0.10M)
 {
     BaseMortgage = baseMortgage;
     Calculator   = new MonthlyPaymentCalculator();
     Prepayments  = new CappedPayments(InitialValue * maximumAllowedPrepaymentPercentage);
 }