Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 68f6478

Browse filesBrowse files
committed
MNT: Fix/ignore issues with flake8 7.2.0
1 parent e177a8c commit 68f6478
Copy full SHA for 68f6478

6 files changed

+17-13Lines changed: 17 additions & 13 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎backtesting/_plotting.py‎

Copy file name to clipboardExpand all lines: backtesting/_plotting.py
+5-5Lines changed: 5 additions & 5 deletions
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]
Collapse file

‎backtesting/_stats.py‎

Copy file name to clipboardExpand all lines: backtesting/_stats.py
+2-2Lines changed: 2 additions & 2 deletions
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
Collapse file

‎backtesting/backtesting.py‎

Copy file name to clipboardExpand all lines: backtesting/backtesting.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def next(self):
211211
"""
212212

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

217217
def buy(self, *,
@@ -449,7 +449,7 @@ def __repr__(self):
449449
('tp', self.__tp_price),
450450
('contingent', self.is_contingent),
451451
('tag', self.__tag),
452-
) if value is not None))
452+
) if value is not None)) # noqa: E126
453453

454454
def cancel(self):
455455
"""Cancel the order."""
@@ -578,7 +578,7 @@ def __init__(self, broker: '_Broker', size: int, entry_price: float, entry_bar,
578578
def __repr__(self):
579579
return f'<Trade size={self.__size} time={self.__entry_bar}-{self.__exit_bar or ""} ' \
580580
f'price={self.__entry_price}-{self.__exit_price or ""} pl={self.pl:.0f}' \
581-
f'{" tag="+str(self.__tag) if self.__tag is not None else ""}>'
581+
f'{" tag=" + str(self.__tag) if self.__tag is not None else ""}>'
582582

583583
def _replace(self, **kwargs):
584584
for k, v in kwargs.items():
Collapse file

‎backtesting/lib.py‎

Copy file name to clipboardExpand all lines: backtesting/lib.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def set_trailing_pct(self, pct: float = .05):
497497
def next(self):
498498
super().next()
499499
# Can't use index=-1 because self.__atr is not an Indicator type
500-
index = len(self.data)-1
500+
index = len(self.data) - 1
501501
for trade in self.trades:
502502
if trade.is_long:
503503
trade.sl = max(trade.sl or -np.inf,
Collapse file

‎backtesting/test/_test.py‎

Copy file name to clipboardExpand all lines: backtesting/test/_test.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_compute_drawdown(self):
287287
def test_compute_stats(self):
288288
stats = Backtest(GOOG, SmaCross, finalize_trades=True).run()
289289
expected = pd.Series({
290-
# NOTE: These values are also used on the website!
290+
# NOTE: These values are also used on the website! # noqa: E126
291291
'# Trades': 66,
292292
'Avg. Drawdown Duration': pd.Timedelta('41 days 00:00:00'),
293293
'Avg. Drawdown [%]': -5.925851581948801,
@@ -929,7 +929,7 @@ def next(self):
929929
self.assertEqual(stats['# Trades'], 56)
930930

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

Collapse file

‎setup.cfg‎

Copy file name to clipboardExpand all lines: setup.cfg
+4Lines changed: 4 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.