コード例 #1
0
        /// <summary>
        /// Gets the payment number date.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="paymentNumber">The payment number.</param>
        /// <param name="frequency">The frequency.</param>
        /// <param name="country">The country.</param>
        public DateTime GetPaymentNumberDate(DateTime startDate,
            int paymentNumber,
            AmortizationPaymentFrequencyType frequency,
            Country country)
        {
            /* Date to return */
            DateTime? paymentDate = null;

            IList<AmortizationEntry> entries = new List<AmortizationEntry> ();

            /* Perform calculations for all payments before the
            * requested payment in case there was days shifted
            * before the paymentNumber required */
            for (int i = 1; i <= paymentNumber; i++)
            {
                paymentDate = GetPaymentDate (startDate, frequency, i);
                AmortizationEntry entry = new AmortizationEntry ();
                entry.Number = i;
                entry.Date = Convert.ToDateTime (paymentDate);
                entries.Add (entry);
            }

            AmortizationTable amortTable = new AmortizationTable (entries);

            /* Now verify all dates are working days */
            VerifyWorkingDates (amortTable, country);

            /* Now get the the actual date */
            foreach (AmortizationEntry entry in amortTable)
            {
                if (entry.Number == paymentNumber)
                {
                    paymentDate = entry.Date;
                    break;
                }
            }

            return Convert.ToDateTime (paymentDate);
        }
コード例 #2
0
        /// <summary>
        /// Calculates an Amortization Table using a Flat Interest approach
        /// </summary>
        /// <returns>Flat Interest Amortization Table</returns>
        protected override AmortizationTable CalculateSpecificAmortizationTable()
        {
            //Stores all the table entries in a list form.
            //Each item in this list will contain all the columns that the amortization
            //table has.
            IList<AmortizationEntry> amortizationEntries = new List<AmortizationEntry> ();

            //Local variables used to store each payments
            //calculated values
            decimal interestPayment = 0.0000m;
            decimal principalPayment = 0.0000m;
            decimal principalBalance = 0.0000m;
            decimal taxPayment = 0.0000m;

            for (int i = 0; i < base.NumberOfPayments; i++)
            {
                //First Payment is of the total amount of the loan
                if (i == 0)
                {
                    //Calculates the amounts
                    if (base.GracePeriod - 1 >= i) //While there is a grace period,
                    {							   //only interests are paid
                        principalPayment = 0;
                        interestPayment = base.CalculationInterest * base.Amount;
                        taxPayment = interestPayment * base.Tax;
                    }
                    else
                    {
                        principalPayment = base.Amount / (base.NumberOfPayments - base.GracePeriod);
                        interestPayment = base.CalculationInterest * base.Amount;
                        taxPayment = interestPayment * base.Tax;
                    }

                    principalBalance = base.Amount - principalPayment;

                    AmortizationEntry newAmortizationTableEntry = new AmortizationEntry ();

                    newAmortizationTableEntry.Number = i + 1;
                    newAmortizationTableEntry.Principal = principalPayment;
                    newAmortizationTableEntry.Interest = interestPayment;
                    newAmortizationTableEntry.Tax = taxPayment;
                    newAmortizationTableEntry.RemainingPrincipalBalance = principalBalance;

                    //Add the new entry to the table.
                    amortizationEntries.Add (newAmortizationTableEntry);
                }
                else //All other payments
                {
                    //Retrieve the previous entry in the table.
                    AmortizationEntry previousTableEntry = amortizationEntries[i - 1];

                    //Calculates the amounts
                    if (base.GracePeriod - 1 >= i)  //While there is a grace period,
                    {								//only interests are paid
                        principalPayment = 0;
                        interestPayment = base.CalculationInterest * base.Amount;
                        taxPayment = interestPayment * base.Tax;
                    }
                    else
                    {
                        principalPayment = base.Amount / (base.NumberOfPayments - base.GracePeriod);
                        interestPayment = base.CalculationInterest * base.Amount;
                        taxPayment = interestPayment * base.Tax;
                    }

                    principalBalance
                    = previousTableEntry.RemainingPrincipalBalance - principalPayment;

                    AmortizationEntry newAmortizationTableEntry = new AmortizationEntry ();

                    newAmortizationTableEntry.Number = i + 1;
                    newAmortizationTableEntry.Principal = principalPayment;
                    newAmortizationTableEntry.Interest = interestPayment;
                    newAmortizationTableEntry.Tax = taxPayment;
                    newAmortizationTableEntry.RemainingPrincipalBalance = principalBalance;

                    //Add the new entry to the table.
                    amortizationEntries.Add (newAmortizationTableEntry);
                }
            }

            //Create table and return it based on the calculated entries.
            AmortizationTable amortizationTable = new AmortizationTable (amortizationEntries);
            return amortizationTable;
        }
コード例 #3
0
ファイル: LoanStatementCalc.cs プロジェクト: zibler/zibler
        /// <summary>
        /// Recalculates the interest and vat for an amortization
        /// no matter what type of amortization table was used. The calculation
        /// is done as a simple multiplication, using the values applicable
        /// to the date of the amortization
        /// </summary>
        /// <param name="amrtztn">Amortization to be calculated</param>
        private void RecalculateInterestAndVAT(AmortizationEntry amrtztn)
        {
            try
            {
                /* Interest, and VAT search date */
                DateTime? searchDate = null;

                /* Use the statement date to calculate the interest since the date for the
                * amortization is in the future */
                bool useStmntDate =
                DateUtilities.IsFirstDateGreaterThanSecondDate (
                    amrtztn.Date,
                    Convert.ToDateTime (_stmntDate));

                if (useStmntDate)
                    searchDate = _stmntDate;
                else
                    searchDate = amrtztn.Date;

                /* Determine the interest rate and Vat rate values to use */
                decimal intrstRtVl = GetInterestRateValue (Convert.ToDateTime (searchDate));
                decimal vatValue = GetVATValue (Convert.ToDateTime (searchDate));
                decimal grssErngsMrgn = _loan.GrossEarningsMargin;

                /* Add the gross earnings margin */
                intrstRtVl = intrstRtVl + grssErngsMrgn;

                /* Recalculate the interest and tax for that amortization */
                _amortization.RecalculateAmortization (amrtztn.Number, intrstRtVl, vatValue);
            }
            /* If the exception was thrown here, just pass it up */
            catch (ZiblerBusinessComponentsException ex)
            {
                throw;
            }
            /* Catch any Data Layer or other exception and throw an unkown exception */
            catch (Exception ex)
            {
                ZiblerBusinessComponentsUnknownException exc
                = new ZiblerBusinessComponentsUnknownException (ex);

                /* Throw the new exception */
                throw exc;
            }
        }