/// <summary> /// Gets a dates schedule. /// </summary> /// <param name="metaScheduleDefinitionRange">This must have 3 columns: interval, interval, rollconventionenum.</param> /// <param name="startDate">The start date of the schedule to be generated.</param> /// <param name="calendar">The relevant calendar.</param> /// <param name="businessDayAdjustment">The business day adjustments.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] GetMetaDatesSchedule(Excel.Range metaScheduleDefinitionRange, DateTime startDate, string calendar, string businessDayAdjustment) { var values = metaScheduleDefinitionRange.Value[System.Reflection.Missing.Value] as object[, ]; List <ThreeStringsRangeItem> metaScheduleDefinition = ObjectToArrayOfPropertiesConverter.CreateListFromHorizontalArrayRange <ThreeStringsRangeItem>(values); BusinessCenters centers = BusinessCentersHelper.Parse(calendar); IBusinessCalendar businessCalendar = Engine.ToBusinessCalendar(centers); var metaSchedule = AdjustedDatesMetaSchedule.GetMetaDatesSchedule(metaScheduleDefinition, startDate, businessCalendar, calendar, businessDayAdjustment); var result = RangeHelper.ConvertArrayToRange(metaSchedule); return(result); }
///<summary> ///</summary> ///<param name="termsRange"></param> ///<param name="metaScheduleDefinitionRange"></param> ///<param name="paymentCalendar"></param> ///<returns></returns> public static List <AmortisingResultItem> GenerateCashflowSchedule(BillsSwapPricer2TermsRange termsRange, List <MetaScheduleRangeItem> metaScheduleDefinitionRange, IBusinessCalendar paymentCalendar) { RollConventionEnum rollConventionEnum = RollConventionEnumHelper.Parse(termsRange.RollDay); BusinessDayAdjustments businessDayAdjustments = BusinessDayAdjustmentsHelper.Create(termsRange.DateRollConvention, termsRange.Calendar); bool backwardGeneration = (termsRange.BuildDates.ToLower() == "backward"); List <DateTime> adjustedDatesResult; List <DateTime> unadjustedDatesResult; if (termsRange.RollFrequency.ToLower().Contains("custom")) { var rollsMetaSchedule = metaScheduleDefinitionRange.Select(item => new MetaScheduleItem { RollFrequency = PeriodHelper.Parse(item.RollFrequency), Period = PeriodHelper.Parse(item.Period), RollConvention = RollConventionEnumHelper.Parse(item.RollConvention) }).ToList(); unadjustedDatesResult = DatesMetaSchedule.GetUnadjustedDates3(termsRange.StartDate, termsRange.EndDate, rollsMetaSchedule, backwardGeneration); adjustedDatesResult = AdjustedDatesMetaSchedule.GetAdjustedDates3(termsRange.StartDate, termsRange.EndDate, rollsMetaSchedule, backwardGeneration, businessDayAdjustments, paymentCalendar); } else { Period interval = PeriodHelper.Parse(termsRange.RollFrequency); unadjustedDatesResult = DatesMetaSchedule.GetUnadjustedDates2(termsRange.StartDate, termsRange.EndDate, interval, rollConventionEnum, backwardGeneration); adjustedDatesResult = AdjustedDatesMetaSchedule.GetAdjustedDates2(termsRange.StartDate, termsRange.EndDate, interval, rollConventionEnum, backwardGeneration, businessDayAdjustments, paymentCalendar); } var result = new List <AmortisingResultItem>(); for (int i = 0; i < adjustedDatesResult.Count; i++) { DateTime adjustedTime = adjustedDatesResult[i]; DateTime unadjustedTime = unadjustedDatesResult[i]; var amortisingResultItem = new AmortisingResultItem { WasRolled = (adjustedTime == unadjustedTime) ? "No" : "Yes", RollDate = adjustedTime, AmortisingAmount = 0, OutstandingValue = termsRange.FaceValue }; result.Add(amortisingResultItem); } return(result); }