Kelly bet sizing money management position sizing strategy 0

Posted on 17, June 2013

in Category SID


Description for Kelly SID 259

Kelly bet sizing money management/position sizing strategy

Description

Kelly money management/position sizing strategy for growing your capital. For more information, type Kelly Formula into a search engine.

The Kelly formula is : Kelly % = W – (1-W)/R where:

W = Historical winning percentage of a trading system.
R = Historical Average Win/Loss ratio.
Kelly % = percentage of capital to be put into a single trade.

This is calculated before each enter order.

Orders available:

BuyOpen, BuyStop, SellOpen and SellStop

This MM will short and will pyramid if account options set.

There are several points you will need to understand before using this money management object.

Since this MM uses “historical trading” performance, you have to consider what should happen before there are enough trades to be statistically meaningful. As a default, this MM will invest 10% of cash per trade until there are at least 20 trades. From then on, the Kelly Formula is used.

The Kelly formula can produce negative values, which could be viewed as do not trade. If this were made into a rule, then the system would stop trading. Perhaps it should! In the cases where the Kelly formula produces a negative value, a warning will be given and 10% of trading cash will be invested for the next order.

A maximum of 50% of Cash will be invested – any Kelly values higher than this will be reduced to 50%.

All these values can be changed in the PositionSize function.Kelly bet sizing money management position sizing strategy/sid The logic for this Position Sizing Strategy:

Kelly bet sizing money management position sizing strategy/sid PositionSize:

###########################
# Kelly Formula - read notes for a description
# Play around with the vars below to change the settings of this MM
#
my $mintrades   = 20; #Minimum number of trades before kelly is used 
my $mintradeper = 10; #Percent to invest if we havn't got enough trades
my $maxper     = 50; #Maximum percent that we will invest
my $minper     = 10; #Minimum Percent that we will invest
#
#
############################

my $kelly; #The kelly percent

if (TotalTrades<$mintrades) {
  #not enough trades to use the kelly, set default %
  $kelly=$mintradeper;
}
else {
  #enough trades, work out the win/loss ratio
  my $winlossratio=AvgWinningTrade / AvgLosingTrade if AvgLosingTrade;
  if ($winlossratio) {
    #we have a winlossratio, work out the win probablility
    my $winprob=PerWinningTrades / 100;
    $kelly=100*($winprob-(1-$winprob) /$winlossratio);
  }
  else {
    #we dont have a winlossratio - no losses! Set the % to the max
    $kelly = $maxper;
  }
  #check for min and max
  $kelly=$maxper if $kelly>$maxper;
  if ($kelly<1) {
    Warning('Negitive Kelly - should you stop trading?');
    $kelly = $minper;
  }
}

###############
#work out the number of units and return the number

my $num=int((($kelly/100)* LiquidatingValue )/ClosePrice);
Output "Kelly $kelly number of units $num ".$num*ClosePrice;
return $num;

Kelly bet sizing money management position sizing strategy/sid BuyMarket event logic:

if (ShortPosition) {
  #If we have a short position, close it.
  PlaceBuyOpen('KellyClosingShort');
}
else {
  #we have no position, or we are long.
  my $num=PositionSize();
  PlaceBuyOpen('KellyGoingLong',$num) if $num;
}

Kelly bet sizing money management position sizing strategy/sid BuyStop event logic:

my $stop=shift;
#Stop trading if we do not have a stop price
die 'No stop price for BuyStop' unless $stop;

if (ShortPosition) {
  #If we have a short position, close it.
  PlaceBuyStop('KellyClosingShort',0,$stop);
}
else {
  #we have no position, or we are long.
  my $num=PositionSize();
  PlaceBuyStop('KellyGoingLong',$num,$stop) if $num;
}

Kelly bet sizing money management position sizing strategy/sid BuyLimit event logic:

my $limit=shift;
#Stop trading if we do not have a limit price
die 'No limit price for BuyLimit' unless $limit;

if (ShortPosition) {
  #If we have a short position, close it.
  PlaceBuyLimit('KellyClosingShort',0,$limit);
}
else {
  #we have no position, or we are long.
  my $num=PositionSize();
  PlaceBuyLimit('KellyGoingLong',$num,$limit) if $num;
}

Kelly bet sizing money management position sizing strategy/sid BuyStopLimit event logic:

my ($stop,$limit)=@_;
#Stop trading if we do not have a stop and limit price
die 'No limit price for BuyStopLimit' unless $limit;
die 'No stop price for BuyStopLimit' unless $stop;

if (ShortPosition) {
  #If we have a short position, close it.
  PlaceBuyStopLimit('KellyClosingShort',0,$stop,$limit);
}
else {
  #we have no position, or we are long.
  my $num=PositionSize();
  PlaceBuyStopLimit('KellyGoingLong',$num,$stop,$limit) if $num;
}

Kelly bet sizing money management position sizing strategy/sid SellMarket event logic:

if (LongPosition) {
  #If we have a long position, close it.
  PlaceSellOpen('KellyClosingLong');
}
else {
  #If we have no position or we are short, place the order
  my $num=PositionSize();
  PlaceSellOpen('KellyGoingShort',$num) if $num;
}

Kelly bet sizing money management position sizing strategy/sid SellStop event logic:

my $stop=shift;
#Stop trading if we do not have a stop price
die 'No stop price for SellStop' unless $stop;

if (LongPosition) {
  #If we have a long position, close it.
  PlaceSellStop('KellyClosingLong',0,$stop);
}
else {
  #If we have no position or we are short, place the order
  my $num=PositionSize();
  PlaceSellStop('KellyGoingShort',$num,$stop) if $num;
}

Kelly bet sizing money management position sizing strategy/sid SellLimit event logic:

my $limit=shift;
#Stop trading if we do not have a limit price
die 'No limit price for SellLimit' unless $limit;

if (LongPosition) {
  #If we have a long position, close it.
  PlaceSellLimit('KellyClosingLong',0,$limit);
}
else {
  #If we have no position or we are short, place the order
  my $num=PositionSize();
  PlaceSellLimit('KellyGoingShort',$num,$limit) if $num;
}

Kelly bet sizing money management position sizing strategy/sid SellStopLimit event logic:

my ($stop,$limit)=@_;
#Stop trading if we do not have a stop and limit price
die 'No limit price for SellStopLimit' unless $limit;
die 'No stop price for SellStopLimit' unless $stop;

if (LongPosition) {
  #If we have a long position, close it.
  PlaceSellStopLimit('KellyClosingLong',0,$stop,$limit);
}
else {
  #If we have no position or we are short, place the order
  my $num=PositionSize();
  PlaceSellStopLimit('KellyGoingShort',$num,$stop,$limit) if $num;
}

0 Comments

Leave a Message