Change backtesting-analysis options to space separated lists

This commit is contained in:
froggleston 2022-06-15 11:25:06 +01:00
parent 6bb342f23a
commit c391ca08de
3 changed files with 33 additions and 35 deletions

View File

@ -28,10 +28,11 @@ backtesting with the `--cache none` option to make sure no cached results are us
If all goes well, you should now see a `backtest-result-{timestamp}_signals.pkl` file in the If all goes well, you should now see a `backtest-result-{timestamp}_signals.pkl` file in the
`user_data/backtest_results` folder. `user_data/backtest_results` folder.
To analyze the entry/exit tags, we now need to use the `freqtrade backtesting-analysis` command: To analyze the entry/exit tags, we now need to use the `freqtrade backtesting-analysis` command
with `--analysis-groups` option provided with space-separated arguments (default `0 1 2`):
``` bash ``` bash
freqtrade backtesting-analysis -c <config.json> --analysis-groups 0,1,2,3,4 freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 1 2 3 4
``` ```
This command will read from the last backtesting results. The `--analysis-groups` option is This command will read from the last backtesting results. The `--analysis-groups` option is
@ -75,14 +76,14 @@ freqtrade backtesting-analysis -c <config.json> --export-filename=/tmp/mystrat_b
To show only certain buy and sell tags in the displayed output, use the following two options: To show only certain buy and sell tags in the displayed output, use the following two options:
``` ```
--enter-reason-list : Comma separated list of enter signals to analyse. Default: "all" --enter-reason-list : Space-separated list of enter signals to analyse. Default: "all"
--exit-reason-list : Comma separated list of exit signals to analyse. Default: "stop_loss,trailing_stop_loss" --exit-reason-list : Space-separated list of exit signals to analyse. Default: "all"
``` ```
For example: For example:
```bash ```bash
freqtrade backtesting-analysis -c <config.json> --analysis-groups 0,1,2,3,4 --enter-reason-list "enter_tag_a,enter_tag_b" --exit-reason-list "roi,custom_exit_tag_a,stop_loss" freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss
``` ```
### Outputting signal candle indicators ### Outputting signal candle indicators
@ -93,7 +94,7 @@ indicators. To print out a column for a given set of indicators, use the `--indi
option: option:
```bash ```bash
freqtrade backtesting-analysis -c <config.json> --analysis-groups 0,1,2,3,4 --enter-reason-list "enter_tag_a,enter_tag_b" --exit-reason-list "roi,custom_exit_tag_a,stop_loss" --indicator-list "rsi,rsi_1h,bb_lowerband,ema_9,macd,macdsignal" freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss --indicator-list rsi rsi_1h bb_lowerband ema_9 macd macdsignal
``` ```
The indicators have to be present in your strategy's main DataFrame (either for your main The indicators have to be present in your strategy's main DataFrame (either for your main

View File

@ -622,28 +622,29 @@ AVAILABLE_CLI_OPTIONS = {
"2: by enter_tag and exit_tag, " "2: by enter_tag and exit_tag, "
"3: by pair and enter_tag, " "3: by pair and enter_tag, "
"4: by pair, enter_ and exit_tag (this can get quite large)"), "4: by pair, enter_ and exit_tag (this can get quite large)"),
nargs='?', nargs='+',
default="0,1,2", default=['0', '1', '2'],
choices=['0', '1', '2', '3', '4'],
), ),
"enter_reason_list": Arg( "enter_reason_list": Arg(
"--enter-reason-list", "--enter-reason-list",
help=("Comma separated list of entry signals to analyse. Default: all. " help=("Comma separated list of entry signals to analyse. Default: all. "
"e.g. 'entry_tag_a,entry_tag_b'"), "e.g. 'entry_tag_a,entry_tag_b'"),
nargs='?', nargs='+',
default='all', default=['all'],
), ),
"exit_reason_list": Arg( "exit_reason_list": Arg(
"--exit-reason-list", "--exit-reason-list",
help=("Comma separated list of exit signals to analyse. Default: all. " help=("Comma separated list of exit signals to analyse. Default: all. "
"e.g. 'exit_tag_a,roi,stop_loss,trailing_stop_loss'"), "e.g. 'exit_tag_a,roi,stop_loss,trailing_stop_loss'"),
nargs='?', nargs='+',
default='all', default=['all'],
), ),
"indicator_list": Arg( "indicator_list": Arg(
"--indicator-list", "--indicator-list",
help=("Comma separated list of indicators to analyse. " help=("Comma separated list of indicators to analyse. "
"e.g. 'close,rsi,bb_lowerband,profit_abs'"), "e.g. 'close,rsi,bb_lowerband,profit_abs'"),
nargs='?', nargs='+',
default='', default=[],
), ),
} }

View File

@ -161,24 +161,20 @@ def _print_results(analysed_trades, stratname, analysis_groups,
bigdf = pd.concat([bigdf, trades], ignore_index=True) bigdf = pd.concat([bigdf, trades], ignore_index=True)
if bigdf.shape[0] > 0 and ('enter_reason' in bigdf.columns): if bigdf.shape[0] > 0 and ('enter_reason' in bigdf.columns):
if analysis_groups is not None: if analysis_groups:
glist = analysis_groups.split(",") _do_group_table_output(bigdf, analysis_groups)
_do_group_table_output(bigdf, glist)
if enter_reason_list is not None and not enter_reason_list == "all": if enter_reason_list and "all" not in enter_reason_list:
enter_reason_list = enter_reason_list.split(",")
bigdf = bigdf.loc[(bigdf['enter_reason'].isin(enter_reason_list))] bigdf = bigdf.loc[(bigdf['enter_reason'].isin(enter_reason_list))]
if exit_reason_list is not None and not exit_reason_list == "all": if exit_reason_list and "all" not in exit_reason_list:
exit_reason_list = exit_reason_list.split(",")
bigdf = bigdf.loc[(bigdf['exit_reason'].isin(exit_reason_list))] bigdf = bigdf.loc[(bigdf['exit_reason'].isin(exit_reason_list))]
if indicator_list is not None and indicator_list != "": if "all" in indicator_list:
if indicator_list == "all":
print(bigdf) print(bigdf)
else: elif indicator_list is not None:
available_inds = [] available_inds = []
for ind in indicator_list.split(","): for ind in indicator_list:
if ind in bigdf: if ind in bigdf:
available_inds.append(ind) available_inds.append(ind)
ilist = ["pair", "enter_reason", "exit_reason"] + available_inds ilist = ["pair", "enter_reason", "exit_reason"] + available_inds
@ -205,10 +201,10 @@ def _print_table(df, sortcols=None, show_index=False):
def process_entry_exit_reasons(backtest_dir: Path, def process_entry_exit_reasons(backtest_dir: Path,
pairlist: List[str], pairlist: List[str],
analysis_groups: Optional[str] = "0,1,2", analysis_groups: Optional[List[str]] = ["0", "1", "2"],
enter_reason_list: Optional[str] = "all", enter_reason_list: Optional[List[str]] = ["all"],
exit_reason_list: Optional[str] = "all", exit_reason_list: Optional[List[str]] = ["all"],
indicator_list: Optional[str] = None): indicator_list: Optional[List[str]] = []):
try: try:
backtest_stats = load_backtest_stats(backtest_dir) backtest_stats = load_backtest_stats(backtest_dir)
for strategy_name, results in backtest_stats['strategy'].items(): for strategy_name, results in backtest_stats['strategy'].items():