Don't start plotting profit without trades

plotting profit only makes sense when trades are available
This commit is contained in:
Matthias 2020-05-21 07:13:08 +02:00
parent 1a984ac677
commit 1f386c570d
2 changed files with 12 additions and 2 deletions

View File

@ -10,8 +10,9 @@ from freqtrade.data.btanalysis import (calculate_max_drawdown,
create_cum_profit,
extract_trades_of_period, load_trades)
from freqtrade.data.converter import trim_dataframe
from freqtrade.exchange import timeframe_to_prev_date
from freqtrade.data.history import load_data
from freqtrade.exceptions import OperationalException
from freqtrade.exchange import timeframe_to_prev_date
from freqtrade.misc import pair_to_filename
from freqtrade.resolvers import StrategyResolver
@ -504,6 +505,9 @@ def plot_profit(config: Dict[str, Any]) -> None:
trades = trades[(trades['pair'].isin(plot_elements["pairs"]))
& (~trades['close_time'].isnull())
]
if len(trades) == 0:
raise OperationalException("No trades found, cannot generate Profit-plot without "
"trades from either Backtest result or database.")
# Create an average close price of all the pairs that were involved.
# this could be useful to gauge the overall market trend

View File

@ -374,7 +374,7 @@ def test_start_plot_profit_error(mocker):
def test_plot_profit(default_conf, mocker, testdatadir, caplog):
default_conf['trade_source'] = 'file'
default_conf["datadir"] = testdatadir
default_conf['exportfilename'] = testdatadir / "backtest-result_test.json"
default_conf['exportfilename'] = testdatadir / "backtest-result_test_nofile.json"
default_conf['pairs'] = ["ETH/BTC", "LTC/BTC"]
profit_mock = MagicMock()
@ -384,6 +384,12 @@ def test_plot_profit(default_conf, mocker, testdatadir, caplog):
generate_profit_graph=profit_mock,
store_plot_file=store_mock
)
with pytest.raises(OperationalException,
match=r"No trades found, cannot generate Profit-plot.*"):
plot_profit(default_conf)
default_conf['exportfilename'] = testdatadir / "backtest-result_test.json"
plot_profit(default_conf)
# Plot-profit generates one combined plot