summaryrefslogtreecommitdiffstats
path: root/c_layer/curve.cpp
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2019-02-22 17:11:42 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2019-02-22 17:11:42 -0500
commitea4ca5a28b9bf9c8eec3d727dc35b6863c1f5d01 (patch)
tree81616f79a1b5dcf4a1fe0b9cededd22542fc144c /c_layer/curve.cpp
parenta0e798113024114c3002e3eee1e09ae194dbf3f4 (diff)
downloadpyisda-ea4ca5a28b9bf9c8eec3d727dc35b6863c1f5d01.tar.gz
bugfixesmore_cpp
Diffstat (limited to 'c_layer/curve.cpp')
-rw-r--r--c_layer/curve.cpp40
1 files changed, 25 insertions, 15 deletions
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;
}
}