Esempio n. 1
0
        ///<summary>
        ///</summary>
        ///<param name="termsRange"></param>
        ///<param name="metaScheduleDefinitionRange"></param>
        ///<param name="paymentCalendar"></param>
        ///<returns></returns>
        public static List <AmortResultItem> 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 <AmortResultItem>();

            for (int i = 0; i < adjustedDatesResult.Count; i++)
            {
                DateTime adjustedTime    = adjustedDatesResult[i];
                DateTime unadjustedTime  = unadjustedDatesResult[i];
                var      amortResultItem = new AmortResultItem
                {
                    WasRolled        = (adjustedTime == unadjustedTime) ? "No" : "Yes",
                    RollDate         = adjustedTime,
                    AmortAmount      = 0,
                    OutstandingValue = termsRange.FaceValue
                };
                result.Add(amortResultItem);
            }
            return(result);
        }
Esempio n. 2
0
        public static List <AmortResultItem> GetAmortizationSchedule(List <Pair <DateTime, string> > rollDates, double initialNotional, List <AmortScheduleItem> amortSchedule)
        {
            var result = rollDates.Select(pair => new AmortResultItem
            {
                RollDate = pair.First, WasRolled = pair.Second, OutstandingValue = initialNotional
            }).ToList();
            double currentNotional = initialNotional;

            foreach (AmortScheduleItem amortScheduleItem in amortSchedule)
            {
                DateTime startDate = amortScheduleItem.StartDate;
                DateTime endDate   = amortScheduleItem.EndDate;
                IEnumerable <DateTime> rollDatesForItem = GetRollsForSchedule(rollDates, startDate, endDate);
                int cashflowNumber = 0;
                foreach (DateTime time in rollDatesForItem)
                {
                    if (cashflowNumber % amortScheduleItem.ApplyEveryNthRoll == 0)
                    {
                        //  implement AS EVERY 1ST ROLL (amortScheduleItem.ApplyEveryNthRoll)
                        //
                        AmortResultItem amortResultItem = GetItem(result, time);
                        amortResultItem.AmortAmount      = amortScheduleItem.AmortAmount;
                        amortResultItem.OutstandingValue = currentNotional + amortResultItem.AmortAmount;
                        currentNotional = amortResultItem.OutstandingValue;
                    }
                    ++cashflowNumber;
                }
            }
            //  normalize notionals
            //
            for (int i = 0; i < result.Count; ++i)
            {
                AmortResultItem currentItem = result[i];
                if (currentItem.AmortAmount == 0 && i > 0)
                {
                    AmortResultItem prevItem = result[i - 1];
                    currentItem.OutstandingValue = prevItem.OutstandingValue;
                }
            }
            return(result);
        }