FinRock icon indicating copy to clipboard operation
FinRock copied to clipboard

calculating balance

Open daliel opened this issue 11 months ago • 1 comments

I don't understand your math. my vision for calculating the balance is this:

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
    asset = last_state.balance * buy_order_size / last_state.close
    next_state.assets = last_state.assets + asset
    balance = last_state.balance * buy_order_size
    next_state.balance = last_state.balance - balance - (balance * self.fee_ratio)

elif action == 1: # sell
    sell_order_size = order_size
    next_state.allocation_percentage = last_state.allocation_percentage - last_state.allocation_percentage * sell_order_size
    balance = last_state.assets * sell_order_size * last_state.close
    next_state.balance = last_state.balance + balance - (balance * self.fee_ratio)
    next_state.assets = last_state.assets - last_state.assets * sell_order_size

maybe this is valid only for BTCUSDT on binance

after all, the exchange receives a percentage of all transactions, and in your code only a percentage of transactions is taken away, and not the purchase/sale cost it is logical to assume that the transaction will be profitable if the sell_price / buy_price - 1 > fee_ratio

daliel avatar Mar 18 '24 10:03 daliel