Open MariamDundua opened 3 years ago
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:
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)
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
When the selling of stock happens, and the cost is updated, I think this update with new amount of shares. I mean, first time
self.state[index+STOCK_DIM+1]
is updated and this updated version is participated to compute costs