This series looks at building a near full-scale application in q and, in the process, tries to answer questions on the amount of code a q application requires, and how that code can be organised so that it is both comprehensible and straightforward to change. The target application is a participation strategy and some of its associated testing framework.
This installment specifies the participation strategy. Previously in this series: a qx market maker. Next: the first step in implementing the strategy.
Participation is one of basic execution strategies: trading in line line with the market. At its simplest, every trade seen in the market is responded to by sending an order to take a proportionate quantity from the opposite side (far side) of the order book, i.e. the ask side if the strategy is buying. The strategy is not a "completing" strategy: it does to aim to finish the full order quantity assigned to it, as it simply reacts to the volume traded in the market. Despite this simplicity, the participation strategy can be viewed as the foundation for many other strategies. Algorithms that have fixed quantity schedules, such as VWAP, can also be expressed as constant or variable rate participation strategies. For one reason why this may be a good thing, see this chart.
The average price achieved by the strategy would be poor if all the strategy did was take from the order book. Consequently participation strategies operate on both the far and the near side of the book, aiming to achieve an average price nearer to the volume weighted average trade price, VWAP. Below is a summary of the basic near and far execution tactics. In the text qty
refers to the upstream order quantity; filled
and leaves
are the quantities filled and remaining; rate
, minsize
and maxtake
are strategy parameters. From 2009-02-18: minqty
was renamed minsize
to avoid confusion with the equivalent FIX field.
Far | Near | |||
---|---|---|---|---|
What is the primary signal for action? | Trades | Quotes | ||
What types of order are used downstream? | IOC with limit price | Day orders with limit price | ||
How is the quantity for the order calculated? | rate times volume, less filled , then grossed up (the executed IOC also adds to market volume) | rate times other quantity on nearside, grossed up, less own quantity
| ||
What are the minimum constraints on order quantity? | minsize to ensure orders are economically worthwhile | minsize to ensure orders are economically worthwhile and quote improvements in trivial size are ignored
| ||
What are the maximum constraints on order quantity? | leaves maxtake to limit proportion of total far quantity to remove from the order book and hence limit market impact | leaves
| ||
Which other signals can prompt action? | Quotes can prompt an order if the execution has been reduced by a maximum constraint, i.e. an increase in the far qty could cause another IOC to be sent | n/a | ||
What happens when minsize is greater than leaves ? | Reduce minsize to a single share/lotIncrease maxtake to 100%. | Reduce minsize to a single share/lotFrom 2009-02-05: Place all the remaining quantity on the book |
If the design (and the coding) is right, then other tactics can be added without rewriting code: for example, consider adding a third tactic ("deep") that, with a hint about the duration of the order, uses the barrier diffusion model for longer term order placement.
In keeping with the limitations in this series, the participation strategy will neglect essential features such as spread constraints, start and end times, and auction participation.
Upstream orders are sent to the strategy and are executed within specification until leaves
equals zero. There is no status change on completion: if the upstream order is amended to have more qty
then the order can be processed again. This can be useful as it allows us to run the strategy with tranches of the original order size.
Execution is delegated to the tactics in equal allocations, each allocation being a multiple of the minsize
. As the tactics work through their allocation, further allocations are made on a "just-in-time" basis. The farside tactic has priority once the last allocation is being made; if the nearside tactic is still executing whilst the farside tactic has stopped, then all the remaining quantity is reallocated to the farside tactic.
This model of the strategy acting as the allocator, and the tactics executing their allocated quantities, means that the tactics will need their own values for qty
, filled
, leaves
and the strategy parameters.
Aspect | Consequences | |
---|---|---|
qty | leaves is recalculated. The upstream order will become executable if leaves is greater than zero. The effective minsize and maxtake used by each tactic are recalculated.
| |
rate | Benchmark figures are reset. | |
minsize | The effective minsize is recalculated for each tactic.
| |
maxtake | The effective maxtake is recalculated for the far tactic.
|
Orders that are explicitly cancelled have their qty
amended down to the current value of filled
and all downstream orders are cancelled.
1. | www.kx.com |