Repository navigation
Conversation
risk_to_qty reduced the position size by (1 - fee_rate * 3) and then passed fee_rate on to size_to_qty, which applies the same adjustment again, so the fee was charged twice. Drop the pre-adjustment in risk_to_qty; size_to_qty applies the fee exactly once. size_to_qty itself is unchanged, so other callers keep the same behavior. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
The existing fee case expected 4.97, which encoded the fee being applied twice. With the fee charged once it is 4.985. Also adds the reporter's example from jesse-ai#614 (10000, 10, 100, 90, fee_rate=0.005) as a regression assertion: 98.5 instead of the double-haircut 97.0225. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Member
|
Thanks @hakarrr for picking this up, with the reproduction and the tests. We went a different way for #614 in 3.6.1, so I'm closing this one. Charging the fee once still treats it as a flat share of the size, while the risk is only the distance to the stop, so a stop-out still loses more than the chosen risk: in the issue's example, about 1,079 instead of 1,000. 3.6.1 sizes the position as Appreciate the help! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #614.
risk_to_qtyreduced the position size by(1 - fee_rate * 3)and then passedfee_rateon tosize_to_qty, which applies the same adjustment again — so withfee_rateset, the fee was charged twice.Reproduction from the issue:
Change: drop the pre-adjustment in
risk_to_qtyand letsize_to_qtyapply the fee exactly once.size_to_qtyitself is unchanged, so its other callers keep the same behavior.Tests (
tests/test_utils.py):test_risk_to_qtyexpected4.97, which encoded the double application; with the fee charged once the value is4.985. Updated.98.5, not97.0225). It fails on current master and passes with this change.python -m pytest tests/test_utils.py→ 14 passed.Note: #620 had the same fix but was closed by the stale bot; this revives it with the test expectations updated.