Closed MiniXC closed 4 years ago
Will ask an Algotrading Proffessional about that.
Slippage is a tricky thing to get right. Additionally, there is the difficultly to incorporate different kind of orders ("market", "limit", "aggressive"). Once we got that, the real problems start with incorporating slippage based on order amount and position size. This would lead to having to simulate other market partizipants.
What I am trying to say is that there is no perfect model for market-induced order losses, other than the market itself.
Having stated that, I think that introducing randomness based on volume is probably the best way to go. Something like
slippage in percent = random.normal(loc=0.002, scale=??) / (volume * some_scaling_factor)
would probably suffice.
Quick online search yielded probably something like around approximatly unstably 0.2% as µ. No idea about the stddev. Will look into that.
Quantopian uses 0.05% per default, not as a normal distribution but on every trade, like a fixed commission. Correct me if I'm wrong, but I think this is quite conservative for small-cap algo-trading, especially in the age of brokers that do not actually execute the order (e.g. Robinhood, Alpaca) - so simple-back will use this as lower bound. This way people also know what to expect when testing their algorithm in quantopian.
The configuration method will be .slippage
with no argument defaulting to quantopians 0.05%
And this is what it looks like visually.
As this backtester is built for open and close data and not intra-day data, results will be wrong to a certain extent as it is rarely possible to buy exactly at open or close price. Adding a
SlippageModel
that calculates a price drift would be easy, but coming up with an accurateSlippageModel
and determining if it is accurate is not.SlippageModel
1) random value from truncated normal distribution with open/close price as mean scaled by low/high
disadvantages
2) drift towards next price point
disadvantages
3) combination
To mitigate most of the disadvantages from both algorithms, a combination could be to use 1) with the price from 2) as mean.
Evaluation
The only way I can think of to test this is to run an identical strategy in simple-back and Quantopian (which provides intra-day data). Using freely available intra-day data would be possible as well, but introduces new problems (e.g. what time do we assume to pass between order and execution)
todo
drawbacks
Slippage in Quantopian (and real life) will differ based on liquidity, volatility, etc. - all data we don't have access to. Whatever default values/algorithms we come up with will heavily overfit to the "joint strategy" we test it on. I don't know of any papers on determining execution price from open and close prices, but if there are any, please let me know!