Skip to content

Commit 2b1e7b3

Browse files
Fix black formatting with line-length 100
1 parent b897f53 commit 2b1e7b3

5 files changed

Lines changed: 10 additions & 30 deletions

File tree

classical/greedy.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def load_portfolio_data(
3232
sigma = np.load(os.path.join(cached_dir, "sigma.npy"))
3333

3434
# Load stock names from CSV
35-
expected_returns_df = pd.read_csv(
36-
os.path.join(cached_dir, "expected_returns.csv"), index_col=0
37-
)
35+
expected_returns_df = pd.read_csv(os.path.join(cached_dir, "expected_returns.csv"), index_col=0)
3836
stock_names = expected_returns_df.index.tolist()
3937

4038
return mu, sigma, stock_names

classical/sim_annealing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import math
44

55

6-
def simulated_annealing_qubo(
7-
Q, k, T_start=1000.0, cooling_rate=0.99, max_iter=10000, seed=None
8-
):
6+
def simulated_annealing_qubo(Q, k, T_start=1000.0, cooling_rate=0.99, max_iter=10000, seed=None):
97
"""
108
Simulated Annealing heuristic for the QUBO formulation of the portfolio problem.
119
Maintains exactly k selected assets at all times to satisfy the constraint naturally.

classical/test_classical.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,4 @@ def test_sa_better_than_random(Q_matrix):
137137
random_objs.append(compute_objective(Q, x))
138138

139139
avg_random = np.mean(random_objs)
140-
assert (
141-
sa_obj <= avg_random
142-
), f"SA obj {sa_obj:.4f} worse than random avg {avg_random:.4f}"
140+
assert sa_obj <= avg_random, f"SA obj {sa_obj:.4f} worse than random avg {avg_random:.4f}"

data/preprocess.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def load_prices(input_dir):
7676
"""
7777
csv_files = glob.glob(os.path.join(input_dir, "*.csv"))
7878
if not csv_files:
79-
raise FileNotFoundError(
80-
f"No CSV files found in '{input_dir}'. Run fetch_data.py first."
81-
)
79+
raise FileNotFoundError(f"No CSV files found in '{input_dir}'. Run fetch_data.py first.")
8280

8381
adj_close_data = {}
8482
for file in csv_files:
@@ -95,9 +93,7 @@ def load_prices(input_dir):
9593
elif "Close" in df.columns:
9694
adj_close_data[ticker] = df["Close"]
9795
else:
98-
print(
99-
f" ⚠ Could not find Close prices for {ticker}. Columns: {list(df.columns)}"
100-
)
96+
print(f" ⚠ Could not find Close prices for {ticker}. Columns: {list(df.columns)}")
10197

10298
if not adj_close_data:
10399
raise ValueError("No valid price data could be loaded from any CSV file.")
@@ -201,13 +197,9 @@ def compute_correlation(returns_df):
201197
print(f" Mean correlation: {corr_flat.mean():.4f}")
202198

203199
if corr_flat.mean() > 0.6:
204-
print(
205-
"\n💡 Portfolio Insight: HIGH average correlation → Limited diversification"
206-
)
200+
print("\n💡 Portfolio Insight: HIGH average correlation → Limited diversification")
207201
elif corr_flat.mean() > 0.4:
208-
print(
209-
"\n💡 Portfolio Insight: MODERATE average correlation → Some diversification"
210-
)
202+
print("\n💡 Portfolio Insight: MODERATE average correlation → Some diversification")
211203
else:
212204
print("\n💡 Portfolio Insight: LOW average correlation → Good diversification")
213205

@@ -276,19 +268,15 @@ def plot_return_distributions(returns_df, results_dir):
276268
axes = axes.flatten()
277269

278270
for idx, stock in enumerate(returns_df.columns):
279-
axes[idx].hist(
280-
returns_df[stock], bins=50, alpha=0.7, color="steelblue", edgecolor="black"
281-
)
271+
axes[idx].hist(returns_df[stock], bins=50, alpha=0.7, color="steelblue", edgecolor="black")
282272
axes[idx].axvline(
283273
returns_df[stock].mean(),
284274
color="red",
285275
linestyle="--",
286276
linewidth=2,
287277
label="Mean",
288278
)
289-
axes[idx].set_title(
290-
f"{stock} – Daily Log Return Distribution", fontweight="bold"
291-
)
279+
axes[idx].set_title(f"{stock} – Daily Log Return Distribution", fontweight="bold")
292280
axes[idx].set_xlabel("Daily Log Return")
293281
axes[idx].set_ylabel("Frequency")
294282
axes[idx].legend()

qaoa/test_circuit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ def test_circuit_depth_increases_with_p(simple_Q):
6969
"""Deeper p should produce a deeper circuit."""
7070
c1, _, _ = create_qaoa_circuit(simple_Q, p=1)
7171
c2, _, _ = create_qaoa_circuit(simple_Q, p=2)
72-
assert (
73-
c2.decompose().depth() > c1.decompose().depth()
74-
), "p=2 circuit should be deeper than p=1"
72+
assert c2.decompose().depth() > c1.decompose().depth(), "p=2 circuit should be deeper than p=1"
7573

7674

7775
def test_circuit_has_measurements(simple_Q):

0 commit comments

Comments
 (0)