Skip to content

Commit 6b7f0f1

Browse files
committed
fix: resolve linting issues (ruff)
- Fix import sorting - Remove trailing whitespace - Fix boolean comparison - Rename unused variable - Add trailing newline
1 parent 0b73ca2 commit 6b7f0f1

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

.coverage

0 Bytes
Binary file not shown.
Binary file not shown.

src/quant_research_starter/backtest/vectorized.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Vectorized backtesting engine."""
22

33
from typing import Dict, Optional
4+
45
import numpy as np
56
import pandas as pd
67

8+
79
class VectorizedBacktest:
810
"""
911
Vectorized backtester for quantitative strategies.
@@ -22,7 +24,7 @@ def __init__(
2224
initial_capital: float = 1_000_000,
2325
transaction_cost: float = 0.001, # 10 bps
2426
max_leverage: float = 1.0,
25-
min_position_size: float = 0.001,
27+
min_position_size: float = 0.001,
2628
rebalance_freq: str = "D",
2729
):
2830
"""
@@ -90,8 +92,8 @@ def run(self, weight_scheme: str = "rank") -> Dict:
9092
rebalance_mask = weights.index.map(self._should_rebalance)
9193
# Broadcast mask to match DataFrame shape
9294
rebalance_mask_df = pd.DataFrame(
93-
np.tile(rebalance_mask.values.reshape(-1, 1), (1, len(weights.columns))),
94-
index=weights.index,
95+
np.tile(rebalance_mask.values.reshape(-1, 1), (1, len(weights.columns))),
96+
index=weights.index,
9597
columns=weights.columns
9698
)
9799
weights = weights.where(rebalance_mask_df, weights.shift(1).fillna(0.0))
-200 Bytes
Binary file not shown.

tests/test_backtest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ def test_should_rebalance_logic(self):
155155
# Test daily rebalancing
156156
backtest_daily = VectorizedBacktest(prices, signals, rebalance_freq="D")
157157
for date in dates:
158-
assert backtest_daily._should_rebalance(date) == True
158+
assert backtest_daily._should_rebalance(date)
159159

160160
# Test weekly rebalancing (should rebalance on Mondays)
161161
backtest_weekly = VectorizedBacktest(prices, signals, rebalance_freq="W")
162-
for i, date in enumerate(dates):
162+
for _i, date in enumerate(dates):
163163
expected = date.weekday() == 0 # Monday
164164
assert backtest_weekly._should_rebalance(date) == expected
165165

@@ -172,7 +172,7 @@ def test_should_rebalance_logic(self):
172172
def test_invalid_rebalance_frequency(self, sample_data):
173173
"""Test that invalid rebalance frequency raises error."""
174174
prices, signals = sample_data
175-
175+
176176
with pytest.raises(ValueError, match="Unsupported rebalance frequency"):
177177
backtest = VectorizedBacktest(prices, signals, rebalance_freq="X")
178178
backtest.run()
@@ -209,4 +209,4 @@ def test_rebalancing_frequency_impact(self, sample_data):
209209

210210
# Weekly and monthly should have fewer position changes than daily
211211
assert weekly_changes <= daily_changes
212-
assert monthly_changes <= daily_changes
212+
assert monthly_changes <= daily_changes

0 commit comments

Comments
 (0)