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

Requesting an article explaining the math of StockTradingEnv #3

Open
fightthepower opened this issue May 4, 2019 · 0 comments
Open

Comments

@fightthepower
Copy link

First of all thank you for writing those articles. I was searching for a stock simulating system similar to gym. In your article you have given a good explanation of programming a gym enviornment but many of us don't know finance, so can you please add an article explaining the math behind it.

 if action_type < 1:
    # Buy amount % of balance in shares
    total_possible = self.balance / current_price
    shares_bought = total_possible * amount
    prev_cost = self.cost_basis * self.shares_held
    additional_cost = shares_bought * current_price
    self.balance -= additional_cost
    self.cost_basis = (prev_cost + additional_cost) / 
                            (self.shares_held + shares_bought)
    self.shares_held += shares_bought
  elif actionType < 2:
    # Sell amount % of shares held
    shares_sold = self.shares_held * amount . 
    self.balance += shares_sold * current_price
    self.shares_held -= shares_sold
    self.total_shares_sold += shares_sold
    self.total_sales_value += shares_sold * current_price

Look at this code I really don't know what is happening inside those conditional statements. It seems that it only buy and sell and don't hold it. I for one wants to build a simulator which trade x number of shares(not percentage of balance) for a amount of say 100 dollars. Without understanding the math I really can't build a new stocksimenv.

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