private DataSet prepareDataSet(OPTION outputOption) { DataSet ret = new DataSet(); // Create a new DataTable. _returnedTable = new DataTable("BondPricer"); _returnedTable.Columns.Add(_ISINColumn); _returnedTable.Columns.Add(_DATEColumn); if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.DURATION)) { _returnedTable.Columns.Add(_columns[OPTION.DURATION]); } if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.ACCRUEDINTEREST)) { _returnedTable.Columns.Add(_columns[OPTION.ACCRUEDINTEREST]); } if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.CLEANPRICE)) { _returnedTable.Columns.Add(_columns[OPTION.CLEANPRICE]); } if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.DIRTYPRICE)) { _returnedTable.Columns.Add(_columns[OPTION.DIRTYPRICE]); } ret.Tables.Add(_returnedTable); return(ret); }
/// <summary> /// Remplit la dataset donnée en paramètre avec le resultat du calcul de : /// OPTION.DURATION , ou ou CLEANPRICE ou DIRTYPRICE ou ACCRUEDPRICE /// sur la base source /// </summary> /// <param name="DS"></param> public DataSet Execute(DataSet INPUTS, OPTION outputOption = OPTION.ALL) { DataRow row; DataSet ret = prepareDataSet(outputOption); // lecture input foreach (DataTable dt in INPUTS.Tables) { IntegratorBatch.InfoLogger.Debug("Nb de bonds à pricer :" + dt.Rows.Count); foreach (DataRow dr in dt.Rows) { // calcul pour une oblig string ISIN = dr.Field <string>("ISIN"); DateTime DATE = dr.Field <DateTime>("DATE"); DateTime maturity = dr.Field <DateTime>("MATURITY"); double ttm = (dr.Field <double?>("TTM") ?? getDays_30E360(DATE, maturity)); double c = dr.Field <double>("COUPON"); double r = dr.Field <double>("RATE"); int nbPeriods; if (ttm != null) { nbPeriods = (int)Math.Truncate((double)ttm); } else { // Calcul impossible continue; } double?cp = null, ai = null; row = _returnedTable.NewRow(); row["ISIN"] = ISIN; row["DATE"] = DATE; if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.CLEANPRICE)) { cp = CleanPrice(c, nbPeriods, r); row["CLEANPRICE"] = cp; } if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.DURATION)) { if (c == 0 || nbPeriods <= 1) { row["DURATION"] = ttm; } else { cp = cp ?? CleanPrice(c, nbPeriods, r); double duration = Duration((double)cp, c, nbPeriods, r); row["DURATION"] = duration; } } if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.ACCRUEDINTEREST)) { ai = AccruedInterest(c, nbPeriods, ttm); row["ACCRUEDINTEREST"] = ai; } if (outputOption.Equals(OPTION.ALL) || outputOption.Equals(OPTION.DIRTYPRICE)) { cp = cp ?? CleanPrice(c, nbPeriods, r); ai = ai ?? AccruedInterest(c, nbPeriods, ttm); row["DIRTYPRICE"] = cp + ai; } _returnedTable.Rows.Add(row); } } return(ret); }