From ea4ca5a28b9bf9c8eec3d727dc35b6863c1f5d01 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 22 Feb 2019 17:11:42 -0500 Subject: bugfixes --- c_layer/curve.cpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'c_layer/curve.cpp') diff --git a/c_layer/curve.cpp b/c_layer/curve.cpp index 2f84d01..221f27c 100644 --- a/c_layer/curve.cpp +++ b/c_layer/curve.cpp @@ -64,7 +64,7 @@ namespace pyisda { } } - void Curve::tweak(TCurve* const ptr, double epsilon) { + void Curve::tweak(TCurve* ptr, double epsilon) { double h1, h2, t1, t2, c; h1 = t1 = c = 0; TRatePt cur; @@ -79,18 +79,22 @@ namespace pyisda { } } - void Curve::tweak(TCurve* const ptr, double epsilon, unsigned long mask) { - double h1, h2, t1, t2, c; - h1 = t1 = c = 0; - TRatePt cur; - for(int i = 0;i < ptr->fNumItems; i++) { - cur = ptr->fArray[i]; - h2 = cur.fRate; - t2 = (cur.fDate - ptr->fBaseDate) / 365.; - c += (h2 * t2 - h1 * t1 ) * (1 + epsilon * (( mask >> i) & 1)); - cur.fRate = c / t2; - h1 = h2; - t1 = t2; + void Curve::tweak(TCurve* ptr, double epsilon, unsigned long mask) { + if (mask == 0) { + Curve::tweak(ptr, epsilon); + } else { + double h1, h2, t1, t2, c; + h1 = t1 = c = 0; + TRatePt cur; + for(int i = 0; i < ptr->fNumItems; i++) { + cur = ptr->fArray[i]; + h2 = cur.fRate; + t2 = (cur.fDate - ptr->fBaseDate) / 365.; + c += (h2 * t2 - h1 * t1 ) * (1 + epsilon * (( mask >> i) & 1)); + cur.fRate = c / t2; + h1 = h2; + t1 = t2; + }; } } @@ -117,7 +121,8 @@ namespace pyisda { } size_t SpreadCurve::size() { - return Curve::size() + recovery_rates.size() * sizeof(double) + 8; + return Curve::size() + recovery_rates.size() * sizeof(double) + + 8 + sizeof(TDate) + sizeof(Seniority); } unsigned char* SpreadCurve::serialize(unsigned char* const buf) { @@ -131,7 +136,12 @@ namespace pyisda { } else { ticker.copy((char*)cur, 8, 0); } - return cur + 8; + cur += 8; + memcpy(cur, &event_date, sizeof(TDate)); + cur += sizeof(TDate); + memcpy(cur, &seniority, sizeof(Seniority)); + cur += sizeof(Seniority); + return cur; } } -- cgit v1.2.3-70-g09d2