mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
chore: revert unnecessary edits
This commit is contained in:
@@ -175,11 +175,11 @@ def calculate_underwater(
|
|||||||
@dataclass()
|
@dataclass()
|
||||||
class DrawDownResult:
|
class DrawDownResult:
|
||||||
# Max drawdown fields
|
# Max drawdown fields
|
||||||
|
drawdown_abs: float = 0.0
|
||||||
high_date: pd.Timestamp = None
|
high_date: pd.Timestamp = None
|
||||||
low_date: pd.Timestamp = None
|
low_date: pd.Timestamp = None
|
||||||
high_value: float = 0.0
|
high_value: float = 0.0
|
||||||
low_value: float = 0.0
|
low_value: float = 0.0
|
||||||
drawdown_abs: float = 0.0
|
|
||||||
relative_account_drawdown: float = 0.0
|
relative_account_drawdown: float = 0.0
|
||||||
# Current drawdown fields
|
# Current drawdown fields
|
||||||
current_high_date: pd.Timestamp = None
|
current_high_date: pd.Timestamp = None
|
||||||
@@ -208,14 +208,10 @@ def calculate_max_drawdown(
|
|||||||
relative account drawdown, and current drawdown information.
|
relative account drawdown, and current drawdown information.
|
||||||
:raise: ValueError if trade-dataframe was found empty.
|
:raise: ValueError if trade-dataframe was found empty.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if len(trades) == 0:
|
if len(trades) == 0:
|
||||||
raise ValueError("Trade dataframe empty.")
|
raise ValueError("Trade dataframe empty.")
|
||||||
|
|
||||||
# Sort trades by close date
|
|
||||||
profit_results = trades.sort_values(date_col).reset_index(drop=True)
|
profit_results = trades.sort_values(date_col).reset_index(drop=True)
|
||||||
|
|
||||||
# Get drawdown data
|
|
||||||
max_drawdown_df = _calc_drawdown_series(
|
max_drawdown_df = _calc_drawdown_series(
|
||||||
profit_results, date_col=date_col, value_col=value_col, starting_balance=starting_balance
|
profit_results, date_col=date_col, value_col=value_col, starting_balance=starting_balance
|
||||||
)
|
)
|
||||||
@@ -231,7 +227,6 @@ def calculate_max_drawdown(
|
|||||||
low_date = profit_results.loc[idxmin, date_col]
|
low_date = profit_results.loc[idxmin, date_col]
|
||||||
high_val = max_drawdown_df.loc[high_idx, "cumulative"]
|
high_val = max_drawdown_df.loc[high_idx, "cumulative"]
|
||||||
low_val = max_drawdown_df.loc[idxmin, "cumulative"]
|
low_val = max_drawdown_df.loc[idxmin, "cumulative"]
|
||||||
max_drawdown_abs = abs(max_drawdown_df.loc[idxmin, "drawdown"])
|
|
||||||
max_drawdown_rel = max_drawdown_df.loc[idxmin, "drawdown_relative"]
|
max_drawdown_rel = max_drawdown_df.loc[idxmin, "drawdown_relative"]
|
||||||
|
|
||||||
# Calculate current drawdown
|
# Calculate current drawdown
|
||||||
@@ -242,13 +237,13 @@ def calculate_max_drawdown(
|
|||||||
current_drawdown_abs = current_high_value - current_cumulative
|
current_drawdown_abs = current_high_value - current_cumulative
|
||||||
current_drawdown_relative = max_drawdown_df.iloc[-1]["drawdown_relative"]
|
current_drawdown_relative = max_drawdown_df.iloc[-1]["drawdown_relative"]
|
||||||
|
|
||||||
result = DrawDownResult(
|
return DrawDownResult(
|
||||||
# Max drawdown
|
# Max drawdown
|
||||||
|
drawdown_abs=abs(max_drawdown_df.loc[idxmin, "drawdown"]),
|
||||||
high_date=high_date,
|
high_date=high_date,
|
||||||
low_date=low_date,
|
low_date=low_date,
|
||||||
high_value=high_val,
|
high_value=high_val,
|
||||||
low_value=low_val,
|
low_value=low_val,
|
||||||
drawdown_abs=max_drawdown_abs,
|
|
||||||
relative_account_drawdown=max_drawdown_rel,
|
relative_account_drawdown=max_drawdown_rel,
|
||||||
# Current drawdown
|
# Current drawdown
|
||||||
current_high_date=current_high_date,
|
current_high_date=current_high_date,
|
||||||
@@ -257,8 +252,6 @@ def calculate_max_drawdown(
|
|||||||
current_relative_account_drawdown=current_drawdown_relative,
|
current_relative_account_drawdown=current_drawdown_relative,
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_csum(trades: pd.DataFrame, starting_balance: float = 0) -> tuple[float, float]:
|
def calculate_csum(trades: pd.DataFrame, starting_balance: float = 0) -> tuple[float, float]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -611,17 +611,18 @@ class RPC:
|
|||||||
)
|
)
|
||||||
|
|
||||||
expectancy, expectancy_ratio = calculate_expectancy(trades_df)
|
expectancy, expectancy_ratio = calculate_expectancy(trades_df)
|
||||||
max_drawdown = DrawDownResult()
|
|
||||||
|
|
||||||
|
drawdown = DrawDownResult()
|
||||||
if len(trades_df) > 0:
|
if len(trades_df) > 0:
|
||||||
try:
|
try:
|
||||||
max_drawdown = calculate_max_drawdown(
|
drawdown = calculate_max_drawdown(
|
||||||
trades_df,
|
trades_df,
|
||||||
value_col="profit_abs",
|
value_col="profit_abs",
|
||||||
date_col="close_date_dt",
|
date_col="close_date_dt",
|
||||||
starting_balance=starting_balance,
|
starting_balance=starting_balance,
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
# ValueError if no losing trade.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
profit_all_fiat = (
|
profit_all_fiat = (
|
||||||
@@ -672,19 +673,19 @@ class RPC:
|
|||||||
"winrate": winrate,
|
"winrate": winrate,
|
||||||
"expectancy": expectancy,
|
"expectancy": expectancy,
|
||||||
"expectancy_ratio": expectancy_ratio,
|
"expectancy_ratio": expectancy_ratio,
|
||||||
"max_drawdown": max_drawdown.relative_account_drawdown,
|
"max_drawdown": drawdown.relative_account_drawdown,
|
||||||
"max_drawdown_abs": max_drawdown.drawdown_abs,
|
"max_drawdown_abs": drawdown.drawdown_abs,
|
||||||
"max_drawdown_start": format_date(max_drawdown.high_date),
|
"max_drawdown_start": format_date(drawdown.high_date),
|
||||||
"max_drawdown_start_timestamp": dt_ts_def(max_drawdown.high_date),
|
"max_drawdown_start_timestamp": dt_ts_def(drawdown.high_date),
|
||||||
"max_drawdown_end": format_date(max_drawdown.low_date),
|
"max_drawdown_end": format_date(drawdown.low_date),
|
||||||
"max_drawdown_end_timestamp": dt_ts_def(max_drawdown.low_date),
|
"max_drawdown_end_timestamp": dt_ts_def(drawdown.low_date),
|
||||||
"drawdown_high": max_drawdown.high_value,
|
"drawdown_high": drawdown.high_value,
|
||||||
"drawdown_low": max_drawdown.low_value,
|
"drawdown_low": drawdown.low_value,
|
||||||
"current_drawdown": max_drawdown.current_relative_account_drawdown,
|
"current_drawdown": drawdown.current_relative_account_drawdown,
|
||||||
"current_drawdown_abs": max_drawdown.current_drawdown_abs,
|
"current_drawdown_abs": drawdown.current_drawdown_abs,
|
||||||
"current_drawdown_high": max_drawdown.current_high_value,
|
"current_drawdown_high": drawdown.current_high_value,
|
||||||
"current_drawdown_start": format_date(max_drawdown.current_high_date),
|
"current_drawdown_start": format_date(drawdown.current_high_date),
|
||||||
"current_drawdown_start_timestamp": dt_ts_def(max_drawdown.current_high_date),
|
"current_drawdown_start_timestamp": dt_ts_def(drawdown.current_high_date),
|
||||||
"trading_volume": trading_volume,
|
"trading_volume": trading_volume,
|
||||||
"bot_start_timestamp": dt_ts_def(bot_start, 0),
|
"bot_start_timestamp": dt_ts_def(bot_start, 0),
|
||||||
"bot_start_date": format_date(bot_start),
|
"bot_start_date": format_date(bot_start),
|
||||||
|
|||||||
Reference in New Issue
Block a user