Git Product home page Git Product logo

Comments (1)

emjay032 avatar emjay032 commented on August 15, 2024

self.cost is a is a variable to track the cost of the agents strategy and updated after each sell/buy action
+=
it will change the account balance because the cost for trading a stock is directly substracted from the money the agent has.
It will not update the new amount of shares:
What this function does:

  1. check if the stock is currently held if yes the sell the amount the agent decided as an action
  2. update the balance by incresasing the balance money you get from the selling of that stock (minus transaction costs so (1-TRANSACTION_FFE_PERCENT)) (not min(abs(action,self.state[index+STOCK_DIM+1]) ensures that you can just sell maximum the amount of shares currently held of that stock because if the rescaled action says "sell 10 stocks but you just hold 5 stocks" you can just sell 5 stocks because no short selling is allowed.
  3. update the number of that particular stock currently held if you hold 10 stocks and sell 5 then you just hold 5 stocks
  4. update the cost variable to track the money spend by follwing the agents strategy
  5. update te count of trades so after each sell/buy action it is increased by 1 to see in the end how much trades the agent made

so yes you are right every sell action deductes the transaction cost directly from the balance

i created a similar environment but seperated the balance, stock_prices, num_stocks in the portfolio to increase readability
just think about it as this

def _sell_stock(self, index, action):

self.holdings[index] > 0: (step 1)
#update balance, holding, cost, trade_count
amount = round(min(abs(action),self.holdings[index])) #amount to trade (step 2)
stock_sell_activity = [self.day,index,amount] (aditionally Track sell activity)
self.balance += self.stock_price[index]amount(1-TRANSACTION_FEE_PERCENT-BPS) (step 2) update balance note BPS is a spread considere because bid and aski prices differ
self.holdings[index] -= amount (step 3) update the hodling of the particular stock by substracting the amount sold
self.cost += self.stock_price[index]amount(TRANSACTION_FEE_PERCENT+BPS) (step 4)
self.daily_cost += self.stock_price[index]amount(TRANSACTION_FEE_PERCENT+BPS) (aditionally track daily cost of the strategy)
self.daily_sell_amount += round(self.stock_price[index]amount(1-TRANSACTION_FEE_PERCENT-BPS)) (additonally to tracl daily amount sold )
self.trades+=1 (step 5)
else:
pass

from finrl-trading.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.