Skip to content

Commit

Permalink
Pep8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
domokane committed Feb 22, 2024
1 parent 34e3181 commit 773bfc7
Show file tree
Hide file tree
Showing 278 changed files with 5,743 additions and 5,656 deletions.
Binary file modified FinancePyManual.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion financepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cr = "\n"

s = "####################################################################" + cr
s += "# FINANCEPY BETA Version " + str('0.34') + " - This build: 19 Feb 2024 at 21:02 #" + cr
s += "# FINANCEPY BETA Version " + str('0.350') + " - This build: 22 Feb 2024 at 19:25 #" + cr
s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
s += "####################################################################"
Expand Down
2 changes: 1 addition & 1 deletion financepy/__init__.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cr = "\n"

s = "####################################################################" + cr
s += "# FINANCEPY BETA Version " + str(__version__) + " - This build: __dateandtime__ #" + cr
s += "# FINANCEPY BETA Version " + str(__version__) + " - This build: __dateandtime__ #" + cr
s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
s += "####################################################################"
Expand Down
22 changes: 11 additions & 11 deletions financepy/market/curves/discount_curve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
###############################################################################
# Copyright (C) 2018, 2019, 2020 Dominic O'Kane
##############################################################################
###############################################################################


import numpy as np
Expand All @@ -9,7 +9,7 @@

from ...utils.date import Date
from ...utils.error import FinError
from ...utils.global_vars import gDaysInYear, gSmall
from ...utils.global_vars import gDaysInYear, g_small
from ...utils.frequency import annual_frequency, FrequencyTypes
from ...utils.day_count import DayCount, DayCountTypes
from ...utils.math import test_monotonicity
Expand Down Expand Up @@ -89,7 +89,7 @@ def value_dt(self):
###########################################################################

def _zero_to_df(self,
value_dt: Date, # TODO: why is value_date not used ?
value_dt: Date, # TODO: why is value_dt not used ?
rates: (float, np.ndarray),
times: (float, np.ndarray),
freq_type: FrequencyTypes,
Expand All @@ -101,7 +101,7 @@ def _zero_to_df(self,
if isinstance(times, float):
times = np.array([times])

t = np.maximum(times, gSmall)
t = np.maximum(times, g_small)

f = annual_frequency(freq_type)

Expand Down Expand Up @@ -147,17 +147,17 @@ def _df_to_zero(self,
if len(date_list) != len(df_list):
raise FinError("Date list and df list do not have same length")

num_dts = len(date_list)
num_dates = len(date_list)
zero_rates = []

times = times_from_dates(
date_list, self._value_dt, dc_type)

for i in range(0, num_dts):
for i in range(0, num_dates):

df = df_list[i]

t = max(times[i], gSmall)
t = max(times[i], g_small)

if freq_type == FrequencyTypes.CONTINUOUS:
r = -np.log(df) / t
Expand Down Expand Up @@ -269,7 +269,7 @@ def swap_rate(self,
pv01 += alpha * df
prev_dt = next_dt

if abs(pv01) < gSmall:
if abs(pv01) < g_small:
par_rate = 0.0
else:
df_start = self.df(effective_dt)
Expand Down Expand Up @@ -424,9 +424,9 @@ def fwd_rate(self,

day_count = DayCount(dc_type)

num_dts = len(start_dts)
num_dates = len(start_dts)
fwd_rates = []
for i in range(0, num_dts):
for i in range(0, num_dates):
dt1 = start_dts[i]

if isinstance(date_or_tenor, str):
Expand Down
4 changes: 2 additions & 2 deletions financepy/market/curves/discount_curve_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils.date import Date
from ...utils.frequency import FrequencyTypes
from ...utils.global_vars import gSmall
from ...utils.global_vars import g_small
from ...utils.error import FinError
from ...market.curves.discount_curve import DiscountCurve
from ...utils.helpers import check_argument_types
Expand Down Expand Up @@ -101,7 +101,7 @@ def _zero_rate(self,
""" Zero rate for Nelson-Siegel curve parametrisation. This means that
the t vector must use the curve day count."""

t = np.maximum(times, gSmall)
t = np.maximum(times, g_small)

theta = t / self._tau
e = np.exp(-theta)
Expand Down
4 changes: 2 additions & 2 deletions financepy/market/curves/discount_curve_nss.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils.date import Date
from ...utils.frequency import FrequencyTypes
from ...utils.global_vars import gSmall
from ...utils.global_vars import g_small
from ...utils.helpers import label_to_string
from ...utils.error import FinError
from ...market.curves.discount_curve import DiscountCurve
Expand Down Expand Up @@ -112,7 +112,7 @@ def _zero_rate(self,
times. This function can return a single zero rate or a vector of zero
rates. The compounding frequency must be provided. """

t = np.maximum(times, gSmall)
t = np.maximum(times, g_small)

theta_1 = t / self._tau_1
theta_2 = t / self._tau_2
Expand Down
4 changes: 2 additions & 2 deletions financepy/market/curves/discount_curve_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils.date import Date
from ...utils.error import FinError
from ...utils.global_vars import gSmall
from ...utils.global_vars import g_small
from ...utils.helpers import label_to_string
from ...market.curves.discount_curve import DiscountCurve
from ...utils.helpers import check_argument_types
Expand Down Expand Up @@ -89,7 +89,7 @@ def _zero_rate(self,
use. The compounding frequency defaults to that specified in the
constructor of the curve object. Which may be annual to continuous. """

t = np.maximum(times, gSmall)
t = np.maximum(times, g_small)

zero_rate = 0.0
for n in range(0, len(self._coefficients)):
Expand Down
4 changes: 2 additions & 2 deletions financepy/market/curves/discount_curve_pwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils.date import Date
from ...utils.error import FinError
from ...utils.global_vars import gSmall
from ...utils.global_vars import g_small
from ...utils.math import test_monotonicity
from ...utils.frequency import FrequencyTypes
from ...utils.helpers import label_to_string
Expand Down Expand Up @@ -69,7 +69,7 @@ def _zero_rate(self,
if np.any(times < 0.0):
raise FinError("All times must be positive")

times = np.maximum(times, gSmall)
times = np.maximum(times, g_small)

zero_rates = []

Expand Down
11 changes: 5 additions & 6 deletions financepy/market/curves/interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
from scipy.interpolate import PchipInterpolator
from scipy.interpolate import CubicSpline
from ...utils.error import FinError
from ...utils.global_vars import gSmall
from ...utils.global_vars import g_small

###############################################################################


class InterpTypes(Enum):
''' Types of interpolation '''
FLAT_FWD_RATES = 1
LINEAR_FWD_RATES = 2
LINEAR_ZERO_RATES = 4
Expand Down Expand Up @@ -223,7 +222,7 @@ def fit(self,

elif self._interp_type == InterpTypes.PCHIP_ZERO_RATES:

g_small_vector = np.ones(len(self._times)) * gSmall
g_small_vector = np.ones(len(self._times)) * g_small
zero_rates = -np.log(self._dfs) / (self._times + g_small_vector)

if self._times[0] == 0.0:
Expand All @@ -243,7 +242,7 @@ def fit(self,

""" Second derivatives at left is zero and first derivative at
right is clamped to zero. """
g_small_vector = np.ones(len(self._times)) * gSmall
g_small_vector = np.ones(len(self._times)) * g_small
zero_rates = -np.log(self._dfs) / (self._times + g_small_vector)

if self._times[0] == 0.0:
Expand All @@ -262,7 +261,7 @@ def fit(self,
elif self._interp_type == InterpTypes.NATCUBIC_ZERO_RATES:

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

if self._times[0] == 0.0:
Expand Down Expand Up @@ -294,7 +293,7 @@ def interpolate(self,
print(t)
raise FinError("Interpolate times must all be >= 0")

if np.abs(t) < gSmall:
if np.abs(t) < g_small:
return 1.0

tvec = np.array([t])
Expand Down
Loading

0 comments on commit 773bfc7

Please sign in to comment.