public static DateTime Add(DateTime dateTime, Period periodToAdd)
 {
     if (periodToAdd == null)
     {
         throw new ArgumentNullException("periodToAdd");
     }
     return(periodToAdd.Add(dateTime));
 }
Exemple #2
0
        /// <summary>
        /// Gets the first regular period start date.
        /// </summary>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <param name="startDate">The start date.</param>
        /// <returns></returns>
        public static DateTime GetFirstRegularPeriodStartDate(Period periodInterval, RollConventionEnum rollConvention, DateTime startDate)
        {
            DateTime advDate = periodInterval.Add(startDate);
            DateTime regularPeriodStartDate = advDate;

            if (rollConvention != RollConventionEnum.NONE)
            {
                regularPeriodStartDate = RollConventionEnumHelper.AdjustDate(rollConvention, advDate);
            }
            return(regularPeriodStartDate);
        }
Exemple #3
0
        /// <summary>
        /// Gets the last regular period end date.
        /// </summary>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <param name="endDate">The end date.</param>
        /// <returns></returns>
        public static DateTime GetLastRegularPeriodEndDate(Period periodInterval, RollConventionEnum rollConvention, DateTime endDate)
        {
            int periodMultiplierAsInt = int.Parse(periodInterval.periodMultiplier);

            if (periodMultiplierAsInt > 0)
            {
                periodMultiplierAsInt = periodMultiplierAsInt * -1;
            }

            periodInterval.periodMultiplier = periodMultiplierAsInt.ToString();

            DateTime advDate = periodInterval.Add(endDate);

            DateTime regularPeriodEndDate = advDate;

            if (rollConvention != RollConventionEnum.NONE)
            {
                regularPeriodEndDate = RollConventionEnumHelper.AdjustDate(rollConvention, advDate);
            }
            return(regularPeriodEndDate);
        }
Exemple #4
0
        /// <summary>
        /// Generates the unadjusted calculation dates.
        /// </summary>
        /// <param name="effectiveDate">The effective date.</param>
        /// <param name="intervalToTerminationDate">The interval to termination date.</param>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <returns></returns>
        static public List <CalculationPeriod> GenerateUnadjustedCalculationDates(DateTime effectiveDate, Period intervalToTerminationDate, Period periodInterval, RollConventionEnum rollConvention)
        {
            DateTime startDate = effectiveDate;

            // Adjust the effective date
            if (rollConvention != RollConventionEnum.NONE)
            {
                startDate = RollConventionEnumHelper.AdjustDate(rollConvention, effectiveDate);
            }

            Double divisor = IntervalHelper.Div(intervalToTerminationDate, periodInterval);

            // The divisor has to be a whole number (i.e. the period must roll to the term date interval
            if ((divisor % 1) != 0)
            {
                throw new ArithmeticException("The period frequency will not roll to the supplied termination date interval");
            }

            DateTime           terminationDate = intervalToTerminationDate.Add(startDate);
            StubPeriodTypeEnum?stubPeriodType  = null;

            return(GenerateUnadjustedCalculationDates(startDate, terminationDate, effectiveDate, periodInterval, rollConvention, stubPeriodType));
        }