qstrader
qstrader copied to clipboard
Netting system and Hedging system
Hello,
following discussion https://github.com/mhallsmoore/qstrader/issues/127 I think that it will be great if qstrader could support like Metatrader 5, 2 kind of accounting system https://www.mql5.com/en/articles/2299
- Netting system
- Hedging system
Kind regards
A similar issue is also opened for zipline (Quantopian backtester) https://github.com/quantopian/zipline/issues/1375
Isnt't the hedging system just a specific view of the trades (group by something)?
I'd say in fact that I think netting system is a specific view of the trades as they appear in hedging system but grouped by Symbol
This is also a different way to handle trades
With Netting
- buy 3 lots of EURUSD (for example) - (you are 3 lots long)
- sell 1 lot - (now, you are 2 lots long)
- sell 2 lot - (no opened trades - balance=equity)
- sell 1 lot - you are 1 lot short
With Hedging
- buy 3 lots of EURUSD (for example) - (you are 3 lots long) You can:
- partially close your trade of 1 lot (you will only see 1 trade)
- open a 1 lot sell order (you will see 2 trades)
True. So as long as tags are attached to trades, it's possible to build custom views.
I recently looked at doc of other backtester with such signal, sizer and risk manager mechanisms.
It make me think that SignalEvent
action (BOT
or SLD
) are not enough to express what a strategy need to be able to do.
If we only consider a netting system we should have
- BOT (Long ie positive quantity)
- SLD (Short ie negative quantity) but also
- FLAT (to be out of market ie quantity = 0)
if we consider a hedging system (or we split strategies into entry strategy and exit strategy) should have:
- EnterLong
- EnterShort
- Flatten
but also exit
- ExitLong
- ExitShort
- Flatten
Indeed, I grappled with this issue for quite some time when I first designed the SignalEvent. You can also imagine the situation with a mean reversion trade when you want to trade signals as a pair, with a certain attached "quantity" or "strength" to each, representing a hedging ratio.
This means that signal events are somewhat intertwined for some strategies. It does indeed motivate some addition signal types.