Skip to content

Fractional (fixed) order size <1 does not work #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nikolhaas65 opened this issue Jan 19, 2025 · 1 comment
Closed

Fractional (fixed) order size <1 does not work #1198

nikolhaas65 opened this issue Jan 19, 2025 · 1 comment
Labels
invalid This is not a (valid) bug report

Comments

@nikolhaas65
Copy link

nikolhaas65 commented Jan 19, 2025

Hi,
I want to backtest with order size of fixed amount (fixed_bet). Previous suggestion was to use fixed_bet/self.equity or fixed_bet/self.data.Close[-1]. Such sizes produce no trades and zero pnl.
I tried self.sell(size=0.05) or self.buy(size=0.5), but result is the same - zero.
After deep dive I think the problem is in class Broker where the size_float is converted into the size_int inside _process_orders.

size = order.size
if -1 < size < 1:
    size = copysign(int((self.margin_available * self._leverage * abs(size))
                        // adjusted_price), size)
    # Not enough cash/margin even for a single unit
    if not size:
        self.orders.remove(order)
        continue
assert size == round(size)
need_size = int(size)

I am trading PERPETUALS, where BTC index price is around 100_000 USD today, but I can trade them at notional as small as 10 USD. I set initial cash at 1_000_000, so I have enough equity. Nothing helps. And the reason, I think, is above.

PS. After trades I am forced to re-scale all trades, which is inconvenient, because I have to rebuild statistics.
PPS. Yes, I have seen earlier issues and replies, but do not find then satisfactory.
For example, this solution produces zero order_size.

current_price = self.data.Close[-1]
order_size = 100 // current_price

Thanks.

@kernc
Copy link
Owner

kernc commented Jan 28, 2025

Previous suggestion

Yes, I have seen earlier issues and replies

Can you point them out?

Issue #226 (comment) is about wanting to order assets for a fixed amount of cash ($100).

@kernc kernc closed this as completed Feb 2, 2025
@kernc kernc added the invalid This is not a (valid) bug report label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not a (valid) bug report
Projects
None yet
Development

No branches or pull requests

2 participants