Skip to content
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

commission in dollar value #623

Closed
gypsyzz opened this issue Apr 4, 2022 · 2 comments · May be fixed by #662
Closed

commission in dollar value #623

gypsyzz opened this issue Apr 4, 2022 · 2 comments · May be fixed by #662
Labels
duplicate This issue or pull request already exists

Comments

@gypsyzz
Copy link

gypsyzz commented Apr 4, 2022

Expected Behavior

able to set commission in dollars, disregard percentage. Some instruments I know (futures for example) has a fixed commission per trade, instead of percentage, there should be a switch to set % or $.

Actual Behavior

only percentage is available

Additional info

  • Backtesting version: 0.3.3
@kernc kernc added the enhancement New feature or request label Apr 4, 2022
@gypsyzz
Copy link
Author

gypsyzz commented Apr 5, 2022

current hack-ish fix
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 or commission >=.5, \
to assert that we want between +-0.1 for percentage, or above 0.5 for fixed amount. I am aware of some brokers offering 0.3 per trade so that may require tweaking.
Accordingly, change the adjuststed price
def _adjusted_price(self, size=None, price=None) -> float: """ Long/shortprice, adjusted for commisions. In long positions, the adjusted price is a fraction higher, and vice versa. """ if self._commission >=0.5: return ((price or self.last_price) + copysign(self._commission, size)) else: return ((price or self.last_price) * (1 + copysign(self._commission, size)))

@kernc
Copy link
Owner

kernc commented Dec 6, 2022

Duplicate of #113.

@kernc kernc closed this as completed Dec 6, 2022
@kernc kernc added duplicate This issue or pull request already exists and removed enhancement New feature or request labels Dec 6, 2022
JungleDruid pushed a commit to JungleDruid/backtesting.py that referenced this issue Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants