Introduce DatetimePrintFormat

This commit is contained in:
Matthias 2020-06-09 08:07:34 +02:00
parent cbcf3dbb43
commit fbddfaeacf
6 changed files with 26 additions and 25 deletions

View File

@ -26,6 +26,7 @@ AVAILABLE_PAIRLISTS = ['StaticPairList', 'VolumePairList',
'ShuffleFilter', 'SpreadFilter'] 'ShuffleFilter', 'SpreadFilter']
AVAILABLE_DATAHANDLERS = ['json', 'jsongz'] AVAILABLE_DATAHANDLERS = ['json', 'jsongz']
DRY_RUN_WALLET = 1000 DRY_RUN_WALLET = 1000
DATETIME_PRINT_FORMAT = '%Y-%m-%d %H:%M:%S'
MATH_CLOSE_PREC = 1e-14 # Precision used for float comparisons MATH_CLOSE_PREC = 1e-14 # Precision used for float comparisons
DEFAULT_DATAFRAME_COLUMNS = ['date', 'open', 'high', 'low', 'close', 'volume'] DEFAULT_DATAFRAME_COLUMNS = ['date', 'open', 'high', 'low', 'close', 'volume']
# Don't modify sequence of DEFAULT_TRADES_COLUMNS # Don't modify sequence of DEFAULT_TRADES_COLUMNS

View File

@ -9,7 +9,7 @@ import utils_find_1st as utf1st
from pandas import DataFrame from pandas import DataFrame
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.constants import UNLIMITED_STAKE_AMOUNT from freqtrade.constants import UNLIMITED_STAKE_AMOUNT, DATETIME_PRINT_FORMAT
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.data.history import get_timerange, load_data, refresh_data from freqtrade.data.history import get_timerange, load_data, refresh_data
from freqtrade.strategy.interface import SellType from freqtrade.strategy.interface import SellType
@ -121,12 +121,9 @@ class Edge:
# Print timeframe # Print timeframe
min_date, max_date = get_timerange(preprocessed) min_date, max_date = get_timerange(preprocessed)
logger.info( logger.info(f'Measuring data from {min_date.strftime(DATETIME_PRINT_FORMAT)} '
'Measuring data from %s up to %s (%s days) ...', f'up to {max_date.strftime(DATETIME_PRINT_FORMAT)} '
min_date.isoformat(), f'({(max_date - min_date).days} days)..')
max_date.isoformat(),
(max_date - min_date).days
)
headers = ['date', 'buy', 'open', 'close', 'sell', 'high', 'low'] headers = ['date', 'buy', 'open', 'close', 'sell', 'high', 'low']
trades: list = [] trades: list = []

View File

@ -11,6 +11,7 @@ from typing import Any, Dict, List, NamedTuple, Optional, Tuple
import arrow import arrow
from pandas import DataFrame from pandas import DataFrame
from freqtrade.constants import DATETIME_PRINT_FORMAT
from freqtrade.configuration import (TimeRange, remove_credentials, from freqtrade.configuration import (TimeRange, remove_credentials,
validate_config_consistency) validate_config_consistency)
from freqtrade.data import history from freqtrade.data import history
@ -137,10 +138,10 @@ class Backtesting:
min_date, max_date = history.get_timerange(data) min_date, max_date = history.get_timerange(data)
logger.info( logger.info(f'Loading data from {min_date.strftime(DATETIME_PRINT_FORMAT)} '
'Loading data from %s up to %s (%s days)..', f'up to {max_date.strftime(DATETIME_PRINT_FORMAT)} '
min_date.isoformat(), max_date.isoformat(), (max_date - min_date).days f'({(max_date - min_date).days} days)..')
)
# Adjust startts forward if not enough data is available # Adjust startts forward if not enough data is available
timerange.adjust_start_if_necessary(timeframe_to_seconds(self.timeframe), timerange.adjust_start_if_necessary(timeframe_to_seconds(self.timeframe),
self.required_startup, min_date) self.required_startup, min_date)
@ -400,10 +401,9 @@ class Backtesting:
preprocessed[pair] = trim_dataframe(df, timerange) preprocessed[pair] = trim_dataframe(df, timerange)
min_date, max_date = history.get_timerange(preprocessed) min_date, max_date = history.get_timerange(preprocessed)
logger.info( logger.info(f'Backtesting with data from {min_date.strftime(DATETIME_PRINT_FORMAT)} '
'Backtesting with data from %s up to %s (%s days)..', f'up to {max_date.strftime(DATETIME_PRINT_FORMAT)} '
min_date.isoformat(), max_date.isoformat(), (max_date - min_date).days f'({(max_date - min_date).days} days)..')
)
# Execute backtest and print results # Execute backtest and print results
all_results[self.strategy.get_strategy_name()] = self.backtest( all_results[self.strategy.get_strategy_name()] = self.backtest(
processed=preprocessed, processed=preprocessed,

View File

@ -25,6 +25,7 @@ import tabulate
from os import path from os import path
import io import io
from freqtrade.constants import DATETIME_PRINT_FORMAT
from freqtrade.data.converter import trim_dataframe from freqtrade.data.converter import trim_dataframe
from freqtrade.data.history import get_timerange from freqtrade.data.history import get_timerange
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
@ -625,10 +626,10 @@ class Hyperopt:
preprocessed[pair] = trim_dataframe(df, timerange) preprocessed[pair] = trim_dataframe(df, timerange)
min_date, max_date = get_timerange(data) min_date, max_date = get_timerange(data)
logger.info( logger.info(f'Hyperopting with data from {min_date.strftime(DATETIME_PRINT_FORMAT)} '
'Hyperopting with data from %s up to %s (%s days)..', f'up to {max_date.strftime(DATETIME_PRINT_FORMAT)} '
min_date.isoformat(), max_date.isoformat(), (max_date - min_date).days f'({(max_date - min_date).days} days)..')
)
dump(preprocessed, self.data_pickle_file) dump(preprocessed, self.data_pickle_file)
# We don't need exchange instance anymore while running hyperopt # We don't need exchange instance anymore while running hyperopt

View File

@ -7,6 +7,7 @@ from arrow import Arrow
from pandas import DataFrame from pandas import DataFrame
from tabulate import tabulate from tabulate import tabulate
from freqtrade.constants import DATETIME_PRINT_FORMAT
from freqtrade.data.btanalysis import calculate_max_drawdown from freqtrade.data.btanalysis import calculate_max_drawdown
from freqtrade.misc import file_dump_json from freqtrade.misc import file_dump_json
@ -338,15 +339,15 @@ def text_table_add_metrics(strategy_results: Dict) -> str:
metrics = [ metrics = [
('Total trades', strategy_results['total_trades']), ('Total trades', strategy_results['total_trades']),
('First trade', datetime.fromtimestamp(min_trade[2], ('First trade', datetime.fromtimestamp(min_trade[2],
tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S')), tz=timezone.utc).strftime(DATETIME_PRINT_FORMAT)),
('First trade Pair', min_trade[0]), ('First trade Pair', min_trade[0]),
('Backtesting from', strategy_results['backtest_start'].strftime('%Y-%m-%d %H:%M:%S')), ('Backtesting from', strategy_results['backtest_start'].strftime(DATETIME_PRINT_FORMAT)),
('Backtesting to', strategy_results['backtest_end'].strftime('%Y-%m-%d %H:%M:%S')), ('Backtesting to', strategy_results['backtest_end'].strftime(DATETIME_PRINT_FORMAT)),
('Trades per day', strategy_results['trades_per_day']), ('Trades per day', strategy_results['trades_per_day']),
('', ''), # Empty line to improve readability ('', ''), # Empty line to improve readability
('Max Drawdown', f"{round(strategy_results['max_drawdown'] * 100, 2)}%"), ('Max Drawdown', f"{round(strategy_results['max_drawdown'] * 100, 2)}%"),
('Drawdown Start', strategy_results['drawdown_start'].strftime('%Y-%m-%d %H:%M:%S')), ('Drawdown Start', strategy_results['drawdown_start'].strftime(DATETIME_PRINT_FORMAT)),
('Drawdown End', strategy_results['drawdown_end'].strftime('%Y-%m-%d %H:%M:%S')), ('Drawdown End', strategy_results['drawdown_end'].strftime(DATETIME_PRINT_FORMAT)),
] ]
return tabulate(metrics, headers=["Metric", "Value"], tablefmt="orgtbl") return tabulate(metrics, headers=["Metric", "Value"], tablefmt="orgtbl")

View File

@ -16,6 +16,7 @@ from werkzeug.security import safe_str_cmp
from werkzeug.serving import make_server from werkzeug.serving import make_server
from freqtrade.__init__ import __version__ from freqtrade.__init__ import __version__
from freqtrade.constants import DATETIME_PRINT_FORMAT
from freqtrade.rpc.rpc import RPC, RPCException from freqtrade.rpc.rpc import RPC, RPCException
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -31,7 +32,7 @@ class ArrowJSONEncoder(JSONEncoder):
elif isinstance(obj, date): elif isinstance(obj, date):
return obj.strftime("%Y-%m-%d") return obj.strftime("%Y-%m-%d")
elif isinstance(obj, datetime): elif isinstance(obj, datetime):
return obj.strftime("%Y-%m-%d %H:%M:%S") return obj.strftime(DATETIME_PRINT_FORMAT)
iterable = iter(obj) iterable = iter(obj)
except TypeError: except TypeError:
pass pass