auto build full_timerange and self manage training_timerange
This commit is contained in:
@@ -3,6 +3,7 @@ import datetime
|
||||
import json
|
||||
import logging
|
||||
import pickle as pk
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
@@ -30,15 +31,10 @@ class DataHandler:
|
||||
|
||||
def __init__(self, config: Dict[str, Any], dataframe: DataFrame):
|
||||
self.full_dataframe = dataframe
|
||||
(self.training_timeranges, self.backtesting_timeranges) = self.split_timerange(
|
||||
config["freqai"]["full_timerange"],
|
||||
config["freqai"]["train_period"],
|
||||
config["freqai"]["backtest_period"],
|
||||
)
|
||||
self.data: Dict[Any, Any] = {}
|
||||
self.data_dictionary: Dict[Any, Any] = {}
|
||||
self.config = config
|
||||
self.freq_config = config["freqai"]
|
||||
self.freqai_config = config["freqai"]
|
||||
self.predictions = np.array([])
|
||||
self.do_predict = np.array([])
|
||||
self.target_mean = np.array([])
|
||||
@@ -46,6 +42,16 @@ class DataHandler:
|
||||
self.model_path = Path()
|
||||
self.model_filename = ""
|
||||
|
||||
self.full_timerange = self.create_fulltimerange(
|
||||
self.config["timerange"], self.freqai_config["train_period"]
|
||||
)
|
||||
|
||||
(self.training_timeranges, self.backtesting_timeranges) = self.split_timerange(
|
||||
self.full_timerange,
|
||||
config["freqai"]["train_period"],
|
||||
config["freqai"]["backtest_period"],
|
||||
)
|
||||
|
||||
def save_data(self, model: Any) -> None:
|
||||
"""
|
||||
Saves all data associated with a model for a single sub-train time range
|
||||
@@ -539,6 +545,29 @@ class DataHandler:
|
||||
|
||||
return
|
||||
|
||||
def create_fulltimerange(self, backtest_tr: str, backtest_period: int) -> str:
|
||||
backtest_timerange = TimeRange.parse_timerange(backtest_tr)
|
||||
|
||||
backtest_timerange.startts = backtest_timerange.startts - backtest_period * SECONDS_IN_DAY
|
||||
start = datetime.datetime.utcfromtimestamp(backtest_timerange.startts)
|
||||
stop = datetime.datetime.utcfromtimestamp(backtest_timerange.stopts)
|
||||
full_timerange = start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d")
|
||||
|
||||
self.full_path = Path(
|
||||
self.config["user_data_dir"]
|
||||
/ "models"
|
||||
/ str(full_timerange + self.freqai_config["identifier"])
|
||||
)
|
||||
|
||||
if not self.full_path.is_dir():
|
||||
self.full_path.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(
|
||||
Path(self.config["config_files"][0]).name,
|
||||
Path(self.full_path / self.config["config_files"][0]),
|
||||
)
|
||||
|
||||
return full_timerange
|
||||
|
||||
def np_encoder(self, object):
|
||||
if isinstance(object, np.generic):
|
||||
return object.item()
|
||||
|
||||
Reference in New Issue
Block a user