fix bug in Base4ActionRLEnv, improve example strats

This commit is contained in:
robcaulk 2022-09-04 11:21:54 +02:00
parent 240b529533
commit 27dce20b29
3 changed files with 9 additions and 13 deletions

View File

@ -31,7 +31,7 @@ class Base4ActionRLEnv(BaseEnvironment):
if self._current_tick == self._end_tick:
self._done = True
self.update_portfolio_log_returns(action)
self._update_unrealized_total_profit()
self._update_profit(action)
step_reward = self.calculate_reward(action)

View File

@ -11,7 +11,7 @@ from freqtrade.strategy import DecimalParameter, IntParameter, IStrategy, merge_
logger = logging.getLogger(__name__)
class ReinforcementLearningExample3ac(IStrategy):
class ReinforcementLearningExample4ac(IStrategy):
"""
Test strategy - used for testing freqAI functionalities.
DO not use in production.
@ -106,8 +106,8 @@ class ReinforcementLearningExample3ac(IStrategy):
# For RL, this is not a target, it is simply a filler until actions come out
# of the model.
# for Base3ActionEnv, 2 is netural (hold)
df["&-action"] = 2
# for Base4ActionEnv, 0 is netural (hold)
df["&-action"] = 0
return df
@ -119,14 +119,14 @@ class ReinforcementLearningExample3ac(IStrategy):
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
enter_long_conditions = [df["do_predict"] == 1, df["&-action"] == 1]
enter_long_conditions = [df["do_predict"] == 1, df["&-action"] == 2]
if enter_long_conditions:
df.loc[
reduce(lambda x, y: x & y, enter_long_conditions), ["enter_long", "enter_tag"]
] = (1, "long")
enter_short_conditions = [df["do_predict"] == 1, df["&-action"] == 2]
enter_short_conditions = [df["do_predict"] == 1, df["&-action"] == 3]
if enter_short_conditions:
df.loc[
@ -136,12 +136,8 @@ class ReinforcementLearningExample3ac(IStrategy):
return df
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
exit_long_conditions = [df["do_predict"] == 1, df["&-action"] == 2]
exit_long_conditions = [df["do_predict"] == 1, df["&-action"] == 1]
if exit_long_conditions:
df.loc[reduce(lambda x, y: x & y, exit_long_conditions), "exit_long"] = 1
exit_short_conditions = [df["do_predict"] == 1, df["&-action"] == 1]
if exit_short_conditions:
df.loc[reduce(lambda x, y: x & y, exit_short_conditions), "exit_short"] = 1
df.loc[reduce(lambda x, y: x & y, exit_long_conditions), "exit"] = 1
return df

View File

@ -107,7 +107,7 @@ class ReinforcementLearningExample5ac(IStrategy):
# For RL, there are no direct targets to set. This is filler (neutral)
# until the agent sends an action.
df["&-action"] = 2
df["&-action"] = 0
return df