exitkit — a catalogue of exit policies, with a backtesting.py adapter #1406
charlieyanhx
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I kept re-writing the same exit logic across strategies — a stop here, a time limit there, a volatility-scaled variant when the first two disagreed — so I packaged the family and wrote an adapter for backtesting.py.
exitkit — twenty-seven exit models in six families (stop-loss, take-profit, time-based, volatility, signal-reversal, convergence) behind one interface.
pip install exitkit[backtesting]The point is comparison. Same entry rule, different exits, on the GOOG sample data that ships with this library:
One dataset and one entry rule, so it's an illustration rather than a finding — but swapping the policy is a one-line change, which is the part I wanted.
Two things I got wrong while building the adapter, in case they're useful to anyone doing something similar:
Holding time has to come off the bar clock. My first version derived it from
time.time(), which is fine live and wrong in a replay — every 2010 position aged to now and fired every time-based exit on the first bar. There's a test asserting a ten-year holding limit doesn't fire on the GOOG data.Two policies can fire on the same trade in one bar. The adapter tracks what it has already closed, so the second one is ignored rather than calling
.close()on a closed trade.It's deliberately narrow — it decides when to close and nothing else. No data feed, no order routing, no backtest loop; this library already does all of that better than I would.
SignalOutputis a plain dataclass so it's a translation layer, not an adoption.MIT, 141 tests, CI across 3.9–3.13. Feedback welcome, especially on the adapter's shape — it's the part most likely to be wrong.
All reactions