public void testThirty360_EurobondBasis() { // Testing thirty/360 day counter (Eurobond Basis) // Source: ISDA 2006 Definitions 4.16 (g) // 30E/360 (or Eurobond Basis) // Based on ICMA (Rule 251) and FBF; this is the version of 30E/360 used by Excel DayCounter dayCounter = new Thirty360(Thirty360.Thirty360Convention.EurobondBasis); List <Date> testStartDates = new List <Date>(); List <Date> testEndDates = new List <Date>(); int calculated; // ISDA - Example 1: End dates do not involve the last day of February testStartDates.Add(new Date(20, Month.August, 2006)); testEndDates.Add(new Date(20, Month.February, 2007)); testStartDates.Add(new Date(20, Month.February, 2007)); testEndDates.Add(new Date(20, Month.August, 2007)); testStartDates.Add(new Date(20, Month.August, 2007)); testEndDates.Add(new Date(20, Month.February, 2008)); testStartDates.Add(new Date(20, Month.February, 2008)); testEndDates.Add(new Date(20, Month.August, 2008)); testStartDates.Add(new Date(20, Month.August, 2008)); testEndDates.Add(new Date(20, Month.February, 2009)); testStartDates.Add(new Date(20, Month.February, 2009)); testEndDates.Add(new Date(20, Month.August, 2009)); //// ISDA - Example 2: End dates include some end-February dates testStartDates.Add(new Date(28, Month.February, 2006)); testEndDates.Add(new Date(31, Month.August, 2006)); testStartDates.Add(new Date(31, Month.August, 2006)); testEndDates.Add(new Date(28, Month.February, 2007)); testStartDates.Add(new Date(28, Month.February, 2007)); testEndDates.Add(new Date(31, Month.August, 2007)); testStartDates.Add(new Date(31, Month.August, 2007)); testEndDates.Add(new Date(29, Month.February, 2008)); testStartDates.Add(new Date(29, Month.February, 2008)); testEndDates.Add(new Date(31, Month.August, 2008)); testStartDates.Add(new Date(31, Month.August, 2008)); testEndDates.Add(new Date(28, Month.Feb, 2009)); testStartDates.Add(new Date(28, Month.February, 2009)); testEndDates.Add(new Date(31, Month.August, 2009)); testStartDates.Add(new Date(31, Month.August, 2009)); testEndDates.Add(new Date(28, Month.Feb, 2010)); testStartDates.Add(new Date(28, Month.February, 2010)); testEndDates.Add(new Date(31, Month.August, 2010)); testStartDates.Add(new Date(31, Month.August, 2010)); testEndDates.Add(new Date(28, Month.Feb, 2011)); testStartDates.Add(new Date(28, Month.February, 2011)); testEndDates.Add(new Date(31, Month.August, 2011)); testStartDates.Add(new Date(31, Month.August, 2011)); testEndDates.Add(new Date(29, Month.Feb, 2012)); //// ISDA - Example 3: Miscellaneous calculations testStartDates.Add(new Date(31, Month.January, 2006)); testEndDates.Add(new Date(28, Month.February, 2006)); testStartDates.Add(new Date(30, Month.January, 2006)); testEndDates.Add(new Date(28, Month.February, 2006)); testStartDates.Add(new Date(28, Month.February, 2006)); testEndDates.Add(new Date(3, Month.March, 2006)); testStartDates.Add(new Date(14, Month.February, 2006)); testEndDates.Add(new Date(28, Month.February, 2006)); testStartDates.Add(new Date(30, Month.September, 2006)); testEndDates.Add(new Date(31, Month.October, 2006)); testStartDates.Add(new Date(31, Month.October, 2006)); testEndDates.Add(new Date(28, Month.November, 2006)); testStartDates.Add(new Date(31, Month.August, 2007)); testEndDates.Add(new Date(28, Month.February, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(28, Month.August, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(30, Month.August, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(31, Month.August, 2008)); testStartDates.Add(new Date(26, Month.February, 2007)); testEndDates.Add(new Date(28, Month.February, 2008)); testStartDates.Add(new Date(26, Month.February, 2007)); testEndDates.Add(new Date(29, Month.February, 2008)); testStartDates.Add(new Date(29, Month.February, 2008)); testEndDates.Add(new Date(28, Month.February, 2009)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(30, Month.March, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(31, Month.March, 2008)); int[] expected = { 180, 180, 180, 180, 180, 180, 182, 178, 182, 179, 181, 178, 182, 178, 182, 178, 182, 179, 28, 28, 5, 14, 30, 28, 178, 180, 182, 182, 362, 363, 359, 32, 32 }; for (int i = 0; i < testStartDates.Count; i++) { calculated = dayCounter.dayCount(testStartDates[i], testEndDates[i]); if (calculated != expected[i]) { QAssert.Fail("from " + testStartDates[i] + " to " + testEndDates[i] + ":\n" + " calculated: " + calculated + "\n" + " expected: " + expected[i]); } } }
public void testThirty360_BondBasis() { // Testing thirty/360 day counter (Bond Basis) // http://www.isda.org/c_and_a/docs/30-360-2006ISDADefs.xls // Source: 2006 ISDA Definitions, Sec. 4.16 (f) // 30/360 (or Bond Basis) DayCounter dayCounter = new Thirty360(Thirty360.Thirty360Convention.BondBasis); List <Date> testStartDates = new List <Date>(); List <Date> testEndDates = new List <Date>(); int calculated; // ISDA - Example 1: End dates do not involve the last day of February testStartDates.Add(new Date(20, Month.August, 2006)); testEndDates.Add(new Date(20, Month.February, 2007)); testStartDates.Add(new Date(20, Month.February, 2007)); testEndDates.Add(new Date(20, Month.August, 2007)); testStartDates.Add(new Date(20, Month.August, 2007)); testEndDates.Add(new Date(20, Month.February, 2008)); testStartDates.Add(new Date(20, Month.February, 2008)); testEndDates.Add(new Date(20, Month.August, 2008)); testStartDates.Add(new Date(20, Month.August, 2008)); testEndDates.Add(new Date(20, Month.February, 2009)); testStartDates.Add(new Date(20, Month.February, 2009)); testEndDates.Add(new Date(20, Month.August, 2009)); // ISDA - Example 2: End dates include some end-February dates testStartDates.Add(new Date(31, Month.August, 2006)); testEndDates.Add(new Date(28, Month.February, 2007)); testStartDates.Add(new Date(28, Month.February, 2007)); testEndDates.Add(new Date(31, Month.August, 2007)); testStartDates.Add(new Date(31, Month.August, 2007)); testEndDates.Add(new Date(29, Month.February, 2008)); testStartDates.Add(new Date(29, Month.February, 2008)); testEndDates.Add(new Date(31, Month.August, 2008)); testStartDates.Add(new Date(31, Month.August, 2008)); testEndDates.Add(new Date(28, Month.February, 2009)); testStartDates.Add(new Date(28, Month.February, 2009)); testEndDates.Add(new Date(31, Month.August, 2009)); //// ISDA - Example 3: Miscellaneous calculations testStartDates.Add(new Date(31, Month.January, 2006)); testEndDates.Add(new Date(28, Month.February, 2006)); testStartDates.Add(new Date(30, Month.January, 2006)); testEndDates.Add(new Date(28, Month.February, 2006)); testStartDates.Add(new Date(28, Month.February, 2006)); testEndDates.Add(new Date(3, Month.March, 2006)); testStartDates.Add(new Date(14, Month.February, 2006)); testEndDates.Add(new Date(28, Month.February, 2006)); testStartDates.Add(new Date(30, Month.September, 2006)); testEndDates.Add(new Date(31, Month.October, 2006)); testStartDates.Add(new Date(31, Month.October, 2006)); testEndDates.Add(new Date(28, Month.November, 2006)); testStartDates.Add(new Date(31, Month.August, 2007)); testEndDates.Add(new Date(28, Month.February, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(28, Month.August, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(30, Month.August, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(31, Month.August, 2008)); testStartDates.Add(new Date(26, Month.February, 2007)); testEndDates.Add(new Date(28, Month.February, 2008)); testStartDates.Add(new Date(26, Month.February, 2007)); testEndDates.Add(new Date(29, Month.February, 2008)); testStartDates.Add(new Date(29, Month.February, 2008)); testEndDates.Add(new Date(28, Month.February, 2009)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(30, Month.March, 2008)); testStartDates.Add(new Date(28, Month.February, 2008)); testEndDates.Add(new Date(31, Month.March, 2008)); int[] expected = { 180, 180, 180, 180, 180, 180, 178, 183, 179, 182, 178, 183, 28, 28, 5, 14, 30, 28, 178, 180, 182, 183, 362, 363, 359, 32, 33 }; for (int i = 0; i < testStartDates.Count; i++) { calculated = dayCounter.dayCount(testStartDates[i], testEndDates[i]); if (calculated != expected[i]) { QAssert.Fail("from " + testStartDates[i] + " to " + testEndDates[i] + ":\n" + " calculated: " + calculated + "\n" + " expected: " + expected[i]); } } }