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"); }
// Class ListedSTFutOption and AssocMatrix public static void Example4() { // Stir (Short Term Interest Rate ) Option example. // (Please check details on www.euronext.com) Example is based on Black Formula // I create my option STFutOption opx1 = new STFutOption(1, 97.935, 98.25, 175, 0.4756); // option deltas Console.WriteLine("{0}, {1}", opx1.Price(), opx1.Delta()); opx1.SwitchCallPut(); Console.WriteLine("{0}, {1}", opx1.Price(), opx1.Delta()); // Call and put checking deltas and call put parity double S = 97.935; double K = 98.25; double DaysToExpiry = 175; STFutOption Call = new STFutOption(1, S, K, 175, 0.4756); STFutOption Put = new STFutOption(-1, S, K, 175, 0.4756); Console.WriteLine("{0},{1},{2}", Call.Delta(), Put.Delta(), Call.Delta() - Put.Delta()); // Call/Put delta are reversed Console.WriteLine("{0}", Call.Price() - Put.Price() - S + K); // Call/Put parity // I will crate a matrix showing deltas of a option, for different underlying price (rows) and passing the time (columns) // header Row: different value of underlying. the center is the current one // header column: passing the time, less days to maturity // Time passing - column int d_columns = 20; // how many days from and including today double shift_c = 1.0; // interval in days between each columns // Changing value of underlying int d_rows = 15; // how many values plus or minus the value double shift_h = 0.10; // interval in underlying NumericMatrix <double> deltaMatrix = new NumericMatrix <double>(d_rows * 2 + 1, d_columns); // Underlying value double d_r = -d_rows; Set <double> underlying = new Set <double>(); for (int i = 0; i < deltaMatrix.Rows; i++) { underlying.Insert(S + d_r * shift_h); d_r++; } // Days to maturity double d_c = 0; Set <double> days = new Set <double>(); for (int i = 0; i < deltaMatrix.Columns; i++) { days.Insert(DaysToExpiry + d_c * shift_c); d_c--; } // Populate DeltaMatrix int my_r = 1; int my_c = 1; foreach (double valueS in underlying) { Call.new_S = valueS; foreach (double valueDays in days) { Call.new_DaysToExpiry = valueDays; deltaMatrix[my_r, my_c] = Call.Delta(); my_c++; } my_r++; my_c = 1; } // Creating AssocMatrix AssocMatrix <double, double, double> OutMatrix = new AssocMatrix <double, double, double>(underlying, days, deltaMatrix); // Print associative matrices in Excel, to "StirDeltas" sheet ExcelMechanisms exl = new ExcelMechanisms(); exl.printAssocMatrixInExcel <double, double, double>(OutMatrix, "StirDeltas"); }