Skip to content

Commit 3109fc5

Browse files
committed
More PEP 8 work
1 parent fd53e32 commit 3109fc5

File tree

86 files changed

+7650
-7240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+7650
-7240
lines changed

.pylintrc

Lines changed: 28 additions & 609 deletions
Large diffs are not rendered by default.

financepy/__init__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
if 1==1:
2-
cr = "\n"
3-
4-
s = "####################################################################" + cr
5-
s += "# FINANCEPY Version " + str('1.1') + " - This build: 15 Aug 2025 at 13:47 #" + cr
6-
s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr
7-
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
8-
s += "####################################################################"
9-
s += cr
10-
11-
print(s)
1+
cr = "\n"
2+
s = "####################################################################" + cr
3+
s += "# FINANCEPY Version " + str('1.1') + " - This build: 20 Aug 2025 at 11:08 #" + cr
4+
s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr
5+
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
6+
s += "####################################################################"
7+
s += cr
8+
print(s)

financepy/market/curves/discount_curve_pwf_onf.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def __init__(
3535
):
3636
"""
3737
Creates a discount curve using a vector of times and ON fwd rates
38-
The fwd rate is right-continuous i.e. a given value in the
39-
input is applied to the left of that date until the previous date exclusive
38+
The fwd rate is right-continuous i.e. a given value in the input
39+
is applied to the left of that date until the previous date exclusive
4040
The last fwd rate is extrapolated into the future
4141
"""
4242

@@ -77,7 +77,7 @@ def __init__(
7777
if test_monotonicity(self._times) is False:
7878
raise FinError("Times are not sorted in increasing order")
7979

80-
###############################################################################
80+
###########################################################################
8181

8282
@classmethod
8383
def brick_wall_curve(
@@ -87,13 +87,17 @@ def brick_wall_curve(
8787
end_dt: Date,
8888
level: float = 1.0 * G_BASIS_POINT,
8989
):
90-
"""Generate a discount curve of the shape f(t) = level*1_{startdate < t <= enddate} where f(.) is the instantaneous forward rate
91-
Mostly useful for applying bumps to other discount_curve's, see composite_discount_curve.py
90+
"""Generate a discount curve of the shape
91+
f(t) = level*1_{startdate < t <= enddate}
92+
where f(.) is the instantaneous forward rate
93+
Mostly useful for applying bumps to other discount_curve's,
94+
see composite_discount_curve.py
9295
Args:
9396
valuation_date (Date): valuation date for the discount_curve
9497
start_dt (Date): start of the non-zero ON forward rate
9598
end_dt (Date): end of the non-zero ON forward rate
96-
level (float, optional): ON forward rate between the start and end dates. Defaults to 1.0*G_BASIS_POINT.
99+
level (float, optional): ON forward rate between the
100+
start and end dates. Defaults to 1.0*G_BASIS_POINT.
97101
98102
Returns:
99103
DiscountCurve: discount curve of the required shape
@@ -102,7 +106,7 @@ def brick_wall_curve(
102106
onfwd_rates = [0.0, level, 0.0]
103107
return cls(valuation_date, knot_dts, onfwd_rates)
104108

105-
###############################################################################
109+
###########################################################################
106110

107111
@classmethod
108112
def flat_curve(
@@ -112,7 +116,7 @@ def flat_curve(
112116
onfwd_rates = [level]
113117
return cls(valuation_date, knot_dts, onfwd_rates)
114118

115-
###############################################################################
119+
###########################################################################
116120

117121
def _zero_rate(self, times: Union[float, np.ndarray, list]):
118122
"""
@@ -129,11 +133,11 @@ def _zero_rate(self, times: Union[float, np.ndarray, list]):
129133
zero_rates = -ldfs / times
130134
return zero_rates
131135

132-
###############################################################################
136+
###########################################################################
133137

134138
def df_t(self, t: Union[float, np.ndarray]):
135-
"""Return discount factors given a single or vector of times in years. The
136-
discount factor depends on the rate and this in turn depends on its
139+
"""Return discount factors given a single or vector of times in years.
140+
The discount factor depends on the rate and this in turn depends on its
137141
compounding frequency and it defaults to continuous compounding. It
138142
also depends on the day count convention. This was set in the
139143
construction of the curve to be ACT_ACT_ISDA."""
@@ -146,7 +150,7 @@ def df_t(self, t: Union[float, np.ndarray]):
146150

147151
return df
148152

149-
###############################################################################
153+
###########################################################################
150154

151155
def __repr__(self):
152156

@@ -157,7 +161,7 @@ def __repr__(self):
157161
s += label_to_string("FREQUENCY", (self.freq_type))
158162
return s
159163

160-
###############################################################################
164+
###########################################################################
161165

162166
def _print(self):
163167
"""Simple print function for backward compatibility."""

financepy/market/volatility/equity_vol_surface.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ def _delta_fit(k, *args):
199199
t = args[2]
200200
r = args[3]
201201
q = args[4]
202-
option_type_value = args[5]
202+
opt_type_value = args[5]
203203
inverse_delta_target = args[6]
204204
params = args[7]
205205

206206
f = s * np.exp((r - q) * t)
207207
v = vol_function(vol_type_value, params, f, k, t)
208-
delta_out = bs_delta(s, t, k, r, q, v, option_type_value)
208+
delta_out = bs_delta(s, t, k, r, q, v, opt_type_value)
209209
inverse_delta_out = norminvcdf(np.abs(delta_out))
210210
inv_obj_fn = inverse_delta_target - inverse_delta_out
211211

@@ -224,7 +224,7 @@ def _solver_for_smile_strike(
224224
t,
225225
r,
226226
q,
227-
option_type_value,
227+
opt_type_value,
228228
vol_type_value,
229229
delta_target,
230230
initial_guess,
@@ -242,12 +242,14 @@ def _solver_for_smile_strike(
242242
t,
243243
r,
244244
q,
245-
option_type_value,
245+
opt_type_value,
246246
inverse_delta_target,
247247
parameters,
248248
)
249249

250-
k = newton_secant(_delta_fit, x0=initial_guess, args=argtuple, tol=1e-8, maxiter=50)
250+
k = newton_secant(
251+
_delta_fit, x0=initial_guess, args=argtuple, tol=1e-8, maxiter=50
252+
)
251253
return k
252254

253255

@@ -362,11 +364,15 @@ def vol_from_strike_date(self, k, expiry_dt):
362364
t0 = self._t_exp[index0]
363365
t1 = self._t_exp[index1]
364366

365-
vol0 = vol_function(vol_type_value, self._parameters[index0], fwd0, k, t0)
367+
vol0 = vol_function(
368+
vol_type_value, self._parameters[index0], fwd0, k, t0
369+
)
366370

367371
if index1 != index0:
368372

369-
vol1 = vol_function(vol_type_value, self._parameters[index1], fwd1, k, t1)
373+
vol1 = vol_function(
374+
vol_type_value, self._parameters[index1], fwd1, k, t1
375+
)
370376

371377
else:
372378

@@ -556,7 +562,9 @@ def vol_from_delta_date(self, call_delta, expiry_dt, delta_method=None):
556562
self._parameters[index0],
557563
)
558564

559-
vol0 = vol_function(vol_type_value, self._parameters[index0], fwd0, k_0, t0)
565+
vol0 = vol_function(
566+
vol_type_value, self._parameters[index0], fwd0, k_0, t0
567+
)
560568

561569
if index1 != index0:
562570

@@ -572,7 +580,9 @@ def vol_from_delta_date(self, call_delta, expiry_dt, delta_method=None):
572580
self._parameters[index1],
573581
)
574582

575-
vol1 = vol_function(vol_type_value, self._parameters[index1], fwd1, k_1, t1)
583+
vol1 = vol_function(
584+
vol_type_value, self._parameters[index1], fwd1, k_1, t1
585+
)
576586
else:
577587
vol1 = vol0
578588

@@ -587,7 +597,9 @@ def vol_from_delta_date(self, call_delta, expiry_dt, delta_method=None):
587597
kt = ((t_exp - t0) * k_1 + (t1 - t_exp) * k_0) / (t1 - t0)
588598

589599
if vart < 0.0:
590-
raise FinError("Failed interpolation due to negative variance.")
600+
raise FinError(
601+
"Failed interpolation due to negative variance."
602+
)
591603

592604
volt = np.sqrt(vart / t_exp)
593605

0 commit comments

Comments
 (0)