Skip to content

Commit

Permalink
Run autopep8 linter to make code PEP8 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
VFermat committed Nov 5, 2021
1 parent be79a79 commit 293eee3
Show file tree
Hide file tree
Showing 182 changed files with 3,424 additions and 3,162 deletions.
10 changes: 6 additions & 4 deletions docs/makeUserGuide.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,11 @@ def parseFunction(lines, startLine, endLine, className=""):

missingSpaces = len(className) - len("__init__")
if (missingSpaces >= 0):
functionSignature = functionSignature.replace("\n ", "\n " + " " * (missingSpaces))
functionSignature = functionSignature.replace(
"\n ", "\n " + " " * (missingSpaces))
else:
functionSignature = functionSignature.replace("\n" + " " * (-missingSpaces), "\n")
functionSignature = functionSignature.replace(
"\n" + " " * (-missingSpaces), "\n")

# Remove 'self' and any whitespace following it
functionSignature = functionSignature.replace("self", "")
Expand Down Expand Up @@ -628,7 +630,6 @@ def parseFunction(lines, startLine, endLine, className=""):
# This is because we remove trailing whitespace
functionComment += line + " "


if functionComment == "":
functionComment = "PLEASE ADD A FUNCTION DESCRIPTION"

Expand Down Expand Up @@ -710,7 +711,8 @@ def extractParams(functionSignature):
functionSignature = functionSignature.replace("%", "\%")

# Remove information that isn't to do with the parameters
stripedSignature = functionSignature.split("(", 1)[1].replace("):", "").strip()
stripedSignature = functionSignature.split(
"(", 1)[1].replace("):", "").strip()
if stripedSignature == "":
# The function has no parameters
return ""
Expand Down
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.204') + " - This build: 02 Nov 2021 at 10:17 #" + cr
s += "# FINANCEPY BETA Version " + str('0.204') + " - This build: 05 Nov 2021 at 09:38 #" + cr
s += "# This software is distributed FREE & WITHOUT ANY WARRANTY #" + cr
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
s += "####################################################################"
Expand Down
1 change: 0 additions & 1 deletion financepy/market/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

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

def _zero_to_df(self,
valuation_date: Date,
rates: (float, np.ndarray),
times: (float, np.ndarray),
freq_type: FrequencyTypes,
day_count_type: DayCountTypes):
valuation_date: Date,
rates: (float, np.ndarray),
times: (float, np.ndarray),
freq_type: FrequencyTypes,
day_count_type: DayCountTypes):
""" Convert a zero with a specified compounding frequency and day count
convention to a discount factor for a single maturity date or a list of
dates. The day count is used to calculate the elapsed year fraction."""
Expand Down Expand Up @@ -118,10 +118,10 @@ def _zero_to_df(self,
###############################################################################

def _df_to_zero(self,
dfs: (float, np.ndarray),
maturityDts: (Date, list),
freq_type: FrequencyTypes,
day_count_type: DayCountTypes):
dfs: (float, np.ndarray),
maturityDts: (Date, list),
freq_type: FrequencyTypes,
day_count_type: DayCountTypes):
""" Given a dates this first generates the discount factors. It then
converts the discount factors to a zero rate with a chosen compounding
frequency which may be continuous, simple, or compounded at a specific
Expand All @@ -146,7 +146,8 @@ def _df_to_zero(self,
num_dates = len(dateList)
zero_rates = []

times = times_from_dates(dateList, self._valuation_date, day_count_type)
times = times_from_dates(
dateList, self._valuation_date, day_count_type)

for i in range(0, num_dates):

Expand All @@ -168,9 +169,9 @@ def _df_to_zero(self,
###############################################################################

def zero_rate(self,
dts: (list, Date),
freq_type: FrequencyTypes = FrequencyTypes.CONTINUOUS,
day_count_type: DayCountTypes = DayCountTypes.ACT_360):
dts: (list, Date),
freq_type: FrequencyTypes = FrequencyTypes.CONTINUOUS,
day_count_type: DayCountTypes = DayCountTypes.ACT_360):
""" Calculation of zero rates with specified frequency. This
function can return a vector of zero rates given a vector of
dates so must use Numpy functions. Default frequency is a
Expand All @@ -195,22 +196,23 @@ def zero_rate(self,
###############################################################################

def cc_rate(self,
dts: (list, Date),
day_count_type: DayCountTypes = DayCountTypes.SIMPLE):
dts: (list, Date),
day_count_type: DayCountTypes = DayCountTypes.SIMPLE):
""" Calculation of zero rates with continuous compounding. This
function can return a vector of cc rates given a vector of
dates so must use Numpy functions. """

cc_rates = self.zero_rate(dts, FrequencyTypes.CONTINUOUS, day_count_type)
cc_rates = self.zero_rate(
dts, FrequencyTypes.CONTINUOUS, day_count_type)
return cc_rates

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

def swap_rate(self,
effective_date: Date,
maturity_date: (list, Date),
freq_type=FrequencyTypes.ANNUAL,
day_count_type: DayCountTypes = DayCountTypes.THIRTY_E_360):
effective_date: Date,
maturity_date: (list, Date),
freq_type=FrequencyTypes.ANNUAL,
day_count_type: DayCountTypes = DayCountTypes.THIRTY_E_360):
""" Calculate the swap rate to maturity date. This is the rate paid by
a swap that has a price of par today. This is the same as a Libor swap
rate except that we do not do any business day adjustments. """
Expand Down Expand Up @@ -282,7 +284,7 @@ def swap_rate(self,

def df(self,
dt: (list, Date),
day_count = DayCountTypes.ACT_ACT_ISDA):
day_count=DayCountTypes.ACT_ACT_ISDA):
""" Function to calculate a discount factor from a date or a
vector of dates. The day count determines how dates get converted to
years. I allow this to default to ACT_ACT_ISDA unless specified. """
Expand Down Expand Up @@ -320,7 +322,7 @@ def _df(self,
###############################################################################

def survival_prob(self,
dt: Date):
dt: Date):
""" This returns a survival probability to a specified date based on
the assumption that the continuously compounded rate is a default
hazard rate in which case the survival probability is directly
Expand Down Expand Up @@ -450,7 +452,7 @@ def __repr__(self):
s += label_to_string("DATES", "DISCOUNT FACTORS")
for i in range(0, num_points):
s += label_to_string("%12s" % self._df_dates[i],
"%12.8f" % self._dfs[i])
"%12.8f" % self._dfs[i])

return s

Expand Down
11 changes: 6 additions & 5 deletions financepy/market/curves/discount_curve_flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def __init__(self,

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

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

Expand Down Expand Up @@ -90,10 +91,10 @@ def df(self,
self._day_count_type)

dfs = self._zero_to_df(self._valuation_date,
self._flat_rate,
dc_times,
self._freq_type,
self._day_count_type)
self._flat_rate,
dc_times,
self._freq_type,
self._day_count_type)

if isinstance(dates, Date):
return dfs[0]
Expand Down
22 changes: 11 additions & 11 deletions financepy/market/curves/discount_curve_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ def zero_rate(self,

# Now get the discount factors using curve conventions
dfs = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

# Convert these to zero rates in the required frequency and day count
zero_rates = self._df_to_zero(dfs,
dates,
freq_type,
day_count_type)
dates,
freq_type,
day_count_type)

return zero_rates

Expand Down Expand Up @@ -128,10 +128,10 @@ def df(self,
zero_rates = self._zero_rate(dc_times)

df = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

return df

Expand Down
22 changes: 11 additions & 11 deletions financepy/market/curves/discount_curve_nss.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ def zero_rate(self,

# Now get the discount factors using curve conventions
dfs = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

# Convert these to zero rates in the required frequency and day count
zero_rates = self._df_to_zero(dfs,
dates,
freq_type,
day_count_type)
dates,
freq_type,
day_count_type)

if isinstance(dates, Date):
return zero_rates[0]
Expand Down Expand Up @@ -142,10 +142,10 @@ def df(self,
zero_rates = self._zero_rate(dc_times)

df = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

if isinstance(dates, Date):
return df[0]
Expand Down
19 changes: 10 additions & 9 deletions financepy/market/curves/discount_curve_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ def zero_rate(self,
raise FinError("Invalid Day Count type.")

# Get day count times to use with curve day count convention
dc_times = times_from_dates(dts, self._valuation_date, self._day_count_type)
dc_times = times_from_dates(
dts, self._valuation_date, self._day_count_type)

# We now get the discount factors using these times
zero_rates = self._zero_rate(dc_times)

# Now get the discount factors using curve conventions
dfs = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

# Convert these to zero rates in the required frequency and day count
zero_rates = self._df_to_zero(dfs, dts, freq_type, day_count_type)
Expand Down Expand Up @@ -115,10 +116,10 @@ def df(self,

# Now get the discount factors using curve conventions
dfs = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

return dfs

Expand Down
8 changes: 4 additions & 4 deletions financepy/market/curves/discount_curve_pwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def df(self,
zero_rates = self._zero_rate(dc_times)

df = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

return df

Expand Down
8 changes: 4 additions & 4 deletions financepy/market/curves/discount_curve_pwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def df(self,
zero_rates = self._zero_rate(dc_times)

df = self._zero_to_df(self._valuation_date,
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)
zero_rates,
dc_times,
self._freq_type,
self._day_count_type)

return df

Expand Down
14 changes: 7 additions & 7 deletions financepy/market/curves/discount_curve_zeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ def __init__(self,
self._zero_rates = np.array(zero_rates)
self._zero_dates = zero_dates

self._times = times_from_dates(zero_dates, valuation_date, day_count_type)
self._times = times_from_dates(
zero_dates, valuation_date, day_count_type)

if test_monotonicity(self._times) is False:
raise FinError("Times or dates are not sorted in increasing order")

dfs = self._zero_to_df(self._valuation_date,
self._zero_rates,
self._times,
self._freq_type,
self._day_count_type)
self._zero_rates,
self._times,
self._freq_type,
self._day_count_type)

self._dfs = np.array(dfs)
self._interpolator = Interpolator(self._interp_type)
Expand Down Expand Up @@ -118,7 +119,7 @@ def __repr__(self):
num_points = len(self._times)
for i in range(0, num_points):
s += label_to_string("%12s" % self._zero_dates[i],
"%10.7f" % self._zero_rates[i])
"%10.7f" % self._zero_rates[i])

return s

Expand All @@ -129,4 +130,3 @@ def _print(self):
print(self)

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

1 change: 0 additions & 1 deletion financepy/market/prices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-

2 changes: 0 additions & 2 deletions financepy/market/volatility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
from .fx_vol_surface import *
from .fx_vol_surface_plus import *
from .ibor_cap_vol_curve import *


Loading

0 comments on commit 293eee3

Please sign in to comment.