exportfilename can be a file or directory
This commit is contained in:
parent
2ed808da1f
commit
7c5587aeaa
@ -199,7 +199,7 @@ class Configuration:
|
|||||||
config['exportfilename'] = Path(config['exportfilename'])
|
config['exportfilename'] = Path(config['exportfilename'])
|
||||||
else:
|
else:
|
||||||
config['exportfilename'] = (config['user_data_dir']
|
config['exportfilename'] = (config['user_data_dir']
|
||||||
/ 'backtest_results/backtest-result.json')
|
/ 'backtest_results')
|
||||||
|
|
||||||
def _process_optimize_options(self, config: Dict[str, Any]) -> None:
|
def _process_optimize_options(self, config: Dict[str, Any]) -> None:
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ def get_latest_backtest_filename(directory: Union[Path, str]) -> str:
|
|||||||
filename = directory / LAST_BT_RESULT_FN
|
filename = directory / LAST_BT_RESULT_FN
|
||||||
|
|
||||||
if not filename.is_file():
|
if not filename.is_file():
|
||||||
raise ValueError(f"Directory '{directory}' does not seem to contain backtest statistics yet.")
|
raise ValueError(
|
||||||
|
f"Directory '{directory}' does not seem to contain backtest statistics yet.")
|
||||||
|
|
||||||
with filename.open() as file:
|
with filename.open() as file:
|
||||||
data = json_load(file)
|
data = json_load(file)
|
||||||
@ -57,9 +58,11 @@ def load_backtest_stats(filename: Union[Path, str]) -> Dict[str, Any]:
|
|||||||
"""
|
"""
|
||||||
if isinstance(filename, str):
|
if isinstance(filename, str):
|
||||||
filename = Path(filename)
|
filename = Path(filename)
|
||||||
|
if filename.is_dir():
|
||||||
|
filename = get_latest_backtest_filename(filename)
|
||||||
if not filename.is_file():
|
if not filename.is_file():
|
||||||
raise ValueError(f"File {filename} does not exist.")
|
raise ValueError(f"File {filename} does not exist.")
|
||||||
|
logger.info(f"Loading backtest result from {filename}")
|
||||||
with filename.open() as file:
|
with filename.open() as file:
|
||||||
data = json_load(file)
|
data = json_load(file)
|
||||||
|
|
||||||
|
@ -16,12 +16,17 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def store_backtest_stats(recordfilename: Path, stats: Dict[str, DataFrame]) -> None:
|
def store_backtest_stats(recordfilename: Path, stats: Dict[str, DataFrame]) -> None:
|
||||||
|
|
||||||
filename = Path.joinpath(recordfilename.parent,
|
if recordfilename.is_dir():
|
||||||
f'{recordfilename.stem}-{datetime.now().isoformat()}'
|
filename = recordfilename / \
|
||||||
).with_suffix(recordfilename.suffix)
|
f'backtest-result-{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.json'
|
||||||
|
else:
|
||||||
|
filename = Path.joinpath(
|
||||||
|
recordfilename.parent,
|
||||||
|
f'{recordfilename.stem}-{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}'
|
||||||
|
).with_suffix(recordfilename.suffix)
|
||||||
file_dump_json(filename, stats)
|
file_dump_json(filename, stats)
|
||||||
|
|
||||||
latest_filename = Path.joinpath(recordfilename.parent, LAST_BT_RESULT_FN)
|
latest_filename = Path.joinpath(filename.parent, LAST_BT_RESULT_FN)
|
||||||
file_dump_json(latest_filename, {'latest_backtest': str(filename.name)})
|
file_dump_json(latest_filename, {'latest_backtest': str(filename.name)})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user