Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > Finance > Algorithmic Trading > Calculations

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: w1(i) and w2(i): the former is for calc in cps; the latter is for bps:

where qe(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; d1 is po.plCps, d2 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 nA, total weights wA, 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.