diff options
| -rw-r--r-- | sql/serenitas.c | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/sql/serenitas.c b/sql/serenitas.c index b2547e15..d1adcf5b 100644 --- a/sql/serenitas.c +++ b/sql/serenitas.c @@ -98,54 +98,58 @@ Datum cds_accrued(PG_FUNCTION_ARGS) { static inline void get_TCurve(const char* buf, uint32_t length, TCurve* curve) { if (LZ4_decompress_safe(buf, (char*)curve, length, 512) < 0) { elog(ERROR, "error during decompression"); + free(curve); } } double calc(TDate today, TDate start_date, TDate end_date, double recovery, double fixed_rate, const char* calendar, const TCurve* yc, double val, bool calc_upfront) { + elog(INFO, "pomme"); TDate cash_settle_date; JpmcdsDateFromBusDaysOffset(today, 3, calendar, &cash_settle_date); TDate step_in_date = today + 1; TStubMethod stub_type = {0, 0}; //f/s TDateInterval ivl = {.prd = 3, .prd_typ='M', .flag=0}; // 3 months double result; + int success; if (calc_upfront) { - JpmcdsCdsoneUpfrontCharge(today, - cash_settle_date, - today, // benchmark_start_date - step_in_date, - start_date, - end_date, - fixed_rate, - true, // pay accrued on default - &ivl, - &stub_type, - JPMCDS_ACT_360, - JPMCDS_BAD_DAY_FOLLOW, - calendar, - yc, - val, - recovery, - true, // pay accrued at start - &result); + success = JpmcdsCdsoneUpfrontCharge(today, + cash_settle_date, + today, // benchmark_start_date + step_in_date, + start_date, + end_date, + fixed_rate, + true, // pay accrued on default + &ivl, + &stub_type, + JPMCDS_ACT_360, + JPMCDS_BAD_DAY_FOLLOW, + calendar, + yc, + val, + recovery, + true, // pay accrued at start + &result); + elog(INFO, "poupou %d", success); } else { - JpmcdsCdsoneSpread(today, - cash_settle_date, - today, // benchmark_start_date - step_in_date, - start_date, - end_date, - fixed_rate, - true, // pay accrued on default - &ivl, - &stub_type, - JPMCDS_ACT_360, - JPMCDS_BAD_DAY_FOLLOW, - calendar, - yc, - val, - recovery, - true, // pay accrued at start - &result); + success = JpmcdsCdsoneSpread(today, + cash_settle_date, + today, // benchmark_start_date + step_in_date, + start_date, + end_date, + fixed_rate, + true, // pay accrued on default + &ivl, + &stub_type, + JPMCDS_ACT_360, + JPMCDS_BAD_DAY_FOLLOW, + calendar, + yc, + val, + recovery, + true, // pay accrued at start + &result); } return result; } @@ -216,10 +220,8 @@ Datum upfront_from_level(PG_FUNCTION_ARGS) { elog(ERROR, "no curve for that date"); } else { buf = DatumGetByteaPP(tmp); - uint32 data_length = VARSIZE_ANY(buf); + uint32 data_length = VARSIZE_ANY_EXHDR(buf); const char *raw_data = VARDATA_ANY(buf); - elog(INFO, "%d", data_length); - elog(INFO, "%.*s", data_length, raw_data); curve = (TCurve*)malloc(512); get_TCurve(raw_data, data_length, curve); } @@ -228,7 +230,6 @@ Datum upfront_from_level(PG_FUNCTION_ARGS) { SPI_finish(); elog(ERROR, "no curve for that date"); } - elog(INFO, "poire"); SPI_finish(); double recovery = 0.4; double upfront; |
