Add cleanup, adjust _print_table for indicators, add rsi to test output

This commit is contained in:
froggleston 2022-05-25 09:57:12 +01:00
parent edd474e663
commit 2873ca6d38
2 changed files with 16 additions and 6 deletions

View File

@ -26,7 +26,6 @@ def _load_signal_candles(backtest_dir: Path):
get_latest_backtest_filename(backtest_dir))[0] + "_signals.pkl" get_latest_backtest_filename(backtest_dir))[0] + "_signals.pkl"
) )
print(scpf)
try: try:
scp = open(scpf, "rb") scp = open(scpf, "rb")
signal_candles = joblib.load(scp) signal_candles = joblib.load(scp)
@ -213,11 +212,9 @@ def _print_results(analysed_trades, stratname, group,
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
print(tabulate(bigdf[ilist].sort_values(['exit_reason']), _print_table(bigdf[ilist], sortcols=['exit_reason'], show_index=False)
headers='keys', tablefmt='psql', showindex=False))
else: else:
print(tabulate(bigdf[columns].sort_values(['pair']), _print_table(bigdf[columns], sortcols=['pair'], show_index=False)
headers='keys', tablefmt='psql', showindex=False))
else: else:
print("\\_ No trades to show") print("\\_ No trades to show")

View File

@ -2,13 +2,22 @@ from pathlib import Path
from unittest.mock import MagicMock, PropertyMock from unittest.mock import MagicMock, PropertyMock
import pandas as pd import pandas as pd
import pytest
from freqtrade.commands.analyze_commands import start_analysis_entries_exits from freqtrade.commands.analyze_commands import start_analysis_entries_exits
from freqtrade.commands.optimize_commands import start_backtesting from freqtrade.commands.optimize_commands import start_backtesting
from freqtrade.enums import ExitType from freqtrade.enums import ExitType
from freqtrade.optimize.backtesting import Backtesting
from tests.conftest import get_args, patch_exchange, patched_configuration_load_config_file from tests.conftest import get_args, patch_exchange, patched_configuration_load_config_file
@pytest.fixture(autouse=True)
def backtesting_cleanup() -> None:
yield None
Backtesting.cleanup()
def test_backtest_analysis_nomock(default_conf, mocker, caplog, testdatadir, capsys): def test_backtest_analysis_nomock(default_conf, mocker, caplog, testdatadir, capsys):
default_conf.update({ default_conf.update({
"use_exit_signal": True, "use_exit_signal": True,
@ -18,7 +27,7 @@ def test_backtest_analysis_nomock(default_conf, mocker, caplog, testdatadir, cap
'analysis_groups': "0", 'analysis_groups': "0",
'enter_reason_list': "all", 'enter_reason_list': "all",
'exit_reason_list': "all", 'exit_reason_list': "all",
'indicator_list': "bb_upperband,ema_10" 'indicator_list': "rsi"
}) })
patch_exchange(mocker) patch_exchange(mocker)
result1 = pd.DataFrame({'pair': ['ETH/BTC', 'LTC/BTC'], result1 = pd.DataFrame({'pair': ['ETH/BTC', 'LTC/BTC'],
@ -84,6 +93,7 @@ def test_backtest_analysis_nomock(default_conf, mocker, caplog, testdatadir, cap
'--config', 'config.json', '--config', 'config.json',
'--datadir', str(testdatadir), '--datadir', str(testdatadir),
'--analysis_groups', '0', '--analysis_groups', '0',
'--indicator_list', 'rsi',
'--strategy', '--strategy',
'StrategyTestV3Analysis', 'StrategyTestV3Analysis',
] ]
@ -92,3 +102,6 @@ def test_backtest_analysis_nomock(default_conf, mocker, caplog, testdatadir, cap
captured = capsys.readouterr() captured = capsys.readouterr()
assert 'enter_tag_long' in captured.out assert 'enter_tag_long' in captured.out
assert '34.049' in captured.out
Backtesting.cleanup()