Skip to content

Commit fe92df7

Browse files
committed
chore: revert unnecessary edits
1 parent e6dd932 commit fe92df7

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

freqtrade/data/metrics.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def calculate_underwater(
175175
@dataclass()
176176
class DrawDownResult:
177177
# Max drawdown fields
178+
drawdown_abs: float = 0.0
178179
high_date: pd.Timestamp = None
179180
low_date: pd.Timestamp = None
180181
high_value: float = 0.0
181182
low_value: float = 0.0
182-
drawdown_abs: float = 0.0
183183
relative_account_drawdown: float = 0.0
184184
# Current drawdown fields
185185
current_high_date: pd.Timestamp = None
@@ -208,14 +208,10 @@ def calculate_max_drawdown(
208208
relative account drawdown, and current drawdown information.
209209
:raise: ValueError if trade-dataframe was found empty.
210210
"""
211-
212211
if len(trades) == 0:
213212
raise ValueError("Trade dataframe empty.")
214213

215-
# Sort trades by close date
216214
profit_results = trades.sort_values(date_col).reset_index(drop=True)
217-
218-
# Get drawdown data
219215
max_drawdown_df = _calc_drawdown_series(
220216
profit_results, date_col=date_col, value_col=value_col, starting_balance=starting_balance
221217
)
@@ -231,7 +227,6 @@ def calculate_max_drawdown(
231227
low_date = profit_results.loc[idxmin, date_col]
232228
high_val = max_drawdown_df.loc[high_idx, "cumulative"]
233229
low_val = max_drawdown_df.loc[idxmin, "cumulative"]
234-
max_drawdown_abs = abs(max_drawdown_df.loc[idxmin, "drawdown"])
235230
max_drawdown_rel = max_drawdown_df.loc[idxmin, "drawdown_relative"]
236231

237232
# Calculate current drawdown
@@ -242,13 +237,13 @@ def calculate_max_drawdown(
242237
current_drawdown_abs = current_high_value - current_cumulative
243238
current_drawdown_relative = max_drawdown_df.iloc[-1]["drawdown_relative"]
244239

245-
result = DrawDownResult(
240+
return DrawDownResult(
246241
# Max drawdown
242+
drawdown_abs=abs(max_drawdown_df.loc[idxmin, "drawdown"]),
247243
high_date=high_date,
248244
low_date=low_date,
249245
high_value=high_val,
250246
low_value=low_val,
251-
drawdown_abs=max_drawdown_abs,
252247
relative_account_drawdown=max_drawdown_rel,
253248
# Current drawdown
254249
current_high_date=current_high_date,
@@ -257,8 +252,6 @@ def calculate_max_drawdown(
257252
current_relative_account_drawdown=current_drawdown_relative,
258253
)
259254

260-
return result
261-
262255

263256
def calculate_csum(trades: pd.DataFrame, starting_balance: float = 0) -> tuple[float, float]:
264257
"""

freqtrade/rpc/rpc.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,18 @@ def _rpc_trade_statistics(
611611
)
612612

613613
expectancy, expectancy_ratio = calculate_expectancy(trades_df)
614-
max_drawdown = DrawDownResult()
615614

615+
drawdown = DrawDownResult()
616616
if len(trades_df) > 0:
617617
try:
618-
max_drawdown = calculate_max_drawdown(
618+
drawdown = calculate_max_drawdown(
619619
trades_df,
620620
value_col="profit_abs",
621621
date_col="close_date_dt",
622622
starting_balance=starting_balance,
623623
)
624624
except ValueError:
625+
# ValueError if no losing trade.
625626
pass
626627

627628
profit_all_fiat = (
@@ -672,19 +673,19 @@ def _rpc_trade_statistics(
672673
"winrate": winrate,
673674
"expectancy": expectancy,
674675
"expectancy_ratio": expectancy_ratio,
675-
"max_drawdown": max_drawdown.relative_account_drawdown,
676-
"max_drawdown_abs": max_drawdown.drawdown_abs,
677-
"max_drawdown_start": format_date(max_drawdown.high_date),
678-
"max_drawdown_start_timestamp": dt_ts_def(max_drawdown.high_date),
679-
"max_drawdown_end": format_date(max_drawdown.low_date),
680-
"max_drawdown_end_timestamp": dt_ts_def(max_drawdown.low_date),
681-
"drawdown_high": max_drawdown.high_value,
682-
"drawdown_low": max_drawdown.low_value,
683-
"current_drawdown": max_drawdown.current_relative_account_drawdown,
684-
"current_drawdown_abs": max_drawdown.current_drawdown_abs,
685-
"current_drawdown_high": max_drawdown.current_high_value,
686-
"current_drawdown_start": format_date(max_drawdown.current_high_date),
687-
"current_drawdown_start_timestamp": dt_ts_def(max_drawdown.current_high_date),
676+
"max_drawdown": drawdown.relative_account_drawdown,
677+
"max_drawdown_abs": drawdown.drawdown_abs,
678+
"max_drawdown_start": format_date(drawdown.high_date),
679+
"max_drawdown_start_timestamp": dt_ts_def(drawdown.high_date),
680+
"max_drawdown_end": format_date(drawdown.low_date),
681+
"max_drawdown_end_timestamp": dt_ts_def(drawdown.low_date),
682+
"drawdown_high": drawdown.high_value,
683+
"drawdown_low": drawdown.low_value,
684+
"current_drawdown": drawdown.current_relative_account_drawdown,
685+
"current_drawdown_abs": drawdown.current_drawdown_abs,
686+
"current_drawdown_high": drawdown.current_high_value,
687+
"current_drawdown_start": format_date(drawdown.current_high_date),
688+
"current_drawdown_start_timestamp": dt_ts_def(drawdown.current_high_date),
688689
"trading_volume": trading_volume,
689690
"bot_start_timestamp": dt_ts_def(bot_start, 0),
690691
"bot_start_date": format_date(bot_start),

0 commit comments

Comments
 (0)