Execution costs
Execution costs are an important part of a backtest, and a strategy, in that they influence directly the outcome of the strategy. Therefore, the strategy has to make more money than the execution costs to see any real benefit.
In the costs, two variables are taken into account:
- The transaction costs, that are charged by the broker to accept orders on the markets
- The slippage, which represents the difference between the medium price on the market, and the price at which the order can be actually executed
How to backtest execution costs?
To add execution costs to your strategy, you have to use the
following annotation at the beginning of your class:
@ExecutionConfig(strategy = ExecutionStrategy.Standard.class)
public class CostStrategy extends AbstractStrategy {
This will add the standard execution costs behaviour to your
strategy. If you want to remove execution costs temporarily,
without removing the annotation, simply replace the
ExecutionStrategy with None:
@ExecutionConfig(strategy = ExecutionStrategy.None.class)
public class NoCostStrategy extends AbstractStrategy {
How do Standard execution costs work?
In the standard execution costs, the following rules are applied for each contract traded in an order:
For Futures
- Slippage is fixed and is equal to 1.5 times the tick size of the traded instrument. For instance, let's assume you want to sell 10 CAC. That will incur a cost of 10 * 1.5 * 0.5, where 0.5 is the tick size for CAC, in CAC's currency EUR. The slippage will then be 7.5 EUR for the whole order of ten contracts.
- Transaction costs are fixed and defined by the currency of the traded instrument. For instance, to buy 20 FTSE, the transaction costs will be 1.99 * 20, where 1.99 is the transaction cost per contract in GBP. The transaction cost will then be 39.8 GBP.
Here is the reference table for transaction costs per currency:
| Currency | Cost per contract |
|---|---|
| USD | 3.00 |
| AUD | 3.26 |
| CAD | 3.05 |
| CHF | 3.19 |
| EUR | 2.23 |
| GBP | 1.99 |
| HKD | 23.30 |
| JPY | 278.00 |
| KRW | 3396.00 |
| SGD | 4.20 |
For Stocks
- Slippage is fixed and is equal to 4 times the tick size of the traded instrument. For instance, let's assume you want to sell 10 Amazon shares. That will incur a cost of 10 * 4 * 0.01, where 0.01 is the tick size for Amazon, in Amazon's currency USD. The slippage will then be 0.4 USD for the whole order of ten shares.
- Transaction costs are 0.02bp of the share price. For instance, to buy 20 Amazon shares at 150.00, the transaction costs will be 150.00 * 20 * 0.0002 in USD. The transaction cost will then be 6 USD.
How to implement custom execution costs?
It is also possible to implement your own execution costs by
extending the BasicExecutionStrategy class.
The easiest way to extend the BasicExecutionStrategy is to specify
a fixed slippage per instrument, as well as a fixed transaction
cost per instrument :
@ExecutionConfig(strategy = MyExecutionStrategy.class)
public class CustomCostStrategy extends AbstractStrategy {
...
}
class MyExecutionStrategy extends BasicExecutionStrategy {
@Override
protected double getFixedTransactionCosts(Tradeable instrument) {
if (instrument instanceof Futures) {
return ...
}
else if (Group.STOCKS_CAC_40.contains(instrument)) {
return ...
}
return ...
}
@Override
protected double getFixedSlippage(Tradeable instrument) {
...
}
}
If needed, in addition you can also override other methods of
BasicExecutionCosts.
For example, to provide transaction costs based on order quantity,
date, etc :
@Override
public double getTransactionCosts(Order order, DateTime executionTime, long executedQuantity, double executionPrice) {
...
}