Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

def get_reward(self, action) #2

Open
formidiable opened this issue Jan 4, 2022 · 0 comments
Open

def get_reward(self, action) #2

formidiable opened this issue Jan 4, 2022 · 0 comments

Comments

@formidiable
Copy link

formidiable commented Jan 4, 2022

def get_reward(self, action):
    """
    @param action: based on the action taken it returns the reward
    @return: reward
    """

    reward_index_first = self.current_state_index + self.start_index_reward
    reward_index_last = self.current_state_index + self.start_index_reward + self.n_step \
        if self.current_state_index + self.n_step < len(self.states) else len(self.close_price) - 1

    p1 = self.close_price[reward_index_first]
    p2 = self.close_price[reward_index_last]

    reward = 0
    if action == 0 or (action == 1 and self.own_share):  # Buy Share or Hold Share
        reward = ((1 - self.trading_cost_ratio) ** 2 * p2 / p1 - 1) * 100  # profit in percent
    elif action == 2 or (action == 1 and not self.own_share):  # Sell Share or No Share
        # consider the transaction in the reverse order
        reward = ((1 - self.trading_cost_ratio) ** 2 * p1 / p2 - 1) * 100

    return reward

Sorry, the function is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant