summaryrefslogtreecommitdiffstats
path: root/c_layer/cdsbootstrap.c
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2016-11-10 14:21:34 -0500
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2016-11-10 14:21:34 -0500
commit8134b12f3d051e468a20df1a8e90408dedc3d112 (patch)
tree914139595dd6c822023fb23da42ce1df6f34a0df /c_layer/cdsbootstrap.c
parentf39919c51ec7e4dab767156db0ed1fd457787672 (diff)
downloadpyisda-8134b12f3d051e468a20df1a8e90408dedc3d112.tar.gz
add fater version
Diffstat (limited to 'c_layer/cdsbootstrap.c')
-rw-r--r--c_layer/cdsbootstrap.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/c_layer/cdsbootstrap.c b/c_layer/cdsbootstrap.c
new file mode 100644
index 0000000..f3ae975
--- /dev/null
+++ b/c_layer/cdsbootstrap.c
@@ -0,0 +1,50 @@
+#include "cdsbootstrap.h"
+
+int cdsBootstrapPointFunction
+(double hazardRate,
+ void *data,
+ double *pv)
+{
+ int status = FAILURE;
+
+ cds_bootstrap_ctx *context = (cds_bootstrap_ctx*)data;
+
+ TCurve *discountCurve = context->discountCurve;
+ TCurve *cdsCurve = context->cdsCurve;
+ TDate cdsBaseDate = cdsCurve->fBaseDate;
+ TDate stepinDate = context->stepinDate;
+ TDate cashSettleDate = context->cashSettleDate;
+
+ double pvC; /* PV of contingent leg */
+ double pvF; /* PV of fee leg */
+ cdsCurve->fArray[0].fRate = hazardRate;
+
+ if (JpmcdsContingentLegPV (context->cl,
+ cdsBaseDate,
+ cashSettleDate,
+ stepinDate,
+ discountCurve,
+ cdsCurve,
+ context->recoveryRate,
+ &pvC) != SUCCESS)
+ goto done;
+
+ if (JpmcdsFeeLegPV(context->fl,
+ cdsBaseDate,
+ stepinDate,
+ cashSettleDate,
+ discountCurve,
+ cdsCurve,
+ 1,
+ &pvF) != SUCCESS)
+ goto done;
+ /* Note: price is discounted to cdsBaseDate */
+ *pv = pvC - context->spread * pvF;
+ status = SUCCESS;
+
+ done:
+
+ if (status != SUCCESS)
+ printf("Something went wrong");
+ return status;
+}