From 45218faeb0c91f07c40e20071278bee2b865f084 Mon Sep 17 00:00:00 2001 From: sonnhfit Date: Thu, 18 Aug 2022 17:01:04 +0700 Subject: [PATCH] fix coding convention --- freqtrade/freqai/RL/Base5ActionRLEnv.py | 46 +++++++++++++++++-------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/freqtrade/freqai/RL/Base5ActionRLEnv.py b/freqtrade/freqai/RL/Base5ActionRLEnv.py index 574e71857..5f817f14e 100644 --- a/freqtrade/freqai/RL/Base5ActionRLEnv.py +++ b/freqtrade/freqai/RL/Base5ActionRLEnv.py @@ -26,11 +26,13 @@ class Positions(Enum): def opposite(self): return Positions.Short if self == Positions.Long else Positions.Long + def mean_over_std(x): std = np.std(x, ddof=1) mean = np.mean(x) return mean / std if std > 0 else 0 + class Base5ActionRLEnv(gym.Env): """ Base class for a 5 action environment @@ -250,42 +252,58 @@ class Base5ActionRLEnv(gym.Env): if len(self.close_trade_profit): # aim x2 rw if self.close_trade_profit[-1] > self.profit_aim * self.rr: - last_trade_price = self.add_buy_fee(self.prices.iloc[self._last_trade_tick].open) - current_price = self.add_sell_fee(self.prices.iloc[self._current_tick].open) + last_trade_price = self.add_buy_fee( + self.prices.iloc[self._last_trade_tick].open) + current_price = self.add_sell_fee( + self.prices.iloc[self._current_tick].open) return float((np.log(current_price) - np.log(last_trade_price)) * 2) # less than aim x1 rw elif self.close_trade_profit[-1] < self.profit_aim * self.rr: - last_trade_price = self.add_buy_fee(self.prices.iloc[self._last_trade_tick].open) - current_price = self.add_sell_fee(self.prices.iloc[self._current_tick].open) + last_trade_price = self.add_buy_fee( + self.prices.iloc[self._last_trade_tick].open + ) + current_price = self.add_sell_fee( + self.prices.iloc[self._current_tick].open + ) return float(np.log(current_price) - np.log(last_trade_price)) # # less than RR SL x2 neg rw # elif self.close_trade_profit[-1] < (self.profit_aim * -1): - # last_trade_price = self.add_buy_fee(self.prices.iloc[self._last_trade_tick].open) - # current_price = self.add_sell_fee(self.prices.iloc[self._current_tick].open) + # last_trade_price = self.add_buy_fee( + # self.prices.iloc[self._last_trade_tick].open) + # current_price = self.add_sell_fee( + # self.prices.iloc[self._current_tick].open) # return float((np.log(current_price) - np.log(last_trade_price)) * 2) * -1 - # close short if action == Actions.Short_buy.value and self._position == Positions.Short: if len(self.close_trade_profit): # aim x2 rw if self.close_trade_profit[-1] > self.profit_aim * self.rr: - last_trade_price = self.add_sell_fee(self.prices.iloc[self._last_trade_tick].open) - current_price = self.add_buy_fee(self.prices.iloc[self._current_tick].open) + last_trade_price = self.add_sell_fee( + self.prices.iloc[self._last_trade_tick].open + ) + current_price = self.add_buy_fee( + self.prices.iloc[self._current_tick].open + ) return float((np.log(last_trade_price) - np.log(current_price)) * 2) # less than aim x1 rw elif self.close_trade_profit[-1] < self.profit_aim * self.rr: - last_trade_price = self.add_sell_fee(self.prices.iloc[self._last_trade_tick].open) - current_price = self.add_buy_fee(self.prices.iloc[self._current_tick].open) + last_trade_price = self.add_sell_fee( + self.prices.iloc[self._last_trade_tick].open + ) + current_price = self.add_buy_fee( + self.prices.iloc[self._current_tick].open + ) return float(np.log(last_trade_price) - np.log(current_price)) # # less than RR SL x2 neg rw # elif self.close_trade_profit[-1] > self.profit_aim * self.rr: - # last_trade_price = self.add_sell_fee(self.prices.iloc[self._last_trade_tick].open) - # current_price = self.add_buy_fee(self.prices.iloc[self._current_tick].open) + # last_trade_price = self.add_sell_fee( + # self.prices.iloc[self._last_trade_tick].open) + # current_price = self.add_buy_fee( + # self.prices.iloc[self._current_tick].open) # return float((np.log(last_trade_price) - np.log(current_price)) * 2) * -1 return 0. - def _update_profit(self, action): # if self._is_trade(action) or self._done: if self._is_trade(action) or self._done: