FinRock icon indicating copy to clipboard operation
FinRock copied to clipboard

Allowing Stock Purchases Beyond Available Balance in Trading Environment Simulation

Open Root-DE opened this issue 10 months ago • 0 comments

I also have a question regarding the buying of stocks. Perhaps I'm misunderstanding something, but it seems to me that the environment does not prevent the purchase of stocks when the funds are insufficient. Currently, when one generates sinusoidal data, it's typically in the range of 18-22K. However, with an initial account value of 1K, one could not make a purchase, right? Or is your code specifically targeting cryptocurrencies, which can be bought in any amount (e.g., 0.1 BTC)?

if action == 2: # buy
    buy_order_size = order_size
    next_state.allocation_percentage = last_state.allocation_percentage + (1 - last_state.allocation_percentage) * buy_order_size
    next_state.assets = last_state.assets + (last_state.balance * buy_order_size / last_state.close) * self.fee_ratio
    next_state.balance = last_state.balance - (last_state.balance * buy_order_size) * self.fee_ratio

When a buy action is initiated (action == 2), the code calculates the amount of the asset to be bought (buy_order_size) and updates the new state (next_state) accordingly—both its assets and balance. The calculation does not explicitly check whether the next_state.balance will end up negative after the buy operation, which would imply buying more than what the available balance allows.

Root-DE avatar Apr 08 '24 13:04 Root-DE