* Adding command for Filtering
* Read latest Backtest file and print trades
This commit is contained in:
parent
9c789856bd
commit
85979c3176
@ -16,7 +16,7 @@ from freqtrade.commands.hyperopt_commands import start_hyperopt_list, start_hype
|
||||
from freqtrade.commands.list_commands import (start_list_exchanges, start_list_hyperopts,
|
||||
start_list_markets, start_list_strategies,
|
||||
start_list_timeframes, start_show_trades)
|
||||
from freqtrade.commands.optimize_commands import start_backtesting, start_edge, start_hyperopt
|
||||
from freqtrade.commands.optimize_commands import start_backtest_filter, start_backtesting, start_edge, start_hyperopt
|
||||
from freqtrade.commands.pairlist_commands import start_test_pairlist
|
||||
from freqtrade.commands.plot_commands import start_plot_dataframe, start_plot_profit
|
||||
from freqtrade.commands.trade_commands import start_trading
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module contains the argument manager class
|
||||
"""
|
||||
import argparse
|
||||
from freqtrade.commands.optimize_commands import start_backtest_filter
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
@ -37,6 +38,8 @@ ARGS_LIST_STRATEGIES = ["strategy_path", "print_one_column", "print_colorized"]
|
||||
|
||||
ARGS_LIST_HYPEROPTS = ["hyperopt_path", "print_one_column", "print_colorized"]
|
||||
|
||||
ARGS_BACKTEST_FILTER = ["backtest_path"]
|
||||
|
||||
ARGS_LIST_EXCHANGES = ["print_one_column", "list_exchanges_all"]
|
||||
|
||||
ARGS_LIST_TIMEFRAMES = ["exchange", "print_one_column"]
|
||||
@ -89,7 +92,7 @@ ARGS_HYPEROPT_SHOW = ["hyperopt_list_best", "hyperopt_list_profitable", "hyperop
|
||||
|
||||
NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data", "list-timeframes",
|
||||
"list-markets", "list-pairs", "list-strategies", "list-data",
|
||||
"list-hyperopts", "hyperopt-list", "hyperopt-show",
|
||||
"list-hyperopts", "hyperopt-list", "backtest-filter", "hyperopt-show",
|
||||
"plot-dataframe", "plot-profit", "show-trades"]
|
||||
|
||||
NO_CONF_ALLOWED = ["create-userdir", "list-exchanges", "new-hyperopt", "new-strategy"]
|
||||
@ -168,7 +171,7 @@ class Arguments:
|
||||
self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot')
|
||||
self._build_args(optionlist=['version'], parser=self.parser)
|
||||
|
||||
from freqtrade.commands import (start_backtesting, start_convert_data, start_create_userdir,
|
||||
from freqtrade.commands import (start_backtesting, start_backtest_filter, start_convert_data, start_create_userdir,
|
||||
start_download_data, start_edge, start_hyperopt,
|
||||
start_hyperopt_list, start_hyperopt_show, start_install_ui,
|
||||
start_list_data, start_list_exchanges, start_list_hyperopts,
|
||||
@ -256,6 +259,15 @@ class Arguments:
|
||||
backtesting_cmd.set_defaults(func=start_backtesting)
|
||||
self._build_args(optionlist=ARGS_BACKTEST, parser=backtesting_cmd)
|
||||
|
||||
# Add backtest-filter subcommand
|
||||
backtest_filter_cmd = subparsers.add_parser(
|
||||
'backtest-filter',
|
||||
help='Filter Backtest results',
|
||||
parents=[_common_parser],
|
||||
)
|
||||
backtest_filter_cmd.set_defaults(func=start_backtest_filter)
|
||||
self._build_args(optionlist=ARGS_BACKTEST_FILTER, parser=backtest_filter_cmd)
|
||||
|
||||
# Add edge subcommand
|
||||
edge_cmd = subparsers.add_parser('edge', help='Edge module.',
|
||||
parents=[_common_parser, _strategy_parser])
|
||||
|
@ -202,6 +202,11 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
help='Specify additional lookup path for Hyperopt and Hyperopt Loss functions.',
|
||||
metavar='PATH',
|
||||
),
|
||||
"backtest_path": Arg(
|
||||
'--backtest-path',
|
||||
help='Specify lookup file path for backtest filter.',
|
||||
metavar='PATH',
|
||||
),
|
||||
"epochs": Arg(
|
||||
'-e', '--epochs',
|
||||
help='Specify number of epochs (default: %(default)d).',
|
||||
|
@ -1,3 +1,7 @@
|
||||
from freqtrade.data.btanalysis import get_latest_backtest_filename
|
||||
import pandas
|
||||
from pandas.io import json
|
||||
from freqtrade.optimize import backtesting
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
|
||||
@ -52,6 +56,30 @@ def start_backtesting(args: Dict[str, Any]) -> None:
|
||||
backtesting = Backtesting(config)
|
||||
backtesting.start()
|
||||
|
||||
def start_backtest_filter(args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
List backtest pairs previously filtered
|
||||
"""
|
||||
|
||||
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
||||
|
||||
no_header = config.get('backtest_show_pair_list', False)
|
||||
results_file = get_latest_backtest_filename(
|
||||
config['user_data_dir'] / 'backtest_results/')
|
||||
|
||||
logger.info("Using Backtesting result {results_file}")
|
||||
|
||||
# load data using Python JSON module
|
||||
with open(config['user_data_dir'] / 'backtest_results/' / results_file,'r') as f:
|
||||
data = json.loads(f.read())
|
||||
strategy = list(data["strategy"])[0]
|
||||
trades = data["strategy"][strategy]
|
||||
|
||||
print(trades)
|
||||
|
||||
|
||||
logger.info("Backtest filtering complete. ")
|
||||
|
||||
|
||||
def start_hyperopt(args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
|
@ -668,3 +668,18 @@ def show_backtest_results(config: Dict, backtest_stats: Dict):
|
||||
print(table)
|
||||
print('=' * len(table.splitlines()[0]))
|
||||
print('\nFor more details, please look at the detail tables above')
|
||||
|
||||
def show_backtest_results_filtered(config: Dict, backtest_stats: Dict):
|
||||
stake_currency = config['stake_currency']
|
||||
|
||||
for strategy, results in backtest_stats['strategy'].items():
|
||||
show_backtest_result(strategy, results, stake_currency)
|
||||
|
||||
if len(backtest_stats['strategy']) > 1:
|
||||
# Print Strategy summary table
|
||||
|
||||
table = text_table_strategy(backtest_stats['strategy_comparison'], stake_currency)
|
||||
print(' STRATEGY SUMMARY '.center(len(table.splitlines()[0]), '='))
|
||||
print(table)
|
||||
print('=' * len(table.splitlines()[0]))
|
||||
print('\nFor more details, please look at the detail tables above')
|
||||
|
Loading…
Reference in New Issue
Block a user