diff --git a/docs/freqai-reinforcement-learning.md b/docs/freqai-reinforcement-learning.md index a09b4c5d0..4442a2f4f 100644 --- a/docs/freqai-reinforcement-learning.md +++ b/docs/freqai-reinforcement-learning.md @@ -58,11 +58,12 @@ where `ReinforcementLearner` will use the templated `ReinforcementLearner` from Most of the function remains the same as for typical Regressors, however, the function above shows how the strategy must pass the raw price data to the agent so that it has access to raw OHLCV in the training environment: ```python + def feature_engineering_standard(): # The following features are necessary for RL models - informative[f"%-{pair}raw_close"] = informative["close"] - informative[f"%-{pair}raw_open"] = informative["open"] - informative[f"%-{pair}raw_high"] = informative["high"] - informative[f"%-{pair}raw_low"] = informative["low"] + informative[f"%-raw_close"] = informative["close"] + informative[f"%-raw_open"] = informative["open"] + informative[f"%-raw_high"] = informative["high"] + informative[f"%-raw_low"] = informative["low"] ``` Finally, there is no explicit "label" to make - instead it is necessary to assign the `&-action` column which will contain the agent's actions when accessed in `populate_entry/exit_trends()`. In the present example, the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action. diff --git a/freqtrade/__init__.py b/freqtrade/__init__.py index 5430cd2d0..18b6c9130 100644 --- a/freqtrade/__init__.py +++ b/freqtrade/__init__.py @@ -2,18 +2,19 @@ __version__ = '2023.1.dev' if 'dev' in __version__: + from pathlib import Path try: import subprocess + freqtrade_basedir = Path(__file__).parent __version__ = __version__ + '-' + subprocess.check_output( ['git', 'log', '--format="%h"', '-n 1'], - stderr=subprocess.DEVNULL).decode("utf-8").rstrip().strip('"') + stderr=subprocess.DEVNULL, cwd=freqtrade_basedir).decode("utf-8").rstrip().strip('"') except Exception: # pragma: no cover # git not available, ignore try: # Try Fallback to freqtrade_commit file (created by CI while building docker image) - from pathlib import Path versionfile = Path('./freqtrade_commit') if versionfile.is_file(): __version__ = f"docker-{__version__}-{versionfile.read_text()[:8]}" diff --git a/freqtrade/misc.py b/freqtrade/misc.py index 93e8da6dd..34df3185b 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -269,6 +269,8 @@ def dataframe_to_json(dataframe: pd.DataFrame) -> str: def default(z): if isinstance(z, pd.Timestamp): return z.timestamp() * 1e3 + if z is pd.NaT: + return 'NaT' raise TypeError return str(orjson.dumps(dataframe.to_dict(orient='split'), default=default), 'utf-8') diff --git a/tests/test_misc.py b/tests/test_misc.py index 2da45bad9..596c7bd51 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -5,6 +5,7 @@ from copy import deepcopy from pathlib import Path from unittest.mock import MagicMock +import pandas as pd import pytest from freqtrade.misc import (dataframe_to_json, decimals_per_coin, deep_merge_dicts, file_dump_json, @@ -231,3 +232,7 @@ def test_dataframe_json(ohlcv_history): assert len(ohlcv_history) == len(dataframe) assert_frame_equal(ohlcv_history, dataframe) + ohlcv_history.at[1, 'date'] = pd.NaT + json = dataframe_to_json(ohlcv_history) + + dataframe = json_to_dataframe(json)