Skip to content

Commit be66b82

Browse files
committed
PEP 8 CHANGES
1 parent b774d36 commit be66b82

File tree

139 files changed

+5072
-4507
lines changed

Some content is hidden

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

139 files changed

+5072
-4507
lines changed

financepy/market/curves/discount_curve.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from ...utils.date import Date
1212
from ...utils.error import FinError
13-
from ...utils.global_vars import g_days_in_year, g_small
13+
from ...utils.global_vars import G_DAYS_IN_YEARS, G_SMALL
1414
from ...utils.frequency import annual_frequency, FrequencyTypes
1515
from ...utils.day_count import DayCount, DayCountTypes
1616
from ...utils.math import test_monotonicity
@@ -65,7 +65,7 @@ def __init__(
6565
start_index = 1
6666

6767
for i in range(start_index, num_points):
68-
t = (df_dates[i] - value_dt) / g_days_in_year
68+
t = (df_dates[i] - value_dt) / G_DAYS_IN_YEARS
6969
self._times.append(t)
7070
self._dfs.append(df_values[i])
7171

@@ -114,7 +114,7 @@ def _zero_to_df(
114114
if isinstance(times, float):
115115
times = np.array([times])
116116

117-
t = np.maximum(times, g_small)
117+
t = np.maximum(times, G_SMALL)
118118

119119
f = annual_frequency(freq_type)
120120

@@ -180,7 +180,7 @@ def _df_to_zero(
180180

181181
df = df_list[i]
182182

183-
t = max(times[i], g_small)
183+
t = max(times[i], G_SMALL)
184184

185185
if freq_type == FrequencyTypes.CONTINUOUS:
186186
r = -np.log(df) / t
@@ -293,7 +293,7 @@ def swap_rate(
293293
pv01 += alpha * df
294294
prev_dt = next_dt
295295

296-
if abs(pv01) < g_small:
296+
if abs(pv01) < G_SMALL:
297297
par_rate = 0.0
298298
else:
299299
df_start = self.df(effective_dt)
@@ -373,7 +373,7 @@ def fwd(self, dts: Date):
373373

374374
df1 = self.df(dts)
375375
df2 = self.df(dts_plus_one_days)
376-
dt = 1.0 / g_days_in_year
376+
dt = 1.0 / G_DAYS_IN_YEARS
377377
fwd = np.log(df1 / df2) / (1.0 * dt)
378378

379379
if isinstance(dts, Date):

financepy/market/curves/discount_curve_ns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...utils.date import Date
1010
from ...utils.frequency import FrequencyTypes
11-
from ...utils.global_vars import g_small
11+
from ...utils.global_vars import G_SMALL
1212
from ...utils.error import FinError
1313
from ...market.curves.discount_curve import DiscountCurve
1414
from ...utils.helpers import check_argument_types
@@ -99,7 +99,7 @@ def _zero_rate(self, times: Union[float, np.ndarray]):
9999
"""Zero rate for Nelson-Siegel curve parametrisation. This means that
100100
the t vector must use the curve day count."""
101101

102-
t = np.maximum(times, g_small)
102+
t = np.maximum(times, G_SMALL)
103103

104104
theta = t / self._tau
105105
e = np.exp(-theta)

financepy/market/curves/discount_curve_nss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...utils.date import Date
1010
from ...utils.frequency import FrequencyTypes
11-
from ...utils.global_vars import g_small
11+
from ...utils.global_vars import G_SMALL
1212
from ...utils.helpers import label_to_string
1313
from ...utils.error import FinError
1414
from ...market.curves.discount_curve import DiscountCurve
@@ -110,7 +110,7 @@ def _zero_rate(self, times: Union[float, np.ndarray]):
110110
times. This function can return a single zero rate or a vector of zero
111111
rates. The compounding frequency must be provided."""
112112

113-
t = np.maximum(times, g_small)
113+
t = np.maximum(times, G_SMALL)
114114

115115
theta_1 = t / self._tau_1
116116
theta_2 = t / self._tau_2

financepy/market/curves/discount_curve_poly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...utils.date import Date
1010
from ...utils.error import FinError
11-
from ...utils.global_vars import g_small
11+
from ...utils.global_vars import G_SMALL
1212
from ...utils.helpers import label_to_string
1313
from ...market.curves.discount_curve import DiscountCurve
1414
from ...utils.helpers import check_argument_types
@@ -91,7 +91,7 @@ def _zero_rate(self, times: Union[float, np.ndarray]):
9191
use. The compounding frequency defaults to that specified in the
9292
constructor of the curve object. Which may be annual to continuous."""
9393

94-
t = np.maximum(times, g_small)
94+
t = np.maximum(times, G_SMALL)
9595

9696
zero_rate = 0.0
9797
for n in range(0, len(self._coefficients)):

financepy/market/curves/discount_curve_pwf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...utils.date import Date
1010
from ...utils.error import FinError
11-
from ...utils.global_vars import g_small
11+
from ...utils.global_vars import G_SMALL
1212
from ...utils.math import test_monotonicity
1313
from ...utils.frequency import FrequencyTypes
1414
from ...utils.helpers import label_to_string
@@ -70,7 +70,7 @@ def _zero_rate(self, times: Union[float, np.ndarray, list]):
7070
if np.any(times < 0.0):
7171
raise FinError("All times must be positive")
7272

73-
times = np.maximum(times, g_small)
73+
times = np.maximum(times, G_SMALL)
7474

7575
zero_rates = []
7676

financepy/market/curves/discount_curve_pwf_onf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...utils.date import Date
1010
from ...utils.error import FinError
11-
from ...utils.global_vars import g_small, g_basis_point
11+
from ...utils.global_vars import G_SMALL, G_BASIS_POINT
1212
from ...utils.math import test_monotonicity
1313
from ...utils.frequency import FrequencyTypes
1414
from ...utils.helpers import label_to_string
@@ -81,15 +81,15 @@ def brick_wall_curve(
8181
valuation_date: Date,
8282
start_dt: Date,
8383
end_dt: Date,
84-
level: float = 1.0 * g_basis_point,
84+
level: float = 1.0 * G_BASIS_POINT,
8585
):
8686
"""Generate a discount curve of the shape f(t) = level*1_{startdate < t <= enddate} where f(.) is the instantaneous forward rate
8787
Mostly useful for applying bumps to other discount_curve's, see composite_discount_curve.py
8888
Args:
8989
valuation_date (Date): valuation date for the discount_curve
9090
start_dt (Date): start of the non-zero ON forward rate
9191
end_dt (Date): end of the non-zero ON forward rate
92-
level (float, optional): ON forward rate between the start and end dates. Defaults to 1.0*g_basis_point.
92+
level (float, optional): ON forward rate between the start and end dates. Defaults to 1.0*G_BASIS_POINT.
9393
9494
Returns:
9595
DiscountCurve: discount curve of the required shape
@@ -101,7 +101,7 @@ def brick_wall_curve(
101101
###############################################################################
102102

103103
@classmethod
104-
def flat_curve(cls, valuation_date: Date, level: float = 1.0 * g_basis_point):
104+
def flat_curve(cls, valuation_date: Date, level: float = 1.0 * G_BASIS_POINT):
105105
knot_dts = [valuation_date.add_tenor("1Y")]
106106
onfwd_rates = [level]
107107
return cls(valuation_date, knot_dts, onfwd_rates)
@@ -118,7 +118,7 @@ def _zero_rate(self, times: Union[float, np.ndarray, list]):
118118
if np.any(times < 0.0):
119119
raise FinError("All times must be positive")
120120

121-
times = np.maximum(times, g_small)
121+
times = np.maximum(times, G_SMALL)
122122
ldfs = self._logdfs_interp(times)
123123
zero_rates = -ldfs / times
124124
return zero_rates

financepy/market/curves/interpolator.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from scipy.interpolate import CubicSpline
1111
from scipy.interpolate import InterpolatedUnivariateSpline
1212
from ...utils.error import FinError
13-
from ...utils.global_vars import g_small
13+
from ...utils.global_vars import G_SMALL
1414
from ...utils.tension_spline import TensionSpline
1515

1616
###############################################################################
@@ -236,8 +236,8 @@ def fit(self, times: np.ndarray, dfs: np.ndarray):
236236

237237
elif self._interp_type == InterpTypes.PCHIP_ZERO_RATES:
238238

239-
g_small_vector = np.ones(len(self._times)) * g_small
240-
zero_rates = -np.log(self._dfs) / (self._times + g_small_vector)
239+
G_SMALL_vector = np.ones(len(self._times)) * G_SMALL
240+
zero_rates = -np.log(self._dfs) / (self._times + G_SMALL_vector)
241241

242242
if self._times[0] == 0.0:
243243
zero_rates[0] = zero_rates[1]
@@ -256,8 +256,8 @@ def fit(self, times: np.ndarray, dfs: np.ndarray):
256256

257257
"""Second derivatives at left is zero and first derivative at
258258
right is clamped to zero."""
259-
g_small_vector = np.ones(len(self._times)) * g_small
260-
zero_rates = -np.log(self._dfs) / (self._times + g_small_vector)
259+
G_SMALL_vector = np.ones(len(self._times)) * G_SMALL
260+
zero_rates = -np.log(self._dfs) / (self._times + G_SMALL_vector)
261261

262262
if self._times[0] == 0.0:
263263
zero_rates[0] = zero_rates[1]
@@ -275,8 +275,8 @@ def fit(self, times: np.ndarray, dfs: np.ndarray):
275275
elif self._interp_type == InterpTypes.NATCUBIC_ZERO_RATES:
276276

277277
"""Second derivatives are clamped to zero at end points"""
278-
g_small_vector = np.ones(len(self._times)) * g_small
279-
zero_rates = -np.log(self._dfs) / (self._times + g_small_vector)
278+
G_SMALL_vector = np.ones(len(self._times)) * G_SMALL
279+
zero_rates = -np.log(self._dfs) / (self._times + G_SMALL_vector)
280280

281281
if self._times[0] == 0.0:
282282
zero_rates[0] = zero_rates[1]
@@ -323,8 +323,8 @@ def fit(self, times: np.ndarray, dfs: np.ndarray):
323323

324324
elif self._interp_type == InterpTypes.TENSION_ZERO_RATES:
325325
tension_sigma = self._optional_interp_params.get("sigma", 1.0)
326-
g_small_vector = np.ones(len(self._times)) * g_small
327-
zero_rates = -np.log(self._dfs) / (self._times + g_small_vector)
326+
G_SMALL_vector = np.ones(len(self._times)) * G_SMALL
327+
zero_rates = -np.log(self._dfs) / (self._times + G_SMALL_vector)
328328

329329
if self._times[0] == 0.0:
330330
zero_rates[0] = zero_rates[1]
@@ -349,7 +349,7 @@ def interpolate(self, t: float):
349349
print(t)
350350
raise FinError("Interpolate times must all be >= 0")
351351

352-
if np.abs(t) < g_small:
352+
if np.abs(t) < G_SMALL:
353353
return 1.0
354354

355355
tvec = np.array([t])

financepy/market/volatility/equity_vol_surface.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ...utils.error import FinError
1414
from ...utils.date import Date
15-
from ...utils.global_vars import g_days_in_year
15+
from ...utils.global_vars import G_DAYS_IN_YEARS
1616
from ...utils.global_types import OptionTypes
1717
from ...models.option_implied_dbn import option_implied_dbn
1818
from ...utils.helpers import check_argument_types, label_to_string
@@ -319,7 +319,7 @@ def vol_from_strike_date(self, K, expiry_dt):
319319
interpolation is done in variance space and then converted back to a
320320
lognormal volatility."""
321321

322-
t_exp = (expiry_dt - self.value_dt) / g_days_in_year
322+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
323323

324324
vol_type_value = self._vol_func_type.value
325325

@@ -394,7 +394,7 @@ def vol_from_strike_date(self, K, expiry_dt):
394394
# """ Interpolates the strike at a delta and expiry date. Linear
395395
# interpolation is used in strike."""
396396

397-
# t_exp = (expiry_dt - self.value_dt) / g_days_in_year
397+
# t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
398398

399399
# vol_type_value = self._vol_func_type.value
400400

@@ -496,7 +496,7 @@ def vol_from_delta_date(self, call_delta, expiry_dt, delta_method=None):
496496
interpolation is done in variance space and then converted back to a
497497
lognormal volatility."""
498498

499-
t_exp = (expiry_dt - self.value_dt) / g_days_in_year
499+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
500500

501501
vol_type_value = self._vol_func_type.value
502502

@@ -653,7 +653,7 @@ def _build_vol_surface(self, fin_solver_type=FinSolverTypes.NELDER_MEAD):
653653
for i in range(0, num_expiry_dts):
654654

655655
expiry_dt = self._expiry_dts[i]
656-
t_exp = (expiry_dt - spot_dt) / g_days_in_year
656+
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEARS
657657

658658
dis_df = self._discount_curve.df_t(t_exp)
659659
div_df = self._dividend_curve.df_t(t_exp)

financepy/market/volatility/fx_vol_surface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ...utils.error import FinError
1414
from ...utils.date import Date
15-
from ...utils.global_vars import g_days_in_year
15+
from ...utils.global_vars import G_DAYS_IN_YEARS
1616
from ...utils.global_types import OptionTypes
1717
from ...products.fx.fx_vanilla_option import FXVanillaOption
1818
from ...models.option_implied_dbn import option_implied_dbn
@@ -619,7 +619,7 @@ def volatility(self, K, expiry_dt):
619619
index0 = 0
620620
index1 = 0
621621

622-
t = (expiry_dt - self.value_dt) / g_days_in_year
622+
t = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
623623

624624
num_curves = self.num_vol_curves
625625

@@ -718,7 +718,7 @@ def build_vol_surface(self):
718718
for i in range(0, num_vol_curves):
719719

720720
expiry_dt = self.expiry_dts[i]
721-
t_exp = (expiry_dt - spot_dt) / g_days_in_year
721+
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEARS
722722

723723
dom_df = self.domestic_curve.df_t(t_exp)
724724
for_df = self.foreign_curve.df_t(t_exp)

financepy/market/volatility/fx_vol_surface_plus.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ...utils.error import FinError
1414
from ...utils.date import Date
15-
from ...utils.global_vars import g_days_in_year
15+
from ...utils.global_vars import G_DAYS_IN_YEARS
1616
from ...utils.global_types import OptionTypes
1717
from ...products.fx.fx_vanilla_option import FXVanillaOption
1818
from ...models.option_implied_dbn import option_implied_dbn
@@ -1346,7 +1346,7 @@ def vol_from_strike_date(self, K, expiry_dt):
13461346
interpolation is done in variance space and then converted back to a
13471347
lognormal volatility."""
13481348

1349-
t_exp = (expiry_dt - self.value_dt) / g_days_in_year
1349+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
13501350

13511351
vol_type_value = self.vol_func_type.value
13521352

@@ -1437,7 +1437,7 @@ def delta_to_strike(self, call_delta, expiry_dt, delta_method):
14371437
"""Interpolates the strike at a delta and expiry date. Linear
14381438
time to expiry interpolation is used in strike."""
14391439

1440-
t_exp = (expiry_dt - self.value_dt) / g_days_in_year
1440+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
14411441

14421442
vol_type_value = self.vol_func_type.value
14431443

@@ -1548,7 +1548,7 @@ def vol_from_delta_date(self, call_delta, expiry_dt, delta_method=None):
15481548
interpolation is done in variance space and then converted back to a
15491549
lognormal volatility."""
15501550

1551-
t_exp = (expiry_dt - self.value_dt) / g_days_in_year
1551+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
15521552

15531553
vol_type_value = self.vol_func_type.value
15541554

@@ -1734,7 +1734,7 @@ def _build_vol_surface(self, fin_solver_type=FinSolverTypes.NELDER_MEAD, tol=1e-
17341734
for i in range(0, num_vol_curves):
17351735

17361736
expiry_dt = self.expiry_dts[i]
1737-
t_exp = (expiry_dt - spot_dt) / g_days_in_year
1737+
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEARS
17381738

17391739
dom_df = self.domestic_curve.df(expiry_dt)
17401740
for_df = self.foreign_curve.df(expiry_dt)

0 commit comments

Comments
 (0)