Skip to content

Commit 39ab2ca

Browse files
committed
MNT: Fix/ignore issues with flake8 7.2.0
1 parent 56f2b12 commit 39ab2ca

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

backtesting/_plotting.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ def _maybe_resample_data(resample_rule, df, indicators, equity_data, trades):
128128
"15min": 15,
129129
"30min": 30,
130130
"1h": 60,
131-
"2h": 60*2,
132-
"4h": 60*4,
133-
"8h": 60*8,
134-
"1D": 60*24,
135-
"1W": 60*24*7,
131+
"2h": 60 * 2,
132+
"4h": 60 * 4,
133+
"8h": 60 * 8,
134+
"1D": 60 * 24,
135+
"1W": 60 * 24 * 7,
136136
"1ME": np.inf,
137137
})
138138
timespan = df.index[-1] - df.index[0]

backtesting/_stats.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ def _round_timedelta(value, _period=_data_period(index)):
137137
# our risk doesn't; they use the simpler approach below.
138138
annualized_return = (1 + gmean_day_return)**annual_trading_days - 1
139139
s.loc['Return (Ann.) [%]'] = annualized_return * 100
140-
s.loc['Volatility (Ann.) [%]'] = np.sqrt((day_returns.var(ddof=int(bool(day_returns.shape))) + (1 + gmean_day_return)**2)**annual_trading_days - (1 + gmean_day_return)**(2*annual_trading_days)) * 100 # noqa: E501
140+
s.loc['Volatility (Ann.) [%]'] = np.sqrt((day_returns.var(ddof=int(bool(day_returns.shape))) + (1 + gmean_day_return)**2)**annual_trading_days - (1 + gmean_day_return)**(2 * annual_trading_days)) * 100 # noqa: E501
141141
# s.loc['Return (Ann.) [%]'] = gmean_day_return * annual_trading_days * 100
142142
# s.loc['Risk (Ann.) [%]'] = day_returns.std(ddof=1) * np.sqrt(annual_trading_days) * 100
143143
if is_datetime_index:
144144
time_in_years = (s.loc['Duration'].days + s.loc['Duration'].seconds / 86400) / annual_trading_days
145-
s.loc['CAGR [%]'] = ((s.loc['Equity Final [$]'] / equity[0])**(1/time_in_years) - 1) * 100 if time_in_years else np.nan # noqa: E501
145+
s.loc['CAGR [%]'] = ((s.loc['Equity Final [$]'] / equity[0])**(1 / time_in_years) - 1) * 100 if time_in_years else np.nan # noqa: E501
146146

147147
# Our Sharpe mismatches `empyrical.sharpe_ratio()` because they use arithmetic mean return
148148
# and simple standard deviation

backtesting/backtesting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def next(self):
210210
"""
211211

212212
class __FULL_EQUITY(float): # noqa: N801
213-
def __repr__(self): return '.9999'
213+
def __repr__(self): return '.9999' # noqa: E704
214214
_FULL_EQUITY = __FULL_EQUITY(1 - sys.float_info.epsilon)
215215

216216
def buy(self, *,

backtesting/lib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def set_trailing_pct(self, pct: float = .05):
496496
def next(self):
497497
super().next()
498498
# Can't use index=-1 because self.__atr is not an Indicator type
499-
index = len(self.data)-1
499+
index = len(self.data) - 1
500500
for trade in self.trades:
501501
if trade.is_long:
502502
trade.sl = max(trade.sl or -np.inf,

backtesting/test/_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def test_compute_drawdown(self):
288288
def test_compute_stats(self):
289289
stats = Backtest(GOOG, SmaCross, finalize_trades=True).run()
290290
expected = pd.Series({
291-
# NOTE: These values are also used on the website!
291+
# NOTE: These values are also used on the website! # noqa: E126
292292
'# Trades': 66,
293293
'Avg. Drawdown Duration': pd.Timedelta('41 days 00:00:00'),
294294
'Avg. Drawdown [%]': -5.925851581948801,
@@ -930,7 +930,7 @@ def next(self):
930930
self.assertEqual(stats['# Trades'], 56)
931931

932932
def test_FractionalBacktest(self):
933-
ubtc_bt = FractionalBacktest(BTCUSD['2015':], SmaCross, fractional_unit=1/1e6, cash=100)
933+
ubtc_bt = FractionalBacktest(BTCUSD['2015':], SmaCross, fractional_unit=1 / 1e6, cash=100)
934934
stats = ubtc_bt.run(fast=2, slow=3)
935935
self.assertEqual(stats['# Trades'], 41)
936936

setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[flake8]
2+
# F824 `nonlocal x` is unused: name is never assigned in scope
3+
# W503 Line break before a binary operator
4+
# W504 Line break after a binary operator -- https://www.flake8rules.com/rules/W504.html
5+
ignore = F824, W503, W504
26
max-line-length = 120
37
exclude =
48
.git,

0 commit comments

Comments
 (0)