feat: improved support for split "export-directory" and export-filenames
This commit is contained in:
@@ -72,7 +72,7 @@ def start_backtesting_show(args: dict[str, Any]) -> None:
|
|||||||
from freqtrade.data.btanalysis import load_backtest_stats
|
from freqtrade.data.btanalysis import load_backtest_stats
|
||||||
from freqtrade.optimize.optimize_reports import show_backtest_results, show_sorted_pairlist
|
from freqtrade.optimize.optimize_reports import show_backtest_results, show_sorted_pairlist
|
||||||
|
|
||||||
results = load_backtest_stats(config["exportdirectory"])
|
results = load_backtest_stats(config["exportdirectory"], config["exportfilename"])
|
||||||
|
|
||||||
show_backtest_results(config, results)
|
show_backtest_results(config, results)
|
||||||
show_sorted_pairlist(config, results)
|
show_sorted_pairlist(config, results)
|
||||||
|
|||||||
@@ -155,33 +155,41 @@ def load_backtest_metadata(filename: Path | str) -> dict[str, Any]:
|
|||||||
raise OperationalException("Unexpected error while loading backtest metadata.") from e
|
raise OperationalException("Unexpected error while loading backtest metadata.") from e
|
||||||
|
|
||||||
|
|
||||||
def load_backtest_stats(filename: Path | str) -> BacktestResultType:
|
def load_backtest_stats(
|
||||||
|
file_or_directory: Path | str, filename: Path | str | None = None
|
||||||
|
) -> BacktestResultType:
|
||||||
"""
|
"""
|
||||||
Load backtest statistics file.
|
Load backtest statistics file.
|
||||||
:param filename: pathlib.Path object, or string pointing to the file.
|
:param file_or_directory: pathlib.Path object, or string pointing to the directory,
|
||||||
|
or absolute/relative path to the backtest results file.
|
||||||
|
:param filename: Optional filename to load from (if different from the main filename).
|
||||||
|
Only valid when loading from a directory.
|
||||||
:return: a dictionary containing the resulting file.
|
:return: a dictionary containing the resulting file.
|
||||||
"""
|
"""
|
||||||
if isinstance(filename, str):
|
if isinstance(file_or_directory, str):
|
||||||
filename = Path(filename)
|
file_or_directory = Path(file_or_directory)
|
||||||
if filename.is_dir():
|
if file_or_directory.is_dir():
|
||||||
filename = filename / get_latest_backtest_filename(filename)
|
if not filename:
|
||||||
if not filename.is_file():
|
filename = get_latest_backtest_filename(file_or_directory)
|
||||||
raise ValueError(f"File {filename} does not exist.")
|
fn = file_or_directory / filename
|
||||||
logger.info(f"Loading backtest result from {filename}")
|
else:
|
||||||
|
fn = file_or_directory
|
||||||
|
|
||||||
if filename.suffix == ".zip":
|
if not fn.is_file():
|
||||||
|
raise ValueError(f"File {fn} does not exist.")
|
||||||
|
logger.info(f"Loading backtest result from {fn}")
|
||||||
|
|
||||||
|
if fn.suffix == ".zip":
|
||||||
data = json_load(
|
data = json_load(
|
||||||
StringIO(
|
StringIO(load_file_from_zip(fn, fn.with_suffix(".json").name).decode("utf-8"))
|
||||||
load_file_from_zip(filename, filename.with_suffix(".json").name).decode("utf-8")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
with filename.open() as file:
|
with fn.open() as file:
|
||||||
data = json_load(file)
|
data = json_load(file)
|
||||||
|
|
||||||
# Legacy list format does not contain metadata.
|
# Legacy list format does not contain metadata.
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
data["metadata"] = load_backtest_metadata(filename)
|
data["metadata"] = load_backtest_metadata(fn)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user