add separator in folder name just incase an asset ends in an integer

This commit is contained in:
robcaulk 2022-07-21 11:25:28 +02:00
parent c9a6dc88a1
commit e7337728bf
3 changed files with 29 additions and 21 deletions

View File

@ -301,7 +301,7 @@ class FreqaiDataDrawer:
model_folders = [x for x in self.full_path.iterdir() if x.is_dir()] model_folders = [x for x in self.full_path.iterdir() if x.is_dir()]
pattern = re.compile(r"sub-train-(\w+)(\d{10})") pattern = re.compile(r"sub-train-(\w+)_(\d{10})")
delete_dict: Dict[str, Any] = {} delete_dict: Dict[str, Any] = {}

View File

@ -88,7 +88,8 @@ class FreqaiDataKitchen:
) )
self.data_path = Path( self.data_path = Path(
self.full_path / str("sub-train" + "-" + pair.split("/")[0] + str(trained_timestamp)) self.full_path
/ str("sub-train" + "-" + pair.split("/")[0] + "_" + str(trained_timestamp))
) )
return return
@ -179,6 +180,7 @@ class FreqaiDataKitchen:
model = load(self.data_path / str(self.model_filename + "_model.joblib")) model = load(self.data_path / str(self.model_filename + "_model.joblib"))
else: else:
from tensorflow import keras from tensorflow import keras
model = keras.models.load_model(self.data_path / str(self.model_filename + "_model.h5")) model = keras.models.load_model(self.data_path / str(self.model_filename + "_model.h5"))
if Path(self.data_path / str(self.model_filename + "_svm_model.joblib")).resolve().exists(): if Path(self.data_path / str(self.model_filename + "_svm_model.joblib")).resolve().exists():
@ -412,8 +414,7 @@ class FreqaiDataKitchen:
if not isinstance(train_split, int) or train_split < 1: if not isinstance(train_split, int) or train_split < 1:
raise OperationalException( raise OperationalException(
"train_period_days must be an integer greater than 0. " "train_period_days must be an integer greater than 0. " f"Got {train_split}."
f"Got {train_split}."
) )
train_period_days = train_split * SECONDS_IN_DAY train_period_days = train_split * SECONDS_IN_DAY
bt_period = bt_split * SECONDS_IN_DAY bt_period = bt_split * SECONDS_IN_DAY
@ -566,8 +567,10 @@ class FreqaiDataKitchen:
""" """
if self.keras: if self.keras:
logger.warning("SVM outlier removal not currently supported for Keras based models. " logger.warning(
"Skipping user requested function.") "SVM outlier removal not currently supported for Keras based models. "
"Skipping user requested function."
)
if predict: if predict:
self.do_predict = np.ones(len(self.data_dictionary["prediction_features"])) self.do_predict = np.ones(len(self.data_dictionary["prediction_features"]))
return return
@ -681,8 +684,7 @@ class FreqaiDataKitchen:
training than older data. training than older data.
""" """
wfactor = self.config["freqai"]["feature_parameters"]["weight_factor"] wfactor = self.config["freqai"]["feature_parameters"]["weight_factor"]
weights = np.exp( weights = np.exp(-np.arange(num_weights) / (wfactor * num_weights))[::-1]
- np.arange(num_weights) / (wfactor * num_weights))[::-1]
return weights return weights
def append_predictions(self, predictions, do_predict, len_dataframe): def append_predictions(self, predictions, do_predict, len_dataframe):
@ -731,10 +733,10 @@ class FreqaiDataKitchen:
def create_fulltimerange(self, backtest_tr: str, backtest_period_days: int) -> str: def create_fulltimerange(self, backtest_tr: str, backtest_period_days: int) -> str:
if not isinstance(backtest_period_days, int): if not isinstance(backtest_period_days, int):
raise OperationalException('backtest_period_days must be an integer') raise OperationalException("backtest_period_days must be an integer")
if backtest_period_days < 0: if backtest_period_days < 0:
raise OperationalException('backtest_period_days must be positive') raise OperationalException("backtest_period_days must be positive")
backtest_timerange = TimeRange.parse_timerange(backtest_tr) backtest_timerange = TimeRange.parse_timerange(backtest_tr)
@ -743,8 +745,9 @@ class FreqaiDataKitchen:
datetime.datetime.now(tz=datetime.timezone.utc).timestamp() datetime.datetime.now(tz=datetime.timezone.utc).timestamp()
) )
backtest_timerange.startts = (backtest_timerange.startts backtest_timerange.startts = (
- backtest_period_days * SECONDS_IN_DAY) backtest_timerange.startts - backtest_period_days * SECONDS_IN_DAY
)
start = datetime.datetime.utcfromtimestamp(backtest_timerange.startts) start = datetime.datetime.utcfromtimestamp(backtest_timerange.startts)
stop = datetime.datetime.utcfromtimestamp(backtest_timerange.stopts) stop = datetime.datetime.utcfromtimestamp(backtest_timerange.stopts)
full_timerange = start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d") full_timerange = start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d")
@ -790,8 +793,9 @@ class FreqaiDataKitchen:
data_load_timerange = TimeRange() data_load_timerange = TimeRange()
# find the max indicator length required # find the max indicator length required
max_timeframe_chars = self.freqai_config.get( max_timeframe_chars = self.freqai_config.get("feature_parameters", {}).get(
"feature_parameters", {}).get("include_timeframes")[-1] "include_timeframes"
)[-1]
max_period = self.freqai_config.get("feature_parameters", {}).get( max_period = self.freqai_config.get("feature_parameters", {}).get(
"indicator_max_period_candles", 50 "indicator_max_period_candles", 50
) )
@ -858,7 +862,7 @@ class FreqaiDataKitchen:
coin, _ = pair.split("/") coin, _ = pair.split("/")
self.data_path = Path( self.data_path = Path(
self.full_path self.full_path
/ str("sub-train" + "-" + pair.split("/")[0] + str(int(trained_timerange.stopts))) / str("sub-train" + "-" + pair.split("/")[0] + "_" + str(int(trained_timerange.stopts)))
) )
self.model_filename = "cb_" + coin.lower() + "_" + str(int(trained_timerange.stopts)) self.model_filename = "cb_" + coin.lower() + "_" + str(int(trained_timerange.stopts))
@ -942,8 +946,9 @@ class FreqaiDataKitchen:
def set_all_pairs(self) -> None: def set_all_pairs(self) -> None:
self.all_pairs = copy.deepcopy(self.freqai_config.get( self.all_pairs = copy.deepcopy(
'feature_parameters', {}).get('include_corr_pairlist', [])) self.freqai_config.get("feature_parameters", {}).get("include_corr_pairlist", [])
)
for pair in self.config.get("exchange", "").get("pair_whitelist"): for pair in self.config.get("exchange", "").get("pair_whitelist"):
if pair not in self.all_pairs: if pair not in self.all_pairs:
self.all_pairs.append(pair) self.all_pairs.append(pair)
@ -987,8 +992,9 @@ class FreqaiDataKitchen:
corr_dataframes: Dict[Any, Any] = {} corr_dataframes: Dict[Any, Any] = {}
base_dataframes: Dict[Any, Any] = {} base_dataframes: Dict[Any, Any] = {}
historic_data = self.dd.historic_data historic_data = self.dd.historic_data
pairs = self.freqai_config.get('feature_parameters', {}).get( pairs = self.freqai_config.get("feature_parameters", {}).get(
'include_corr_pairlist', []) "include_corr_pairlist", []
)
for tf in self.freqai_config.get("feature_parameters", {}).get("include_timeframes"): for tf in self.freqai_config.get("feature_parameters", {}).get("include_timeframes"):
base_dataframes[tf] = self.slice_dataframe(timerange, historic_data[pair][tf]) base_dataframes[tf] = self.slice_dataframe(timerange, historic_data[pair][tf])
@ -1053,7 +1059,7 @@ class FreqaiDataKitchen:
dataframe: DataFrame = dataframe containing populated indicators dataframe: DataFrame = dataframe containing populated indicators
""" """
dataframe = base_dataframes[self.config["timeframe"]].copy() dataframe = base_dataframes[self.config["timeframe"]].copy()
pairs = self.freqai_config.get('feature_parameters', {}).get('include_corr_pairlist', []) pairs = self.freqai_config.get("feature_parameters", {}).get("include_corr_pairlist", [])
sgi = True sgi = True
for tf in self.freqai_config.get("feature_parameters", {}).get("include_timeframes"): for tf in self.freqai_config.get("feature_parameters", {}).get("include_timeframes"):
dataframe = strategy.populate_any_indicators( dataframe = strategy.populate_any_indicators(
@ -1086,7 +1092,8 @@ class FreqaiDataKitchen:
Fit the labels with a gaussian distribution Fit the labels with a gaussian distribution
""" """
import scipy as spy import scipy as spy
num_candles = self.freqai_config.get('fit_live_predictions_candles', 100)
num_candles = self.freqai_config.get("fit_live_predictions_candles", 100)
self.data["labels_mean"], self.data["labels_std"] = {}, {} self.data["labels_mean"], self.data["labels_std"] = {}, {}
for label in self.label_list: for label in self.label_list:
f = spy.stats.norm.fit(self.dd.historic_predictions[self.pair][label].tail(num_candles)) f = spy.stats.norm.fit(self.dd.historic_predictions[self.pair][label].tail(num_candles))

View File

@ -189,6 +189,7 @@ class IFreqaiModel(ABC):
"sub-train" "sub-train"
+ "-" + "-"
+ metadata["pair"].split("/")[0] + metadata["pair"].split("/")[0]
+ "_"
+ str(int(trained_timestamp.stopts)) + str(int(trained_timestamp.stopts))
) )
) )