public static void Example4() { DateTime startDate = new Date(2009, 8, 3).DateValue; DateTime endDate = new Date(2014, 10, 3).DateValue; // Now test with bool as well bool adjusted = true; int paymentPerYear = 2; bool arrears = false; int fixingDays = -2; bool shortPeriod = true; DateSchedule myDL_1 = new DateSchedule(startDate, endDate, paymentPerYear, shortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("Marix<Date> GetLongScheduleDate()"); myDL_1.PrintDateMatrix(myDL_1.GetLongScheduleDate()); Console.WriteLine(); Console.WriteLine("Matrix<double> GetLongScheduleSerial()"); myDL_1.GetLongScheduleSerial().extendedPrint(); Console.WriteLine(); Console.WriteLine("Marix<Date> GetShortScheduleDate()"); myDL_1.PrintDateMatrix(myDL_1.GetShortScheduleDate()); Console.WriteLine(); Console.WriteLine("Array<Date>PaymentDateArray()"); myDL_1.PrintDateArray(myDL_1.PaymentDateArray()); Console.WriteLine(); Console.WriteLine("count numbers of rows: public int Length " + myDL_1.Length); }
} // std convention // Copy Constructor public DateSchedule(DateSchedule my_dateListo) { this.adjusted = my_dateListo.adjusted; this.arrears = my_dateListo.arrears; this.fixingDays = my_dateListo.fixingDays; this.firstShortPeriod = my_dateListo.firstShortPeriod; this.my_DateArray = my_dateListo.my_DateArray; this.my_DateArrayAdjusted = my_dateListo.my_DateArrayAdjusted; }
public static void Example8() { // DateSchedule. The output of is a matrix of dates, for scheduled payments period, each rows is a period // for columns: // 1° column fixing date // 2° column startingDate of period // 3° column endDate of period // 4° column payment date of period DateTime startDate = new Date(2009, 8, 3).DateValue; DateTime endDate = new Date(2014, 10, 3).DateValue; bool adjusted = true; int paymentPerYear = 2; bool arrears = false; int fixingDays = -2; bool firstShortPeriod = true; DateSchedule myDL_1 = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("Starting DateSchedule"); myDL_1.PrintDateMatrix(); Console.WriteLine(); adjusted = false; DateSchedule myDL_2 = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("adjusted = 0, 3° column can be Sat or Sun"); myDL_2.PrintDateMatrix(); Console.WriteLine(); paymentPerYear = 1; DateSchedule myDL_3 = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("paymentPerYear = 1, frequency of payment changed"); myDL_3.PrintDateMatrix(); Console.WriteLine(); arrears = true; DateSchedule myDL_4 = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("arrears = 1, 1° column count fixing date starting from 3° column and not from 2° column"); myDL_4.PrintDateMatrix(); Console.WriteLine(); fixingDays = 0; DateSchedule myDL_5 = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("fixingDays = 0, 1° column has a different leg"); myDL_5.PrintDateMatrix(); Console.WriteLine(); firstShortPeriod = false; DateSchedule myDL_6 = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod, adjusted, arrears, fixingDays); Console.WriteLine("shortPeriod = 2, changed the short period"); myDL_6.PrintDateMatrix(); Console.WriteLine(); }
public void dateAndMonthExtracter() { String[] dates = DateSchedule.Split(' '); String[] arraynew = { "0", "0", "0" }; int c = 0; foreach (String words in dates) { arraynew[c] = words; Console.WriteLine(arraynew[c]); c++; } DateNumber = arraynew[0]; }
public static void Example10() { // I will pay 5% quarterly 30/360 for 5y starting from 5 Oct 09 on a nominal of 1.000.000 USD. I want to see // interest rates cash flows // input data Date startDate = new Date(2009, 10, 5); Date endDate = startDate.AddYears(5); int paymentPerYear = 4; // Quarterly bool firstShortPeriod = true; double rate = 0.05; // I use standard constructor DateSchedule myDS = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod); // I get start and end date schedule NumericMatrix <Date> myShortSchedule = myDS.GetShortScheduleDate(); // my nominals Array <double> nominals = new Array <double>(myShortSchedule.Rows, 0, 1000000); // year fraction from/to according 30/360 Array <double> yearFractions = new Array <double>(myShortSchedule.Rows, 0); // days from/to according 30/360 Array <double> days = new Array <double>(myShortSchedule.Rows, 0); // interest to pay Array <double> interest = new Array <double>(myShortSchedule.Rows, 0); Console.WriteLine("{0},\t{1},\t{2},\t{3},\t{4}", "days", "yearFrac", "rate", "nominals", "interest"); // running sum double totalInterest = 0.0; // iterate interest calculation using schedule for (int i = 0; i < myShortSchedule.Rows; i++) { yearFractions[i] = myShortSchedule[i, 0].YF_30_360(myShortSchedule[i, 1]); days[i] = myShortSchedule[i, 0].D_30_360(myShortSchedule[i, 1]); interest[i] = yearFractions[i] * rate * nominals[i]; Console.WriteLine("{0},\t{1:F5},\t{2:P},\t{3:C},\t{4:C}", days[i], yearFractions[i], rate, nominals[i], interest[i]); totalInterest += interest[i]; } Console.WriteLine("{0},\t{1:F2}", "Total interests: ", totalInterest); }
/// <summary>Creates a date schedule that contains the start and end dates of the interest periods of each caplets, i.e. T_0, T_1, T_2, ..., where [T_k; T_{k+1}] is the /// interest period of caplet k, k=0,...,n-1; The first caplet is already expired but it is part of the date schedule. /// </summary> /// <param name="referenceDate">The reference date, i.e. the trading date.</param> /// <param name="startDateAndEndDateDescription">A description of the start date of the first caplet as well as the end date of the last caplet, i.e. the start date and the maturity of the cap.</param> /// <param name="marketConventions">The market conventions.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <param name="underlyingLiborTenor">A mapping of the null-based index of the start date of each caplet interest period to the tenor of the underlying Libor rate (output).</param> /// <param name="logger">An optional logger.</param> /// <returns>The date schedule of the interest periods, i.e. the start and end dates of each caplet; thus T_0, T_1, T_2, ..., where [T_k; T_{k+1}] is the /// interest period of caplet k, k=0,...,n-1; The first caplet is already expired but it is part of the date schedule. /// </returns> public ReadOnlyDateSchedule CreateInterestPeriodDateSchedule(DateTime referenceDate, ITimeframeDescription startDateAndEndDateDescription, ReadOnlyMoneyMarketConventions marketConventions, IHolidayCalendar holidayCalendar, out Func <int, TenorTimeSpan> underlyingLiborTenor, ILogger logger = null) { if (marketConventions == null) { throw new ArgumentNullException("marketConventions"); } if (holidayCalendar == null) { throw new ArgumentNullException("holidayCalendar"); } DateSchedule dateSchedule = new DateSchedule(holidayCalendar, logger: logger); dateSchedule.Add(new ForwardDateScheduleRule(referenceDate, startDateAndEndDateDescription, m_LiborRateTenor, marketConventions.BusinessDayConvention)); underlyingLiborTenor = (i => m_LiborRateTenor.GetFrequencyTenor()); return(dateSchedule.AsReadOnly()); }
public static void Example5() { // 1. Create the date schedule data DateTime startDate = new Date(2009, 8, 3).DateValue; DateTime endDate = new Date(2014, 10, 3).DateValue; bool adjusted = true; int paymentPerYear = 2; bool arrears = false; int fixingDays = -2; bool shortPeriod = true; // 2. My date scheduled. DateSchedule myDL_1 = new DateSchedule(startDate, endDate, paymentPerYear, shortPeriod, adjusted, arrears, fixingDays); // 3. Init a NumericMatrix<double> Class from my dates. NumericMatrix <double> myDates = (NumericMatrix <double>) myDL_1.GetLongScheduleSerial(); // 4. Create an associative matrix AssocMatrix with "header" label // for columns and "n_lines" for rows 4A. Label for columns. Set <string> header = new Set <string>(); header.Insert("FixingDate"); header.Insert("StartDate"); header.Insert("EndDate"); header.Insert("PaymentDate"); // 4B. Label for rows Set <string> n_line = new Set <string>(); for (int i = 0; i < myDates.MaxRowIndex + 1; i++) { n_line.Insert("# " + (i + 1)); } // 5. Creating AssocMatrix. AssocMatrix <string, string, double> OutMatrix = new AssocMatrix <string, string, double>(n_line, header, myDates); // 6. Print associative matrices in Excel, to "My Date // List" sheet, the output in Excel serial number format. ExcelMechanisms exl = new ExcelMechanisms(); exl.printAssocMatrixInExcel <string, string, double> (OutMatrix, "My Date List"); }
/// <summary>Creates a date schedule that contains the start and end dates of the interest periods of each caplets, i.e. T_0, T_1, T_2, ..., where [T_k; T_{k+1}] is the /// interest period of caplet k, k=0,...,n-1; The first caplet is already expired but it is part of the date schedule. /// </summary> /// <param name="referenceDate">The reference date, i.e. the trading date.</param> /// <param name="startDateAndEndDateDescription">A description of the start date of the first caplet as well as the end date of the last caplet, i.e. the start date and the maturity of the cap.</param> /// <param name="marketConventions">The market conventions.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <param name="underlyingLiborTenor">A mapping of the null-based index of the start date of each caplet interest period to the tenor of the underlying Libor rate (output).</param> /// <param name="logger">An optional logger.</param> /// <returns> /// The date schedule of the interest periods, i.e. the start and end dates of each caplet; thus T_0, T_1, T_2, ..., where [T_k; T_{k+1}] is the /// interest period of caplet k, k=0,...,n-1; The first caplet is already expired but it is part of the date schedule. /// </returns> public ReadOnlyDateSchedule CreateInterestPeriodDateSchedule(DateTime referenceDate, ITimeframeDescription startDateAndEndDateDescription, ReadOnlyMoneyMarketConventions marketConventions, IHolidayCalendar holidayCalendar, out Func <int, TenorTimeSpan> underlyingLiborTenor, ILogger logger = null) { if (marketConventions == null) { throw new ArgumentNullException("marketConventions"); } if (holidayCalendar == null) { throw new ArgumentNullException("holidayCalendar"); } IBusinessDayConvention businessDayConvention = marketConventions.BusinessDayConvention; DateTime capStartDate, capEndDate; startDateAndEndDateDescription.GetStartAndEndDate(referenceDate, holidayCalendar, out capStartDate, out capEndDate); DateTime lastDate3M = businessDayConvention.GetAdjustedDate(capStartDate.AddTenorTimeSpan(sm_2YTenor), holidayCalendar); // it is the end date of the latest caplet with tenor 3M DateSchedule dateSchedule = new DateSchedule(holidayCalendar, logger: logger); if (capEndDate <= lastDate3M) { dateSchedule.Add(new ForwardDateScheduleRule(referenceDate, startDateAndEndDateDescription, sm_3MLiborRateTenor, businessDayConvention)); underlyingLiborTenor = (i => sm_3MLiborRateTenor.GetFrequencyTenor()); } else { ITimeframeDescription firstPeriod3M = TimeframeDescription.Create(lastDate3M); // applied to reference date='capStartDate' shows [capStartDate; lastDate3M] dateSchedule.Add(new ForwardDateScheduleRule(capStartDate, firstPeriod3M, sm_3MLiborRateTenor, businessDayConvention)); int indexOfLast3MPeriodEndDate = dateSchedule.Count - 1; ITimeframeDescription secondPeriod6M = TimeframeDescription.Create(capEndDate, endDateAdjustment: businessDayConvention); // applied to reference date ='lastDate3M' shows [lastDate3M; capEndDate] dateSchedule.Add(new ForwardDateScheduleRule(lastDate3M, secondPeriod6M, sm_6MLiborRateTenor, businessDayConvention)); underlyingLiborTenor = (i => (i < indexOfLast3MPeriodEndDate) ? sm_3MLiborRateTenor.GetFrequencyTenor() : sm_3MLiborRateTenor.GetFrequencyTenor()); } return(dateSchedule.AsReadOnly()); }