private void GenerateSchedule(DateTime asOf, DateTime startDate, DateTime endDate, DayCount dayCount, DayRule dayRule, CurveTenor tenor, StubPlacement stub = StubPlacement.NullStub) { // This only works for short stubs atm, although NullStub will generate a long stub DateTime AdjStart = DateHandling.AdjustDate(startDate, dayRule); DateTime AdjEnd = DateHandling.AdjustDate(endDate, dayRule); string tenorString = EnumToStr.CurveTenor(tenor); string TenorLetter = DateHandling.GetTenorLetterFromTenor(tenorString); double TenorNumber = DateHandling.GetTenorNumberFromTenor(tenorString); int periods = CalculatePeriods(startDate, endDate, tenor); // Create estimate of how long the schedule should be //double YearsUpper = DateHandling.Cvg(AdjStart, AdjEnd, dayCount); //double YearLower = DateHandling.Cvg(AsOf, AdjStart, dayCount); // Will be sorted at end (when coverages are also calculated) UnAdjStartDates.Add(StartDate); UnAdjEndDates.Add(EndDate); AdjStartDates.Add(AdjStart); AdjEndDates.Add(AdjEnd); //if (StrToEnum.ConvertTenorLetter(TenorLetter) == Tenor.M) //{ // periods = periodsInMonths / (int)TenorNumber; // //WholePeriods = periodsInMonths / (int) TenorNumber; // //double tempPeriods = YearsUpper * 12 / TenorNumber; // //WholePeriods = (int)Math.Truncate(tempPeriods); //} //else if (StrToEnum.ConvertTenorLetter(TenorLetter) == Tenor.Y) //{ // periods = periodsInMonths / (12 * (int)TenorNumber); // //WholePeriods = (int) Math.Truncate(YearsUpper); //} //else //{ // throw new ArgumentException("Can only roll out swap calender for month and year tenors"); //} if (stub == StubPlacement.Beginning) { periods += 1 * 12 / (int)Math.Round(TenorNumber); for (int i = 1; i < periods; i++) { UnAdjEndDates.Add(DateHandling.AddTenorAdjust(UnAdjEndDates[i - 1], "-" + tenorString)); AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[i], DayRule)); UnAdjStartDates.Add(UnAdjEndDates[i]); AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[i], DayRule)); } } else if (stub == StubPlacement.End) { periods += 1 * 12 / (int)Math.Round(TenorNumber); for (int i = 1; i < periods; i++) { UnAdjStartDates.Add(DateHandling.AddTenorAdjust(UnAdjStartDates[i - 1], tenorString)); AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[i], DayRule)); UnAdjEndDates.Add(UnAdjStartDates[i]); AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[i], DayRule)); } } else if (stub == StubPlacement.NullStub) { for (int i = 1; i < periods; i++) { UnAdjEndDates.Add(DateHandling.AddTenorAdjust(UnAdjEndDates[i - 1], "-" + tenorString)); AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[i], DayRule)); UnAdjStartDates.Add(UnAdjEndDates[i]); AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[i], DayRule)); } } // Sort dates according to date UnAdjStartDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y))); UnAdjEndDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y))); AdjStartDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y))); AdjEndDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y))); for (int i = 0; i < AdjStartDates.Count; i++) { Coverages.Add(DateHandling.Cvg(AdjStartDates[i], AdjEndDates[i], DayCount)); } }
private void ConstructZcbCurveFromDatesAndValues() { _tenorStr = EnumToStr.CurveTenor(Tenor); _zcbCurve = new MasterThesis.Curve(Dates, _zcbValues); }