Skip to content

Commit aaa94dd

Browse files
committed
fix: remove trailing whitespace (ruff W293)
1 parent 34917f8 commit aaa94dd

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/quant_research_starter/backtest/vectorized.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ def run(self, weight_scheme: str = "rank") -> Dict:
7171
# Track rebalancing
7272
prev_rebalance_date = None
7373
current_weights = pd.Series(0.0, index=self.prices.columns)
74-
74+
7575
# Compute daily weights from signals (rebalance only on rebalance dates)
7676
weights_list = []
7777
for date in returns_df.index:
7878
if self._should_rebalance(date, prev_rebalance_date):
7979
# Rebalance: compute new target weights
8080
current_weights = self._calculate_weights(aligned_signals.loc[date], weight_scheme)
8181
prev_rebalance_date = date
82-
82+
8383
# Append current weights (maintain between rebalances)
8484
weights_list.append(current_weights)
85-
85+
8686
weights = pd.DataFrame(weights_list, index=returns_df.index, columns=self.prices.columns).fillna(0.0)
8787

8888
# Previous day weights for PnL calculation
@@ -116,18 +116,18 @@ def run(self, weight_scheme: str = "rank") -> Dict:
116116

117117
def _should_rebalance(self, date: pd.Timestamp, prev_rebalance_date: Optional[pd.Timestamp] = None) -> bool:
118118
"""Check if we should rebalance on given date.
119-
119+
120120
Args:
121121
date: Current date to check
122122
prev_rebalance_date: Last rebalance date (None for first rebalance)
123-
123+
124124
Returns:
125125
True if should rebalance, False otherwise
126126
"""
127127
# Always rebalance on first date
128128
if prev_rebalance_date is None:
129129
return True
130-
130+
131131
if self.rebalance_freq == "D":
132132
# Daily rebalancing
133133
return True

tests/test_backtest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_rebalance_frequency_weekly(self, sample_data):
150150
# Count the number of times weights change
151151
positions = results["positions"]
152152
position_changes = (positions.diff().abs().sum(axis=1) > 0).sum()
153-
153+
154154
# Should be significantly fewer than daily (100 days)
155155
# Approximately ~14 weeks in 100 days
156156
assert position_changes < len(prices) - 1
@@ -168,7 +168,7 @@ def test_rebalance_frequency_monthly(self, sample_data):
168168
# Monthly rebalancing should result in fewer position changes than weekly
169169
positions = results["positions"]
170170
position_changes = (positions.diff().abs().sum(axis=1) > 0).sum()
171-
171+
172172
# Should be significantly fewer than daily
173173
# Approximately ~3 months in 100 days
174174
assert position_changes < len(prices) - 1
@@ -177,7 +177,7 @@ def test_rebalance_frequency_invalid(self, sample_data):
177177
"""Test that invalid rebalance frequency raises error."""
178178
prices, signals = sample_data
179179
backtest = VectorizedBacktest(prices, signals, rebalance_freq="X")
180-
180+
181181
with pytest.raises(ValueError, match="Unsupported rebalance frequency"):
182182
backtest.run()
183183

0 commit comments

Comments
 (0)