Closed vincentfortin closed 4 years ago
Basically in the Stocks Market, we don't trade short. We buy a stock at a low price and sell it at a high price. So I implemented the reward function as you see. But you can inherit the StocksEnv
and change the reward function in the way you have mentioned and maybe you get better results.
Or you can do it in a simpler way if you don't want to use inheritance:
def _calculate_reward(self, action):
step_reward = 0
trade = False
if ((action == Actions.Buy.value and self._position == Positions.Short) or
(action == Actions.Sell.value and self._position == Positions.Long)):
trade = True
if trade:
current_price = self.prices[self._current_tick]
last_trade_price = self.prices[self._last_trade_tick]
price_diff = current_price - last_trade_price
if self._position == Positions.Long:
step_reward += price_diff
else:
step_reward -= price_diff
return step_reward
StocksEnv._calculate_reward = _calculate_reward
Thanks, also changed the profit function to account for shorting.
Not sure if here is the best place to ask a question.
In the
_calculate_reward
function, the reward does not seem to consider when shorting. Trade is true, but it does not add reward when we short and price goes down or remove reward if price goes up when shorting.Shouldn't it be changed to: