Skip to content

Negative commission isnt properly calculated? #958

Closed
@masafumimori

Description

@masafumimori

Expected Behavior

Increased entry price when selling while it decreases when buying.

Actual Behavior

No matter if it is a positive or negative commission, it is counted as a positive value.
For example, when 0 commission is set, the entry price is 5,429,749 for buying. (calculated with atr values)
When setting 0.04% commission, it becomes 5,431,921, which is 1.0004x than the 0 commission.
When setting -0.04%, the entry price stays the same as 5,431,921. This should be 5,427,577.1004(5,429,749*0.9996)?

For selling, 5,458,457 for both -0.0004 and 0.0004% commission, which is 1.0004x less than commission 0 for 5,460,642.

Steps to Reproduce

  1. Create any strategy
  2. place order with limit price.
  3. run backtest with negative commision like -0.0001
  4. run backtest with positive commision like 0.0001
  5. compare the result and entry prices in _trade

Additional info

I see the code accepting negative commision til -10% but negative commision doent seem to be working.

class _Broker:
    def __init__(self, *, data, cash, commission, margin,
                 trade_on_close, hedging, exclusive_orders, index):
        assert 0 < cash, f"cash should be >0, is {cash}"
        assert -.1 <= commission < .1, \
            ("commission should be between -10% "
             f"(e.g. market-maker's rebates) and 10% (fees), is {commission}")

Backtesting version: 0.3.3

I'm sorry if i am missing something for negative commission settings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions