Calculations
Supposing that we have following information:
// copyright: www.idogicat.com
class MarketOrder {
private String orderId;
private String parentOrderId;
private double price;
private double qty;
// ...
}
class ParentOrder {
private String orderId;
private String clientId;
private String basketId; // in case we need to aggregate per basket...
private Instrument instr;
private String side; // 'B', 'S', 'SS' (or use enumerate...)
private double qty;
private double limitPrice;
private double execQty; // sum of qty's of all market orders
private double benchmark;
private double notionalExecValue;
private double notionalExecPrice;
private double pl;
private double plCps; // P & L in cps
private double plBps; // P & L in bps
// market orders
private ArrayList<MarketOrder> marketOrders;
// many methods are omitted
private int getSideSign() {
if(side.equals('B')) return 1;
else return -1;
}
private void calcNotionalExecValue() {
notionalExecValue= 0;
for(MarketOrder order : marketOrders) {
notionalExecValue+= order.getPrice() * order.getQty();
}
}
private void calcNotionalExecPrice() {
notionalExecPrice = notionalExecValue / execQty;
}
private void calcPL() {
pl = getSideSign() * (benchmark * execQty - execValue);
}
private void calcPlInCps() {
plCps = pl / execQty;
}
private void calcPlInBps() {
plBps = pl * 10000 / (execQty * benchmark)
}
}
class Instrument {
private String ric;
private double lotSize;
private double adv;
private double mktCap;
// many methods omitted...
public double getVwap(Date date);
public double getTimedVwap(Date date, Time from, Time to);
}
Basic Calculations
Calculate deviation & standard deviation of all orders in a group (as described previously under 'Groups'):
All parent orders in the group form an order set O, any parent order in O is written as o(i):
Define two weights: w
1(i) and w
2(i): the former is for calc in cps; the latter is for bps:
where q
e(i) is executed quantities, and b(i) is benchmark of parent order o(i).
So we have average deviation of P & L of all orders in O:
where μ
1 is in cps, while μ
2 is in bps; d
1 is po.plCps, d
2 is po.plBps.
Standard deviations of P & L of all orders in O:
Performance Improvement
If we need to calculate for more than one order sets, as well as total orders, then we can use the following way to avoid repeated calculations:
Supposing that we have a collection of disjoint order sets:
then we can calculate total number of parent orders n
A, total weights w
A, population mean of all parent orders μ
A, and population standard deviation of all parent orders σ
A in following way:
First, calculate the values for each of the order set, and store the calculated results; then use the stored results and following formulas to calculate values for set A.