fix coding convention
This commit is contained in:
parent
d55092ff17
commit
45218faeb0
@ -26,11 +26,13 @@ class Positions(Enum):
|
|||||||
def opposite(self):
|
def opposite(self):
|
||||||
return Positions.Short if self == Positions.Long else Positions.Long
|
return Positions.Short if self == Positions.Long else Positions.Long
|
||||||
|
|
||||||
|
|
||||||
def mean_over_std(x):
|
def mean_over_std(x):
|
||||||
std = np.std(x, ddof=1)
|
std = np.std(x, ddof=1)
|
||||||
mean = np.mean(x)
|
mean = np.mean(x)
|
||||||
return mean / std if std > 0 else 0
|
return mean / std if std > 0 else 0
|
||||||
|
|
||||||
|
|
||||||
class Base5ActionRLEnv(gym.Env):
|
class Base5ActionRLEnv(gym.Env):
|
||||||
"""
|
"""
|
||||||
Base class for a 5 action environment
|
Base class for a 5 action environment
|
||||||
@ -250,42 +252,58 @@ class Base5ActionRLEnv(gym.Env):
|
|||||||
if len(self.close_trade_profit):
|
if len(self.close_trade_profit):
|
||||||
# aim x2 rw
|
# aim x2 rw
|
||||||
if self.close_trade_profit[-1] > self.profit_aim * self.rr:
|
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)
|
last_trade_price = self.add_buy_fee(
|
||||||
current_price = self.add_sell_fee(self.prices.iloc[self._current_tick].open)
|
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)
|
return float((np.log(current_price) - np.log(last_trade_price)) * 2)
|
||||||
# less than aim x1 rw
|
# less than aim x1 rw
|
||||||
elif self.close_trade_profit[-1] < self.profit_aim * self.rr:
|
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)
|
last_trade_price = self.add_buy_fee(
|
||||||
current_price = self.add_sell_fee(self.prices.iloc[self._current_tick].open)
|
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))
|
return float(np.log(current_price) - np.log(last_trade_price))
|
||||||
# # less than RR SL x2 neg rw
|
# # less than RR SL x2 neg rw
|
||||||
# elif self.close_trade_profit[-1] < (self.profit_aim * -1):
|
# 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)
|
# last_trade_price = self.add_buy_fee(
|
||||||
# current_price = self.add_sell_fee(self.prices.iloc[self._current_tick].open)
|
# 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
|
# return float((np.log(current_price) - np.log(last_trade_price)) * 2) * -1
|
||||||
|
|
||||||
|
|
||||||
# close short
|
# close short
|
||||||
if action == Actions.Short_buy.value and self._position == Positions.Short:
|
if action == Actions.Short_buy.value and self._position == Positions.Short:
|
||||||
if len(self.close_trade_profit):
|
if len(self.close_trade_profit):
|
||||||
# aim x2 rw
|
# aim x2 rw
|
||||||
if self.close_trade_profit[-1] > self.profit_aim * self.rr:
|
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)
|
last_trade_price = self.add_sell_fee(
|
||||||
current_price = self.add_buy_fee(self.prices.iloc[self._current_tick].open)
|
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)
|
return float((np.log(last_trade_price) - np.log(current_price)) * 2)
|
||||||
# less than aim x1 rw
|
# less than aim x1 rw
|
||||||
elif self.close_trade_profit[-1] < self.profit_aim * self.rr:
|
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)
|
last_trade_price = self.add_sell_fee(
|
||||||
current_price = self.add_buy_fee(self.prices.iloc[self._current_tick].open)
|
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))
|
return float(np.log(last_trade_price) - np.log(current_price))
|
||||||
# # less than RR SL x2 neg rw
|
# # less than RR SL x2 neg rw
|
||||||
# elif self.close_trade_profit[-1] > self.profit_aim * self.rr:
|
# 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)
|
# last_trade_price = self.add_sell_fee(
|
||||||
# current_price = self.add_buy_fee(self.prices.iloc[self._current_tick].open)
|
# 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 float((np.log(last_trade_price) - np.log(current_price)) * 2) * -1
|
||||||
return 0.
|
return 0.
|
||||||
|
|
||||||
|
|
||||||
def _update_profit(self, action):
|
def _update_profit(self, action):
|
||||||
# if self._is_trade(action) or self._done:
|
# if self._is_trade(action) or self._done:
|
||||||
if self._is_trade(action) or self._done:
|
if self._is_trade(action) or self._done:
|
||||||
|
Loading…
Reference in New Issue
Block a user