qstrader
qstrader copied to clipboard
More attributes needed in Position class
There are a few attributes needed in the position
class for statistics, etc:
-
entry_datetime
: when the position was first opened -
exit_datetime
: end the position was closed -
trade_pct
: trade percentage ( avg_sld / avg_bot -1 ) -
bars_in_trade
: how long the position was open for in terms of bars -
mfe
: maximum favorable excursion -
mae
: maximum adverse excursion
Some of these can be calculated later on (i.e in the Statistics
class), but I think it might be needed somewhere else in the system and the best place is probably Position
class.
I can do some of this, but I believe we have some PR's pending?
Exit is not necessary binary... There is for example partial close and we need a way to handle this
I'm not in favor of this bars_in_trade
because you can backtest using tick data.
Not sure if MFE and MAE should be store here.
I believe that what you suggest is more appropriate to trades than to positions.
I don't know if it's been discussed somewhere, but it would be good to separate the trades from the positions, as positions (ie, per instrument) are in my opinion simply a view of the currently open trades P&L. Trades objects could contain a tag attribute (a dict) to allow users to compute views per whatever they want (eg, system name, a spread/combo, sector, etc.). Any thoughts on this?