appease mypy

This commit is contained in:
robcaulk 2022-05-06 16:20:52 +02:00
parent a4f5811a5b
commit 178c2014b0
2 changed files with 25 additions and 14 deletions

View File

@ -8,6 +8,7 @@ from pathlib import Path
from typing import Any, Dict, List, Tuple from typing import Any, Dict, List, Tuple
import numpy as np import numpy as np
import numpy.typing as npt
import pandas as pd import pandas as pd
from joblib import dump, load from joblib import dump, load
from pandas import DataFrame from pandas import DataFrame
@ -35,14 +36,14 @@ class FreqaiDataKitchen:
self.data_dictionary: Dict[Any, Any] = {} self.data_dictionary: Dict[Any, Any] = {}
self.config = config self.config = config
self.freqai_config = config["freqai"] self.freqai_config = config["freqai"]
self.predictions = np.array([]) self.predictions: npt.ArrayLike = np.array([])
self.do_predict = np.array([]) self.do_predict: npt.ArrayLike = np.array([])
self.target_mean = np.array([]) self.target_mean: npt.ArrayLike = np.array([])
self.target_std = np.array([]) self.target_std: npt.ArrayLike = np.array([])
self.full_predictions = np.array([]) self.full_predictions: npt.ArrayLike = np.array([])
self.full_do_predict = np.array([]) self.full_do_predict: npt.ArrayLike = np.array([])
self.full_target_mean = np.array([]) self.full_target_mean: npt.ArrayLike = np.array([])
self.full_target_std = np.array([]) self.full_target_std: npt.ArrayLike = np.array([])
self.model_path = Path() self.model_path = Path()
self.model_filename = "" self.model_filename = ""
@ -123,6 +124,7 @@ class FreqaiDataKitchen:
:labels: cleaned labels ready to be split. :labels: cleaned labels ready to be split.
""" """
weights: npt.ArrayLike
if self.config["freqai"]["feature_parameters"]["weight_factor"] > 0: if self.config["freqai"]["feature_parameters"]["weight_factor"] > 0:
weights = self.set_weights_higher_recent(len(filtered_dataframe)) weights = self.set_weights_higher_recent(len(filtered_dataframe))
else: else:
@ -519,12 +521,13 @@ class FreqaiDataKitchen:
self.do_predict += do_predict self.do_predict += do_predict
self.do_predict -= 1 self.do_predict -= 1
def set_weights_higher_recent(self, num_weights: int) -> int: def set_weights_higher_recent(self, num_weights: int) -> npt.ArrayLike:
""" """
Set weights so that recent data is more heavily weighted during Set weights so that recent data is more heavily weighted during
training than older data. training than older data.
""" """
weights = np.zeros(num_weights)
weights = np.zeros_like(num_weights)
for i in range(1, len(weights)): for i in range(1, len(weights)):
weights[len(weights) - i] = np.exp( weights[len(weights) - i] = np.exp(
-i / (self.config["freqai"]["feature_parameters"]["weight_factor"] * num_weights) -i / (self.config["freqai"]["feature_parameters"]["weight_factor"] * num_weights)

View File

@ -4,10 +4,12 @@ from abc import ABC, abstractmethod
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
import numpy as np import numpy.typing as npt
import pandas as pd import pandas as pd
from pandas import DataFrame from pandas import DataFrame
from freqtrade.data.dataprovider import DataProvider
from freqtrade.enums import RunMode
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
@ -37,8 +39,9 @@ class IFreqaiModel(ABC):
self.current_time = None self.current_time = None
self.model = None self.model = None
self.predictions = None self.predictions = None
self.live_trained_timerange = None
def start(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def start(self, dataframe: DataFrame, metadata: dict, dp: DataProvider) -> DataFrame:
""" """
Entry point to the FreqaiModel, it will train a new model if Entry point to the FreqaiModel, it will train a new model if
necesssary before making the prediction. necesssary before making the prediction.
@ -57,6 +60,9 @@ class IFreqaiModel(ABC):
self.pair = metadata["pair"] self.pair = metadata["pair"]
self.dh = FreqaiDataKitchen(self.config, dataframe) self.dh = FreqaiDataKitchen(self.config, dataframe)
if dp.runmode in (RunMode.DRY_RUN, RunMode.LIVE):
logger.info('testing live')
logger.info("going to train %s timeranges", len(self.dh.training_timeranges)) logger.info("going to train %s timeranges", len(self.dh.training_timeranges))
# Loop enforcing the sliding window training/backtesting paragigm # Loop enforcing the sliding window training/backtesting paragigm
@ -99,7 +105,7 @@ class IFreqaiModel(ABC):
:dataframe: the full dataframe for the present training period :dataframe: the full dataframe for the present training period
""" """
return dataframe return
@abstractmethod @abstractmethod
def train(self, unfiltered_dataframe: DataFrame, metadata: dict) -> Any: def train(self, unfiltered_dataframe: DataFrame, metadata: dict) -> Any:
@ -124,8 +130,10 @@ class IFreqaiModel(ABC):
all the training and test data/labels. all the training and test data/labels.
""" """
return
@abstractmethod @abstractmethod
def predict(self, dataframe: DataFrame) -> Tuple[np.array, np.array]: def predict(self, dataframe: DataFrame) -> Tuple[npt.ArrayLike, npt.ArrayLike]:
""" """
Filter the prediction features data and predict with it. Filter the prediction features data and predict with it.
:param: unfiltered_dataframe: Full dataframe for the current backtest period. :param: unfiltered_dataframe: Full dataframe for the current backtest period.