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 fn is not smooth #461

Open
posidonius opened this issue Nov 27, 2024 · 0 comments
Open

commission fn is not smooth #461

posidonius opened this issue Nov 27, 2024 · 0 comments

Comments

@posidonius
Copy link

posidonius commented Nov 27, 2024

I am getting the commission fn is not smooth error when trying to implement quantity and price-based commission as follows:

class TradingCommissions:
    MIN_COMM = 0.35
    QTY_RATE = 0.0035
    MAX_RATE = 0.01

    @staticmethod
    def calc(q, p):
        qty_comm = abs(q) * TradingCommissions.QTY_RATE
        max_comm = abs(q) * p * TradingCommissions.MAX_RATE

        # Final commission is the maximum of the minimum commission
        # and the smaller of the quantity and maximum commissions
        return max(TradingCommissions.MIN_COMM, min(qty_comm, max_comm))

I am passing TradingCommissions.calc to the backtester. The tests will run but invariably and somewhat unpredictably end in the message:

The difference between what we have raised with q and the amount we are trying to raise has gotten bigger since last iteration! full_outlay should always be approaching amount! There may be a case where the commission fn is not smooth

I have gone over my code for hours looking for a reason. I have concluded it has something to do with a bug in the core. There is some discussion here about past issues in implementing commissions.

Some references: #97 #247 #342 #384

I am using integer positions. Any suggestions for how or where to look for a way to resolve this issue would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant