Merge pull request #7868 from freqtrade/fix-add-state-info-bt

Fix add state info bt
This commit is contained in:
Matthias 2022-12-08 08:34:11 +01:00 committed by GitHub
commit fcbc1a8a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ from gym.utils import seeding
from pandas import DataFrame from pandas import DataFrame
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
from freqtrade.enums import RunMode
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -78,6 +79,12 @@ class BaseEnvironment(gym.Env):
# set here to default 5Ac, but all children envs can override this # set here to default 5Ac, but all children envs can override this
self.actions: Type[Enum] = BaseActions self.actions: Type[Enum] = BaseActions
self.custom_info: dict = {} self.custom_info: dict = {}
self.live: bool = False
if dp:
self.live = dp.runmode in (RunMode.DRY_RUN, RunMode.LIVE)
if not self.live and self.add_state_info:
self.add_state_info = False
logger.warning("add_state_info is not available in backtesting. Deactivating.")
def reset_env(self, df: DataFrame, prices: DataFrame, window_size: int, def reset_env(self, df: DataFrame, prices: DataFrame, window_size: int,
reward_kwargs: dict, starting_point=True): reward_kwargs: dict, starting_point=True):
@ -188,7 +195,7 @@ class BaseEnvironment(gym.Env):
""" """
features_window = self.signal_features[( features_window = self.signal_features[(
self._current_tick - self.window_size):self._current_tick] self._current_tick - self.window_size):self._current_tick]
if self.add_state_info: if self.add_state_info and self.live:
features_and_state = DataFrame(np.zeros((len(features_window), 3)), features_and_state = DataFrame(np.zeros((len(features_window), 3)),
columns=['current_profit_pct', columns=['current_profit_pct',
'position', 'position',