diff options
Diffstat (limited to 'c_layer')
| -rw-r--r-- | c_layer/curve.cpp | 40 | ||||
| -rw-r--r-- | c_layer/curve.hpp | 24 |
2 files changed, 43 insertions, 21 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; } } diff --git a/c_layer/curve.hpp b/c_layer/curve.hpp index 5cc796a..39fdce9 100644 --- a/c_layer/curve.hpp +++ b/c_layer/curve.hpp @@ -5,6 +5,7 @@ #include "isda/bastypes.h" #include "isda/cdate.h" #include "isda/tcurve.h" +#include <iostream> namespace pyisda { class Curve { @@ -17,7 +18,7 @@ namespace pyisda { ~Curve() { JpmcdsFreeTCurve(ptr); } - explicit operator TCurve*() const { return ptr; } + TCurve* get_TCurve() const {return ptr; } unsigned char* serialize(unsigned char* buf); double zeroPrice(const TDate date); double zeroPrice(const TDate date1, const TDate date2); @@ -36,7 +37,7 @@ namespace pyisda { public: YieldCurve(TCurve* const curve, const std::vector<TDate>& dates) : Curve(curve), - dates(dates) {}; + dates(std::move(dates)) {}; YieldCurve(const YieldCurve &curve2) : Curve(curve2), dates(std::move(curve2.dates)) {}; @@ -47,18 +48,29 @@ namespace pyisda { class SpreadCurve : public Curve { public: + enum Seniority { + Senior, + Subordinated + }; + SpreadCurve(TCurve* const curve, const std::vector<double>& recovery_rates, - const std::string& ticker) : + const std::string& ticker, TDate event_date = -1, + Seniority sen = Senior) : Curve(curve), recovery_rates(recovery_rates), - ticker(ticker) {}; + ticker(ticker), + event_date(event_date), + seniority(sen) {}; SpreadCurve(const SpreadCurve &curve2) : Curve(curve2), recovery_rates(std::move(curve2.recovery_rates)), - ticker(std::move(curve2.ticker)) {}; - + ticker(std::move(curve2.ticker)), + event_date(curve2.event_date), + seniority(curve2.seniority) {}; std::vector<double> recovery_rates; std::string ticker; + TDate event_date; + SpreadCurve::Seniority seniority; size_t size(); unsigned char* serialize(unsigned char* buf); }; |
