Tuesday 27 March 2012

Position Sizing Strategies - Kelly's F

When you have a trading model you are confident of and you want to maximise your gains, I suggest you look at the Kelly Criterion or  Kelly's F. Originally devised as a method to optimise transmission over noisy telegraph wires, Kelly's F has been applied to gambling as a way of maximising returns. In turn it has also been applied to forex and stock market trading. A good article on the subject can be found here.

Unlike using ATR as a measure of volatility and thus a method of formulating your position size, Kelly's F is based upon the premise that previous gambles and outcomes are an indicator of future success. This is where the formula has its critics as one is assuming that the number of positive outcomes and return for a trade are an indicator of your system's likely future performance. Strangely, I have found Kelly's F to be a more successful position sizing strategy than ATR, but it takes a brave heart! In the model below, I calculate Kelly's F for each share based upon historical performance against my model. I also 'dilute' the KellyF recommendation by 50% - this is very common amongst traders and is know as a 'Half Kelly'. The code I use to calculate KellyF is shown below:

 public decimal GetKellyF(string epic)  
     {  
       if (_transactions.WinningTradeCount(epic) > 1)  
       {  
         if (_transactions.LosingTradeCount() == 0)  
         {  
           return 1;  
         }  
         decimal? avgWin = _transactions.WinningTradeValue(epic);  
         decimal? avgLose = _transactions.LosingTradeValue(epic) * -1;  
         decimal? avgWinningTradeValue = avgWin / _transactions.WinningTradeCount(epic);  
         decimal? avgLosingTradeValue = avgLose / _transactions.LosingTradeCount(epic);  
         int tranCount = _transactions.WinningTradeCount(epic) 
                                  + _transactions.LosingTradeCount(epic);  
         decimal winPct = (decimal)_transactions.WinningTradeCount(epic) / tranCount;  
         decimal? wlRatio = avgWinningTradeValue / avgLosingTradeValue;  
         decimal? kelly = ((wlRatio + 1) * winPct - 1) / wlRatio;  
         if (kelly != null)  
           return (decimal)kelly;  
         return 1;  
       }  
       return 0;  
     }  
   }  

Points to note here - many of the calculations shown here such as 'WinningTradeValue' and 'WinningTradeCount' are calculated within my transcations class - this is a big class and too large to print here - if anyone wants it I can send it to them. The key line here is:

 decimal? kelly = ((wlRatio + 1) * winPct - 1) / wlRatio;  

This will calculate KellyF for each share so long as a history exists. I then use the results of the KellyF calculation to work out the size of the shareholding using this line of code:

  noStocksHeld = (int)((Balance * KellyF * 0.5m) / BuyPrice);  

(Note the '0.5m' to limit the final size of the shareholding). KellyF can get pretty aggressive in the size of holdings it demands, so you have to tone it down. I have only really seen KellyF being used in options and forex trading, so this is my customisation to make it work in stocks and shares. I have had a lot of success with it over the years.

1 comment:

  1. AlgoTrader is a Java based Algorithmic Trading Software that lets trading firms automate trading strategies in forex, options, futures and stocks. algorithmictradingportfolio.com Admin

    ReplyDelete