mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-19 06:11:15 +00:00
Introduce --exit-signals flag to backtesting-analysis command
This commit is contained in:
@@ -222,6 +222,7 @@ ARGS_ANALYZE_ENTRIES_EXITS = [
|
||||
"indicator_list",
|
||||
"timerange",
|
||||
"analysis_rejected",
|
||||
"analysis_exited",
|
||||
"analysis_to_csv",
|
||||
"analysis_csv_path",
|
||||
]
|
||||
|
||||
@@ -720,6 +720,11 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
help="Analyse rejected signals",
|
||||
action="store_true",
|
||||
),
|
||||
"analysis_exited": Arg(
|
||||
"--exit-signals",
|
||||
help="Analyse indicators at exit signals",
|
||||
action="store_true",
|
||||
),
|
||||
"analysis_to_csv": Arg(
|
||||
"--analysis-to-csv",
|
||||
help="Save selected analysis tables to individual CSVs",
|
||||
|
||||
@@ -401,6 +401,7 @@ class Configuration:
|
||||
("indicator_list", "Analysis indicator list: {}"),
|
||||
("timerange", "Filter trades by timerange: {}"),
|
||||
("analysis_rejected", "Analyse rejected signals: {}"),
|
||||
("analysis_exited", "Analyse exited signals: {}"),
|
||||
("analysis_to_csv", "Store analysis tables to CSV: {}"),
|
||||
("analysis_csv_path", "Path to store analysis CSVs: {}"),
|
||||
# Lookahead analysis results
|
||||
|
||||
@@ -319,6 +319,7 @@ def process_entry_exit_reasons(config: Config):
|
||||
enter_reason_list = config.get("enter_reason_list", ["all"])
|
||||
exit_reason_list = config.get("exit_reason_list", ["all"])
|
||||
indicator_list = config.get("indicator_list", [])
|
||||
do_exited = config.get("analysis_exited", False)
|
||||
do_rejected = config.get("analysis_rejected", False)
|
||||
to_csv = config.get("analysis_to_csv", False)
|
||||
csv_path = Path(config.get("analysis_csv_path", config["exportfilename"]))
|
||||
@@ -335,8 +336,10 @@ def process_entry_exit_reasons(config: Config):
|
||||
trades = load_backtest_data(config["exportfilename"], strategy_name)
|
||||
|
||||
if trades is not None and not trades.empty:
|
||||
if do_exited is True:
|
||||
signal_candles = _load_exit_signal_candles(config["exportfilename"])
|
||||
else:
|
||||
signal_candles = _load_signal_candles(config["exportfilename"])
|
||||
exit_signal_candles = _load_exit_signal_candles(config["exportfilename"])
|
||||
|
||||
rej_df = None
|
||||
if do_rejected:
|
||||
@@ -353,10 +356,6 @@ def process_entry_exit_reasons(config: Config):
|
||||
config["exchange"]["pair_whitelist"], strategy_name, trades, signal_candles
|
||||
)
|
||||
|
||||
exited_trades_dict = _process_candles_and_indicators(
|
||||
config["exchange"]["pair_whitelist"], strategy_name, trades, exit_signal_candles
|
||||
)
|
||||
|
||||
res_df = prepare_results(
|
||||
analysed_trades_dict,
|
||||
strategy_name,
|
||||
@@ -365,23 +364,6 @@ def process_entry_exit_reasons(config: Config):
|
||||
timerange=timerange,
|
||||
)
|
||||
|
||||
exited_df = prepare_results(
|
||||
exited_trades_dict,
|
||||
strategy_name,
|
||||
enter_reason_list,
|
||||
exit_reason_list,
|
||||
timerange=timerange,
|
||||
)
|
||||
|
||||
print_results(
|
||||
exited_df,
|
||||
analysis_groups,
|
||||
indicator_list,
|
||||
to_csv=False,
|
||||
rejected_signals=None,
|
||||
csv_path=csv_path,
|
||||
)
|
||||
|
||||
print_results(
|
||||
res_df,
|
||||
analysis_groups,
|
||||
|
||||
@@ -295,7 +295,7 @@ def test_store_backtest_candles(testdatadir, mocker):
|
||||
# mock directory exporting
|
||||
store_backtest_analysis_results(testdatadir, candle_dict, {}, {}, "2022_01_01_15_05_13")
|
||||
|
||||
assert dump_mock.call_count == 2
|
||||
assert dump_mock.call_count == 3
|
||||
assert isinstance(dump_mock.call_args_list[0][0][0], Path)
|
||||
assert str(dump_mock.call_args_list[0][0][0]).endswith("_signals.pkl")
|
||||
|
||||
@@ -303,7 +303,7 @@ def test_store_backtest_candles(testdatadir, mocker):
|
||||
# mock file exporting
|
||||
filename = Path(testdatadir / "testresult")
|
||||
store_backtest_analysis_results(filename, candle_dict, {}, {}, "2022_01_01_15_05_13")
|
||||
assert dump_mock.call_count == 2
|
||||
assert dump_mock.call_count == 3
|
||||
assert isinstance(dump_mock.call_args_list[0][0][0], Path)
|
||||
# result will be testdatadir / testresult-<timestamp>_signals.pkl
|
||||
assert str(dump_mock.call_args_list[0][0][0]).endswith("_signals.pkl")
|
||||
|
||||
Reference in New Issue
Block a user