Use joblib instead of pickle, add signal candle read/write test, move docs to new Advanced Backtesting doc

This commit is contained in:
froggleston
2022-04-20 13:38:52 +01:00
parent 9421d19cba
commit b3cb722646
6 changed files with 128 additions and 86 deletions

View File

@@ -4,7 +4,6 @@ Various tool function for Freqtrade and scripts
import gzip
import hashlib
import logging
import pickle
import re
from copy import deepcopy
from datetime import datetime
@@ -13,6 +12,7 @@ from typing import Any, Iterator, List, Union
from typing.io import IO
from urllib.parse import urlparse
import joblib
import rapidjson
from freqtrade.constants import DECIMAL_PER_COIN_FALLBACK, DECIMALS_PER_COIN
@@ -87,7 +87,7 @@ def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool =
logger.debug(f'done json to "{filename}"')
def file_dump_pickle(filename: Path, data: Any, log: bool = True) -> None:
def file_dump_joblib(filename: Path, data: Any, log: bool = True) -> None:
"""
Dump object data into a file
:param filename: file to create
@@ -96,10 +96,10 @@ def file_dump_pickle(filename: Path, data: Any, log: bool = True) -> None:
"""
if log:
logger.info(f'dumping pickle to "{filename}"')
logger.info(f'dumping joblib to "{filename}"')
with open(filename, 'wb') as fp:
pickle.dump(data, fp)
logger.debug(f'done pickling to "{filename}"')
joblib.dump(data, fp)
logger.debug(f'done joblib dump to "{filename}"')
def json_load(datafile: IO) -> Any:

View File

@@ -11,7 +11,7 @@ from tabulate import tabulate
from freqtrade.constants import DATETIME_PRINT_FORMAT, LAST_BT_RESULT_FN, UNLIMITED_STAKE_AMOUNT
from freqtrade.data.btanalysis import (calculate_csum, calculate_market_change,
calculate_max_drawdown)
from freqtrade.misc import (decimals_per_coin, file_dump_json, file_dump_pickle,
from freqtrade.misc import (decimals_per_coin, file_dump_joblib, file_dump_json,
get_backtest_metadata_filename, round_coin_value)
@@ -45,7 +45,7 @@ def store_backtest_stats(recordfilename: Path, stats: Dict[str, DataFrame]) -> N
file_dump_json(latest_filename, {'latest_backtest': str(filename.name)})
def store_backtest_signal_candles(recordfilename: Path, candles: Dict[str, Dict]) -> None:
def store_backtest_signal_candles(recordfilename: Path, candles: Dict[str, Dict]) -> Path:
"""
Stores backtest trade signal candles
:param recordfilename: Path object, which can either be a filename or a directory.
@@ -63,7 +63,9 @@ def store_backtest_signal_candles(recordfilename: Path, candles: Dict[str, Dict]
f'{recordfilename.stem}-{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}_signals.pkl'
)
file_dump_pickle(filename, candles)
file_dump_joblib(filename, candles)
return filename
def _get_line_floatfmt(stake_currency: str) -> List[str]: