Skip to content

Allowing Stock Purchases Beyond Available Balance in Trading Environment Simulation #12

@Root-DE

Description

@Root-DE

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions