summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-10-29 15:36:51 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2018-10-29 15:36:51 -0400
commit4c4223ff594a4f19a2942da182b1bdeecd835915 (patch)
treeceb3118da64af6713451966842d3312a85e85c9a
parent6806cc9b159ec5f0f9816c1e0f4ae1f0792ddf16 (diff)
downloadpyisda-4c4223ff594a4f19a2942da182b1bdeecd835915.tar.gz
small speedup
-rw-r--r--pyisda/curve.pyx32
1 files changed, 19 insertions, 13 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 7235ce7..98c6044 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -49,9 +49,9 @@ cdef double survival_prob(TCurve* curve, TDate start_date, TDate maturity_date,
else:
lambda1 = JpmcdsZeroRate(curve, start_date)
lambda2 = JpmcdsZeroRate(curve, maturity_date)
- t1 = (start_date - curve.fBaseDate) / 365.
- t2 = (maturity_date - curve.fBaseDate) / 365.
- u = lambda1 * t1 - lambda2 * t2
+ t1 = start_date - curve.fBaseDate
+ t2 = maturity_date - curve.fBaseDate
+ u = (lambda1 * t1 - lambda2 * t2) / 365.
if eps != 0.:
u *= (1 + eps)
return exp(u)
@@ -440,16 +440,22 @@ cdef void tweak_curve(const TCurve* sc, TCurve* sc_tweaked, double epsilon,
h1 = t1 = c = 0
cdef size_t i
- for i in range(sc.fNumItems):
- h2 = sc.fArray[i].fRate
- t2 = (sc.fArray[i].fDate - sc.fBaseDate) / 365.
- h = (h2 * t2 - h1 * t1) / (t2 - t1)
- if mask == 0 or (mask >> i) & 1:
- h *= (1 + epsilon)
- c += (t2 - t1) * h
- sc_tweaked.fArray[i].fRate = c / t2
- h1 = h2
- t1 = t2
+ if mask == 0:
+ for i in range(sc.fNumItems):
+ h2 = sc.fArray[i].fRate
+ t2 = (sc.fArray[i].fDate - sc.fBaseDate) / 365.
+ c += h2 * t2 - h1 * t1
+ sc_tweaked.fArray[i].fRate = c / t2
+ h1 = h2
+ t1 = t2
+ else:
+ for i in range(sc.fNumItems):
+ h2 = sc.fArray[i].fRate
+ t2 = (sc.fArray[i].fDate - sc.fBaseDate) / 365.
+ c += (h2 * t2 - h1 * t1) * ( 1 + epsilon * ((mask >> i) & 1))
+ sc_tweaked.fArray[i].fRate = c / t2
+ h1 = h2
+ t1 = t2
cdef class SpreadCurve(Curve):
"""