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
`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
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
@ -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:
```
--enter-reason-list : Comma 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"
--enter-reason-list : Space-separated list of enter signals to analyse. Default: "all"
--exit-reason-list : Space-separated list of exit signals to analyse. Default: "all"
```
For example:
```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
@ -93,7 +94,7 @@ indicators. To print out a column for a given set of indicators, use the `--indi
option:
```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

View File

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

View File

@ -161,24 +161,20 @@ def _print_results(analysed_trades, stratname, analysis_groups,
bigdf = pd.concat([bigdf, trades], ignore_index=True)
if bigdf.shape[0] > 0 and ('enter_reason' in bigdf.columns):
if analysis_groups is not None:
glist = analysis_groups.split(",")
_do_group_table_output(bigdf, glist)
if analysis_groups:
_do_group_table_output(bigdf, analysis_groups)
if enter_reason_list is not None and not enter_reason_list == "all":
enter_reason_list = enter_reason_list.split(",")
if enter_reason_list and "all" not in 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":
exit_reason_list = exit_reason_list.split(",")
if exit_reason_list and "all" not in exit_reason_list:
bigdf = bigdf.loc[(bigdf['exit_reason'].isin(exit_reason_list))]
if indicator_list is not None and indicator_list != "":
if indicator_list == "all":
if "all" in indicator_list:
print(bigdf)
else:
elif indicator_list is not None:
available_inds = []
for ind in indicator_list.split(","):
for ind in indicator_list:
if ind in bigdf:
available_inds.append(ind)
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,
pairlist: List[str],
analysis_groups: Optional[str] = "0,1,2",
enter_reason_list: Optional[str] = "all",
exit_reason_list: Optional[str] = "all",
indicator_list: Optional[str] = None):
analysis_groups: Optional[List[str]] = ["0", "1", "2"],
enter_reason_list: Optional[List[str]] = ["all"],
exit_reason_list: Optional[List[str]] = ["all"],
indicator_list: Optional[List[str]] = []):
try:
backtest_stats = load_backtest_stats(backtest_dir)
for strategy_name, results in backtest_stats['strategy'].items():