Skip to content

Commit

Permalink
FIles amended to pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
domokane committed Dec 4, 2023
1 parent a2b270d commit 24cdd62
Show file tree
Hide file tree
Showing 20 changed files with 937 additions and 314 deletions.
636 changes: 636 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions financepy/market/curves/discount_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self,
###########################################################################

def _zero_to_df(self,
value_dt: Date,
value_dt: Date, #TODO: why is value_date not used ?
rates: (float, np.ndarray),
times: (float, np.ndarray),
freq_type: FrequencyTypes,
Expand Down Expand Up @@ -342,15 +342,15 @@ def fwd(self,
one date. """

if isinstance(dts, Date):
dtsPlusOneDays = [dts.add_days(1)]
dts_plus_one_days = [dts.add_days(1)]
else:
dtsPlusOneDays = []
dts_plus_one_days = []
for dt in dts:
dtsPlusOneDay = dt.add_days(1)
dtsPlusOneDays.append(dtsPlusOneDay)
dts_plus_one_day = dt.add_days(1)
dts_plus_one_days.append(dts_plus_one_day)

df1 = self.df(dts)
df2 = self.df(dtsPlusOneDays)
df2 = self.df(dts_plus_one_days)
dt = 1.0 / gDaysInYear
fwd = np.log(df1 / df2) / (1.0 * dt)

Expand Down Expand Up @@ -392,12 +392,12 @@ def bump(self,
t = times[i]
values[i] = values[i] * np.exp(-bump_size * t)

discCurve = DiscountCurve(self._value_dt,
times,
values,
self._interp_type)
disc_curve = DiscountCurve(self._value_dt,
times,
values,
self._interp_type)

return discCurve
return disc_curve

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

Expand Down
26 changes: 13 additions & 13 deletions financepy/market/curves/discount_curve_flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def __init__(self,

# Need to set up a grid of times and discount factors
years = np.linspace(0.0, 10.0, 41)
dates = self._value_dt.add_years(years)
dts = self._value_dt.add_years(years)

# Set up a grid of times and discount factors for functions
self._dfs = self.df(dates)
self._times = times_from_dates(dates, self._value_dt, dc_type)
self._dfs = self.df(dts)
self._times = times_from_dates(dts, self._value_dt, dc_type)

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

Expand All @@ -67,25 +67,25 @@ def bump(self,
""" Creates a new FinDiscountCurveFlat object with the entire curve
bumped up by the bumpsize. All other parameters are preserved."""

rBumped = self._flat_rate + bump_size
discCurve = DiscountCurveFlat(self._value_dt,
rBumped,
freq_type=self._freq_type,
dc_type=self._dc_type)
return discCurve
rate_bumped = self._flat_rate + bump_size
disc_curve = DiscountCurveFlat(self._value_dt,
rate_bumped,
freq_type=self._freq_type,
dc_type=self._dc_type)
return disc_curve

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

def df(self,
dates: (Date, list)):
""" Return discount factors given a single or vector of dates. The
dts: (Date, list)):
""" Return discount factors given a single or vector of dts. The
discount factor depends on the rate and this in turn depends on its
compounding frequency and it defaults to continuous compounding. It
also depends on the day count convention. This was set in the
construction of the curve to be ACT_ACT_ISDA. """

# Get day count times to use with curve day count convention
dc_times = times_from_dates(dates,
dc_times = times_from_dates(dts,
self._value_dt,
self._dc_type)

Expand All @@ -95,7 +95,7 @@ def df(self,
self._freq_type,
self._dc_type)

if isinstance(dates, Date):
if isinstance(dts, Date):
return dfs[0]
else:
return np.array(dfs)
Expand Down
4 changes: 2 additions & 2 deletions financepy/market/curves/discount_curve_zeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def __init__(self,
# t = times[i]
# discount_factors[i] = discount_factors[i] * np.exp(-bump_size*t)

# discCurve = FinDiscountCurve(self._value_dt, times,
# disc_curve = FinDiscountCurve(self._value_dt, times,
# discount_factors,
# self._interp_type)

# return discCurve
# return disc_curve

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

Expand Down
16 changes: 8 additions & 8 deletions financepy/market/curves/interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def fit(self,

if self._interp_type == InterpTypes.PCHIP_LOG_DISCOUNT:

logDfs = np.log(self._dfs)
self._interp_fn = PchipInterpolator(self._times, logDfs)
log_dfs = np.log(self._dfs)
self._interp_fn = PchipInterpolator(self._times, log_dfs)

elif self._interp_type == InterpTypes.PCHIP_ZERO_RATES:

Expand All @@ -236,8 +236,8 @@ def fit(self,

# """ Second derivatives at left is zero and first derivative at
# right is clamped to zero. """
# logDfs = np.log(self._dfs)
# self._interp_fn = CubicSpline(self._times, logDfs,
# log_dfs = np.log(self._dfs)
# self._interp_fn = CubicSpline(self._times, log_dfs,
# bc_type=((2, 0.0), (1, 0.0)))

elif self._interp_type == InterpTypes.FINCUBIC_ZERO_RATES:
Expand All @@ -256,8 +256,8 @@ def fit(self,
elif self._interp_type == InterpTypes.NATCUBIC_LOG_DISCOUNT:

""" Second derivatives are clamped to zero at end points """
logDfs = np.log(self._dfs)
self._interp_fn = CubicSpline(self._times, logDfs,
log_dfs = np.log(self._dfs)
self._interp_fn = CubicSpline(self._times, log_dfs,
bc_type='natural')

elif self._interp_type == InterpTypes.NATCUBIC_ZERO_RATES:
Expand All @@ -274,8 +274,8 @@ def fit(self,

# elif self._interp_type == InterpTypes.LINEAR_LOG_DISCOUNT:
#
# logDfs = np.log(self._dfs)
# self._interp_fn = interp1d(self._times, logDfs,
# log_dfs = np.log(self._dfs)
# self._interp_fn = interp1d(self._times, log_dfs,
# fill_value="extrapolate")

###########################################################################
Expand Down
22 changes: 11 additions & 11 deletions financepy/market/volatility/equity_vol_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def _delta_fit(k, *args):
v = vol_function(vol_type_value, params, f, k, t)
delta_out = bs_delta(s, t, k, r, q, v, option_type_value)
inverse_delta_out = norminvcdf(np.abs(delta_out))
invObjFn = inverse_delta_target - inverse_delta_out
inv_obj_fn = inverse_delta_target - inverse_delta_out

return invObjFn
return inv_obj_fn

###############################################################################
# Unable to cache this function due to dynamic globals warning. Revisit.
Expand Down Expand Up @@ -709,10 +709,10 @@ def implied_dbns(self, lowS, highS, numIntervals):
dS = (highS - lowS) / numIntervals

disDF = self._discount_curve._df(t)
divDF = self._dividend_curve._df(t)
div_df = self._dividend_curve._df(t)

r = -np.log(disDF) / t
q = -np.log(divDF) / t
q = -np.log(div_df) / t

Ks = []
vols = []
Expand Down Expand Up @@ -747,9 +747,9 @@ def plot_vol_curves(self):
lowK = self._strikes[0] * 0.9
highK = self._strikes[-1] * 1.1

for tenorIndex in range(0, self._numExpiryDates):
for tenor_index in range(0, self._numExpiryDates):

expiry_dt = self._expiry_dts[tenorIndex]
expiry_dt = self._expiry_dts[tenor_index]
plt.figure()

ks = []
Expand All @@ -766,12 +766,12 @@ def plot_vol_curves(self):
fitted_vols.append(fittedVol)
K = K + dK

labelStr = "FITTED AT " + str(self._expiry_dts[tenorIndex])
plt.plot(ks, fitted_vols, label=labelStr)
label_str = "FITTED AT " + str(self._expiry_dts[tenor_index])
plt.plot(ks, fitted_vols, label=label_str)

labelStr = "MARKET AT " + str(self._expiry_dts[tenorIndex])
mkt_vols = self._volatility_grid[tenorIndex] * 100.0
plt.plot(self._strikes, mkt_vols, 'o', label=labelStr)
label_str = "MARKET AT " + str(self._expiry_dts[tenor_index])
mkt_vols = self._volatility_grid[tenor_index] * 100.0
plt.plot(self._strikes, mkt_vols, 'o', label=label_str)

plt.xlabel("Strike")
plt.ylabel("Volatility")
Expand Down
Loading

0 comments on commit 24cdd62

Please sign in to comment.