/// <summary>
 /// The number of periods per year for a given UnitPeriod
 /// </summary>
 internal static double PeriodsPerYear(UnitPeriod period)
 {
     return(period.periodType switch
     {
         UnitPeriodType.Monthly => Convert.ToDouble(12d / period.numPeriods),
         UnitPeriodType.Weekly => Convert.ToDouble(52d / period.numPeriods),
         UnitPeriodType.Yearly => 1d,//The maximum UnitPeriod is 1 year, so this is always 1 (as opposed to say .5 for a 2 year common period)
         UnitPeriodType.Daily => Convert.ToDouble(365d / period.numPeriods),
         _ => throw new ApplicationException("Invalid Unit Period Type passed into DaysPerPeriod"),
     });
Beispiel #2
0
        /// <summary>
        /// Finished Adding Line Items, must be used prior to adding to APR
        /// </summary>
        public void MarkComplete()
        {
            this.Sort();

            //And now we calculate the Unit Period
            this.m_CommonPeriod   = DateTimeCalculations.CalculateCommonPeriod(this);
            this.m_DaysPerPeriod  = DateTimeCalculations.DaysPerPeriod(this.m_CommonPeriod);
            this.m_PeriodsPerYear = DateTimeCalculations.PeriodsPerYear(this.m_CommonPeriod);

            //Mark all line items as complete
            for (int i = 0; i < this.m_Items.Count; i++)
            {
                LineItem li = (LineItem)this.m_Items[i];
                li.Complete();
            }

            m_Completed = true;
        }
        internal static double GetPVIFA(DateTime StartDate, DateTime CurrLIDate, UnitPeriod frequency, double APR, double PeriodsPerYear, double DaysPerPeriod, int NumberOccurrences, UnitPeriod CommonPeriod)
        {
            StringBuilder sb    = new StringBuilder();
            int           ic    = 1;
            double        pvifa = 0.0d; //return value, running tally of PVIF
            PeriodSpan    lastSpan;
            PeriodSpan    currSpan = DateTimeCalculations.GetNumberPeriods(StartDate, CurrLIDate, CommonPeriod);

            lastSpan.OddDays = 0;
            lastSpan.Periods = 0;
            for (int i = 0; i < NumberOccurrences; i++)
            {
                //get the PVIF for this current item and add to the pvifa
                pvifa += GetPVIF(currSpan, APR, PeriodsPerYear, DaysPerPeriod);
                sb.AppendLine(ic.ToString() + "   " + CurrLIDate.ToString() + "    " + currSpan.Periods.ToString() + currSpan.OddDays.ToString() + "    " + pvifa.ToString());
                //TODO... figure out how to determine the recurrence in periods if
                //periods other than a monthly type or annual are passed in.
                //Perhaps we should restrict to only dates instead?
                lastSpan   = currSpan;
                CurrLIDate = DateTimeCalculations.AddPeriodToDate(CurrLIDate, frequency);
                currSpan   = DateTimeCalculations.GetNumberPeriods(StartDate, CurrLIDate, CommonPeriod);
            }
            return(pvifa);
        }
        /// <summary>
        /// Gets a Date based on a given period in the Loan Lifecycle.
        /// </summary>
        internal static DateTime GetDateFromPeriod(PeriodSpan Span, DateTime StartDate, UnitPeriod CommonPeriod)
        {
            DateTime dtReturn;

            try
            {
                if (CommonPeriod.periodType == UnitPeriodType.Monthly)
                {
                    dtReturn = StartDate.AddMonths(CommonPeriod.numPeriods * Span.Periods).AddDays(Span.OddDays);
                }
                else if (CommonPeriod.periodType == UnitPeriodType.Yearly)
                {
                    dtReturn = StartDate.AddYears(CommonPeriod.numPeriods * Span.Periods).AddDays(Span.OddDays);
                }
                else if (CommonPeriod.periodType == UnitPeriodType.Weekly)
                {
                    dtReturn = StartDate.AddDays(CommonPeriod.numPeriods * Span.Periods * 7).AddDays(Span.OddDays);
                }
                else
                {
                    dtReturn = StartDate.AddDays(CommonPeriod.numPeriods * Span.Periods);
                }
                return(dtReturn);
            }
            catch (Exception ex)
            {
                ApplicationException newex = new ApplicationException("Exception in DateTimeCalculations.GetDateFromPeriod", ex);
                throw(newex);
            }
        }