diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index cf6e18e64..972961b36 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -179,7 +179,7 @@ def load_trades_from_db(db_url: str, strategy: Optional[str] = None) -> pd.DataF filters = [] if strategy: - filters = Trade.strategy == strategy + filters.append(Trade.strategy == strategy) trades = pd.DataFrame([(t.pair, t.open_date.replace(tzinfo=timezone.utc), diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 8e25d9d89..c69442d46 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -31,20 +31,6 @@ def store_backtest_stats(recordfilename: Path, stats: Dict[str, DataFrame]) -> N file_dump_json(latest_filename, {'latest_backtest': str(filename.name)}) -def backtest_result_to_list(results: DataFrame) -> List[List]: - """ - Converts a list of Backtest-results to list - :param results: Dataframe containing results for one strategy - :return: List of Lists containing the trades - """ - # Return 0 as "index" for compatibility reasons (for now) - # TODO: Evaluate if we can remove this - return [[t.pair, t.profit_percent, t.open_date.timestamp(), - t.close_date.timestamp(), 0, t.trade_duration, - t.open_rate, t.close_rate, t.open_at_end, t.sell_reason.value] - for index, t in results.iterrows()] - - def _get_line_floatfmt() -> List[str]: """ Generate floatformat (goes in line with _generate_result_line()) diff --git a/tests/optimize/test_optimize_reports.py b/tests/optimize/test_optimize_reports.py index 2fab4578c..e5d98ca43 100644 --- a/tests/optimize/test_optimize_reports.py +++ b/tests/optimize/test_optimize_reports.py @@ -146,6 +146,25 @@ def test_generate_backtest_stats(default_conf, testdatadir): filename1.unlink() +def test_store_backtest_stats(testdatadir, mocker): + + dump_mock = mocker.patch('freqtrade.optimize.optimize_reports.file_dump_json') + + store_backtest_stats(testdatadir, {}) + + assert dump_mock.call_count == 2 + assert isinstance(dump_mock.call_args_list[0][0][0], Path) + assert str(dump_mock.call_args_list[0][0][0]).startswith(str(testdatadir/'backtest-result')) + + dump_mock.reset_mock() + filename = testdatadir / 'testresult.json' + store_backtest_stats(filename, {}) + assert dump_mock.call_count == 2 + assert isinstance(dump_mock.call_args_list[0][0][0], Path) + # result will be testdatadir / testresult-.json + assert str(dump_mock.call_args_list[0][0][0]).startswith(str(testdatadir / 'testresult')) + + def test_generate_pair_metrics(default_conf, mocker): results = pd.DataFrame(