Skip to content

Commit

Permalink
formatting based on the .pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Dec 7, 2024
1 parent ffb77bc commit 081b5ac
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.8.1'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.30.0
hooks:
- id: check-dependabot
args: ["--verbose"]
- id: check-github-workflows
args: ["--verbose"]
2 changes: 1 addition & 1 deletion pypfopt/black_litterman.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(
view_confidences=None,
tau=0.05,
risk_aversion=1,
**kwargs
**kwargs,
):
"""
:param cov_matrix: NxN covariance matrix of returns
Expand Down
16 changes: 8 additions & 8 deletions pypfopt/cla.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ def _solve(self):
covarF_inv = np.linalg.inv(covarF)
j = 0
for i in f:
l, bi = self._compute_lambda(
lamb, bi = self._compute_lambda(
covarF_inv, covarFB, meanF, wB, j, [self.lB[i], self.uB[i]]
)
if CLA._infnone(l) > CLA._infnone(l_in):
l_in, i_in, bi_in = l, i, bi
if CLA._infnone(lamb) > CLA._infnone(l_in):
l_in, i_in, bi_in = lamb, i, bi
j += 1
# 2) case b): Free one bounded weight
l_out = None
Expand All @@ -327,18 +327,18 @@ def _solve(self):
for i in b:
covarF, covarFB, meanF, wB = self._get_matrices(f + [i])
covarF_inv = np.linalg.inv(covarF)
l, bi = self._compute_lambda(
lamb, bi = self._compute_lambda(
covarF_inv,
covarFB,
meanF,
wB,
meanF.shape[0] - 1,
self.w[-1][i],
)
if (self.ls[-1] is None or l < self.ls[-1]) and l > CLA._infnone(
l_out
):
l_out, i_out = l, i
if (
self.ls[-1] is None or lamb < self.ls[-1]
) and lamb > CLA._infnone(l_out):
l_out, i_out = lamb, i
if (l_in is None or l_in < 0) and (l_out is None or l_out < 0):
# 3) compute minimum variance solution
self.ls.append(0)
Expand Down
2 changes: 1 addition & 1 deletion pypfopt/discrete_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
self.latest_prices = latest_prices
self.total_portfolio_value = total_portfolio_value
if short_ratio is None:
self.short_ratio = sum((-x[1] for x in self.weights if x[1] < 0))
self.short_ratio = sum(-x[1] for x in self.weights if x[1] < 0)
else:
self.short_ratio = short_ratio

Expand Down
4 changes: 2 additions & 2 deletions pypfopt/risk_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def semicovariance(
benchmark=0.000079,
frequency=252,
log_returns=False,
**kwargs
**kwargs,
):
"""
Estimate the semicovariance matrix, i.e the covariance given that
Expand Down Expand Up @@ -290,7 +290,7 @@ def min_cov_determinant(
frequency=252,
random_state=None,
log_returns=False,
**kwargs
**kwargs,
): # pragma: no cover
warnings.warn("min_cov_determinant is deprecated and will be removed in v1.5")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_base_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ def test_save_weights_to_file():
json.dump(weights, f)

# Test reading
with open(test_file_path_txt, "r") as f:
with open(test_file_path_txt) as f:
parsed = json.load(f)
assert ef.clean_weights() == parsed

ef.save_weights_to_file(test_file_path_json)
with open(test_file_path_json, "r") as f:
with open(test_file_path_json) as f:
parsed = json.load(f)
assert ef.clean_weights() == parsed

ef.save_weights_to_file(test_file_path_csv)
with open(test_file_path_csv, "r") as f:
with open(test_file_path_csv) as f:
df = pd.read_csv(
f,
header=None,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def test_dendrogram_plot():

ax = plotting.plot_dendrogram(hrp, showfig=False)
assert len(ax.findobj()) > 180
assert type(ax.findobj()[0]) == matplotlib.collections.LineCollection
assert isinstance(ax.findobj()[0], matplotlib.collections.LineCollection)
plt.clf()

ax = plotting.plot_dendrogram(hrp, show_tickers=False, showfig=False)
assert len(ax.findobj()) > 60
assert type(ax.findobj()[0]) == matplotlib.collections.LineCollection
assert isinstance(ax.findobj()[0], matplotlib.collections.LineCollection)
plt.clf()
plt.close()

Expand All @@ -78,7 +78,7 @@ def test_dendrogram_plot():
== "hrp param has not been optimized. Attempting optimization."
)
assert len(ax.findobj()) > 60
assert type(ax.findobj()[0]) == matplotlib.collections.LineCollection
assert isinstance(ax.findobj()[0], matplotlib.collections.LineCollection)
plt.clf()
plt.close()

Expand Down

0 comments on commit 081b5ac

Please sign in to comment.