From a94509a93d91e0071ad5ee9ef5c4687e2d7a0fea Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 8 May 2018 14:44:49 -0400 Subject: pep8 --- pyisda/cdsone.pyx | 43 +++++++++++++++++++++---------------------- pyisda/credit_index.pyx | 23 +++++++++++------------ pyisda/curve.pyx | 4 ++-- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/pyisda/cdsone.pyx b/pyisda/cdsone.pyx index 6d0712f..e2f78a0 100644 --- a/pyisda/cdsone.pyx +++ b/pyisda/cdsone.pyx @@ -3,6 +3,7 @@ from date cimport JpmcdsMakeDateInterval, pydate_to_TDate, dcc cdef int SUCCESS = 0 + def upfront_charge(date, value_date, benchmark_start_date, stepin_date, start_date, end_date, double coupon_rate, YieldCurve yc, @@ -41,16 +42,15 @@ def upfront_charge(date, value_date, benchmark_start_date, stepin_date, in case of default do we pay current accrued on default or at maturity. """ cdef: - TDate today = pydate_to_TDate(date) - TDate value_date_c = pydate_to_TDate(value_date) - TDate benchmark_start_date_c = pydate_to_TDate(benchmark_start_date) - TDate stepin_date_c = pydate_to_TDate(stepin_date) - TDate start_date_c = pydate_to_TDate(start_date) - TDate end_date_c = pydate_to_TDate(end_date) - double result - TStubMethod stub - TDateInterval ivl - char* routine = "upfront_charge" + TDate today = pydate_to_TDate(date) + TDate value_date_c = pydate_to_TDate(value_date) + TDate benchmark_start_date_c = pydate_to_TDate(benchmark_start_date) + TDate stepin_date_c = pydate_to_TDate(stepin_date) + TDate start_date_c = pydate_to_TDate(start_date) + TDate end_date_c = pydate_to_TDate(end_date) + double result + TStubMethod stub + TDateInterval ivl if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: raise ValueError("can't convert stub") @@ -71,8 +71,8 @@ def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date, YieldCurve yc, double upfront, double recovery_rate, - TBoolean pay_accrued_at_start = True, - TBoolean pay_accrued_on_default = True): + TBoolean pay_accrued_at_start=True, + TBoolean pay_accrued_on_default=True): """Computes the equivalent fair spread for a cds with upfront+running. Parameters @@ -104,16 +104,15 @@ def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date, """ cdef: - TDate today = pydate_to_TDate(date) - TDate value_date_c = pydate_to_TDate(value_date) - TDate benchmark_start_date_c = pydate_to_TDate(benchmark_start_date) - TDate stepin_date_c = pydate_to_TDate(stepin_date) - TDate start_date_c = pydate_to_TDate(start_date) - TDate end_date_c = pydate_to_TDate(end_date) - double result - TStubMethod stub - TDateInterval ivl - char* routine = "upfront_charge" + TDate today = pydate_to_TDate(date) + TDate value_date_c = pydate_to_TDate(value_date) + TDate benchmark_start_date_c = pydate_to_TDate(benchmark_start_date) + TDate stepin_date_c = pydate_to_TDate(stepin_date) + TDate start_date_c = pydate_to_TDate(start_date) + TDate end_date_c = pydate_to_TDate(end_date) + double result + TStubMethod stub + TDateInterval ivl if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: raise ValueError("can't convert stub") diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index d642acf..89d8802 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -113,7 +113,6 @@ cdef class CurveList: return sc def items(self): - ## would need to use a shared pointer to avoid a copy cdef: SpreadCurve sc pair[string, size_t] p @@ -349,6 +348,7 @@ cdef class CreditIndex(CurveList): columns=d.view('M8[D]'), index=tickers)], keys=['duration', 'protection_pv']) + def accrued(self): cdef double accrued FeeLegAI(self.fee_legs[0], self.base_date, &accrued) @@ -393,11 +393,11 @@ cdef class CreditIndex(CurveList): if theta_date is None, this is 1 year theta, otherwise theta to that date""" cdef: TDate step_in_date_c = pydate_to_TDate(step_in_date) - TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date) + TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date) TDate maturity_c = pydate_to_TDate(maturity) TDate theta_date_c, temp vector[double] h - pair[TContingentLeg_ptr,TFeeLeg_ptr] legs + pair[TContingentLeg_ptr, TFeeLeg_ptr] legs TDateInterval ivl int i double carry @@ -466,8 +466,8 @@ cdef class CreditIndex(CurveList): &stub_type, 1., 1.0, - 3, #ACT_360 - 'M', # MODIFIED + 3, # ACT_360 + 'M', # MODIFIED b'NONE', True) else: @@ -541,7 +541,6 @@ cdef unsigned long fill_mask(const TDate maturity, const vector[TDate]& maturiti TRatePt* it = sc.get().fArray unsigned long mask = 0 - for i in range(maturities.size()): if maturities[i] == maturity: break @@ -569,10 +568,10 @@ cdef inline int get_maturity_index(TDate maturity, const vector[TDate]& maturiti return -1 return i -cdef pair[TContingentLeg_ptr,TFeeLeg_ptr] get_legs(TDate maturity, - TDate start_date) nogil: +cdef pair[TContingentLeg_ptr, TFeeLeg_ptr] get_legs(TDate maturity, + TDate start_date) nogil: cdef: - pair[TContingentLeg_ptr,TFeeLeg_ptr] r + pair[TContingentLeg_ptr, TFeeLeg_ptr] r TStubMethod stub_type JpmcdsStringToStubMethod(b"f/s", &stub_type) r.first = JpmcdsCdsContingentLegMake(start_date, @@ -586,8 +585,8 @@ cdef pair[TContingentLeg_ptr,TFeeLeg_ptr] get_legs(TDate maturity, &stub_type, 1., 1.0, - 3, #ACT_360 - 'M', # MODIFIED + 3, # ACT_360 + 'M', # MODIFIED b'NONE', True) return r @@ -597,7 +596,7 @@ cdef double pv(vector[shared_ptr[TCurve]]& curves, TDate step_in_date, TDate cash_settle_date, TCurve* yc, - pair[TContingentLeg_ptr,TFeeLeg_ptr]& legs, + pair[TContingentLeg_ptr, TFeeLeg_ptr]& legs, double recovery_rate, double fixed_rate, vector[double]& weights, diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 7e5ee58..8dc79a5 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -110,13 +110,13 @@ cdef class Curve(object): h2 = it[i].fRate t2 = (it[i].fDate - base_date)/365. h[i] = (h2 * t2 - h1 * t1) / (t2 - t1) - d[i] = it[i].fDate -134774 + d[i] = it[i].fDate - 134774 h1 = h2 t1 = t2 else: for i in range(n): h[i] = it[i].fRate - d[i] = it[i].fDate -134774 + d[i] = it[i].fDate - 134774 if isinstance(self, YieldCurve): name = 'forward_rates' elif isinstance(self, SpreadCurve): -- cgit v1.2.3-70-g09d2