RL-Bitcoin-trading-bot icon indicating copy to clipboard operation
RL-Bitcoin-trading-bot copied to clipboard

get_reward() returns None, later results in exception

Open HoaxParagon opened this issue 4 years ago • 0 comments

    # Calculate reward
    def get_reward(self):
        if self.episode_orders > 1 and self.episode_orders > self.prev_episode_orders:
            self.prev_episode_orders = self.episode_orders
            if self.trades[-1]['type'] == "buy" and self.trades[-2]['type'] == "sell":
                reward = self.trades[-2]['total']*self.trades[-2]['current_price'] - self.trades[-2]['total']*self.trades[-1]['current_price']
                self.trades[-1]["Reward"] = reward
                return reward
            elif self.trades[-1]['type'] == "sell" and self.trades[-2]['type'] == "buy":
                reward = self.trades[-1]['total']*self.trades[-1]['current_price'] - self.trades[-2]['total']*self.trades[-2]['current_price']
                self.trades[-1]["Reward"] = reward
                return reward
             # return needed

        else:
            return 0

This code returns None sometimes and it doesn't seem to have any rhyme or reason to do so. I noticed there's no else in the nested conditional to return anything and I believe this is the source of the error as my commented code would suggest above.

HoaxParagon avatar Jul 02 '21 18:07 HoaxParagon