diff options
| -rw-r--r-- | sql/date.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -56,9 +56,17 @@ static inline TDate TDate_from_DateADT(DateADT d) { return d + 145731; } +static inline const char* cal_from_currency(const char* curr) { + const char default_cal[] = "NONE"; + const char us_cal[] = "/usr/share/cds/US"; + if (strcmp(currency, "USD") == 0) { + return us_cal; + } else { + return default_cal; + } +} PG_FUNCTION_INFO_V1(cds_accrued); - Datum cds_accrued(PG_FUNCTION_ARGS) { const char default_cal[] = "NONE"; const char us_cal[] = "/usr/share/cds/US"; @@ -66,13 +74,7 @@ Datum cds_accrued(PG_FUNCTION_ARGS) { float8 coupon = PG_GETARG_FLOAT8(1); bool include_cashflow = PG_GETARG_BOOL(2); char* currency = text_to_cstring(PG_GETARG_TEXT_PP(3)); - const char* cal; - - if (strcmp(currency, "USD") == 0) { - cal = us_cal; - } else { - cal = default_cal; - } + const char* cal = cal_from_currency(currency); TDate date = TDate_from_DateADT(d) + 1; TDate date1 = next_business_day(date, JPMCDS_BAD_DAY_PREVIOUS, cal); if (date1 == -1) { @@ -90,12 +92,14 @@ Datum cds_accrued(PG_FUNCTION_ARGS) { PG_FUNCTION_INFO_V1(test); -Datum test(PG_FUNCTION_ARGS) { +Datum cds_enrich(PG_FUNCTION_ARGS) { if (SPI_connect() == SPI_ERROR_CONNECT) { elog(ERROR, "pomme"); } const text* redindexcode = PG_GETARG_TEXT_PP(0); DateADT maturity = PG_GETARG_DATEADT(1); + float8 traded_level = PG_GETARG_FLOAT8(2); + DateADT trade_datge = PG_GETARG_DATEADT(3); char* sql_query = "SELECT index, series, tenor::text, coupon, issue_date, indexfactor/100, " "version, cumulativeloss " "FROM index_desc " @@ -128,9 +132,8 @@ Datum test(PG_FUNCTION_ARGS) { factor = DatumGetFloat8(SPI_getbinval(tuple, tupdesc, 6, &isnull)); version = DatumGetInt16(SPI_getbinval(tuple, tupdesc, 7, &isnull)); cumulativeloss = DatumGetFloat8(SPI_getbinval(tuple, tupdesc, 8, &isnull)); - elog(ERROR, "index: %s, series: %dh, tenor: %s, coupon: %d, issue_date: %d, factor: %f, version: %dh, cumulativeloss: %f", - index, series, tenor, coupon, issue_date, factor, version, cumulativeloss); } + char* yc_query SPI_finish(); pfree(index); pfree(tenor); |
