Examples of Execution Algorithms?

Discussion in 'Automated Trading' started by sf631, Mar 20, 2012.

  1. sf631

    sf631

    I am building a simple trading application (on TradeLink, C#) and want to implement some simple accumulation / distribution execution algos, by which I mean algos that can break up a large order into many smaller orders to minimize impact on what can be a relatively illiquid market.

    I've already got my algos that tell me when I want to trade, now I need to implement the "how" to get that order filled. At the moment I'm not trying to "win" the HFT game, just trying to get my orders executed at something close to VWAP/TWAP through a mix of passive limit orders, and aggressive limit orders and/or market orders.

    Are there any good sources of *example code* or pseudocode for order execution? Obviously no one is sharing their super-secret HFT money machine, but certainly there are algos which are outdated and widely known which may be a good starting place for me to modify? I've read Barry Johnson's book on DMA as well as many others and they all explain the concept of IS or minimized impact algorithms but stop short of actual code.

    Any suggestions sources of code/pseudocode for simple execution algorithms would be much appreciated.

    Thanks in advance
     
  2. sf631

    sf631

    By the way, Java, TradeStation, MetaTrader, Amibroker, or any other code type is fine (and of course .NET is great) - any of the above would get the general idea across
     
  3. very simple algo would be to
    * buy / sell at some minimium size with cross
    * look for when trading in your desired range
    * look for when your traded volume is small part of previous bar's volume (eg 1min/5min)

    here is a tradelink example.

    this is psuedo code, ask on user list if you need help with building this.

    Code:
    public class MyResponse : ResponseTemplate
    {
        TickTracker kt = new TickTracker();
        BarListTracker blt = new BarListTracker(BarInterval.OneMin);
        GenericTracker<long> sizethisinterval = new GenericTracker<long>();
        GenericTracker<long> totalsize = new GenericTracker<long>();
        public decimal MinPrice = 10;
        public decimal MaxPrice = 12;
        public int MaxSize = 1000000;
        public decimal isBuyingStrategy = true;
        public int SmallSize = 100;
    
        void GotTick(Tick k)
        {
              kt.newTick(k);
              blt.newTick(k);
              if (sizethisinterval.getindex(k.symbol)<0)) 
              {
                   sizethisinterval.addindex(k.symbol,0);
                   totalsize.addindex(k.symbol,0);
              }
              if (!kt.isFullQuote(k.symbol)) return;
              // cross market if we can do it in small way
              if ((k.trade>MinPrice) && (k.trade < MaxPrice) && (sizethisinterval[k.symbol] < blt[k.symbol][-1].Volume*.01) && (totalsize[k.symbol] < MaxSize))
              {
                   // account for our size
                   sizethisinterval[k.symbol] += SmallSize;
                   totalsize[k.symbol] += SmallSize;
                   // send order
                   sendorder(new LimitOrder(k.symbol,isBuyingStrategy,SmallSize, isBuyingStrategy ? kt.Ask(k.symbol) : kt.Bid(k.symbol)));
              }
        }
        void GotNewBar(string sym, int interval)
        {
             // reset our size
             sizethisinterval[sym] = 0;
        }
    }
    

    google tradelink project or tradelink.org for more info