The book, The Leverage Space Trading Model by RALPH VINCE

Page 173, applied Martingale, an introduction

Suppose we found a set of f, i.e. leverages for some financial instruments. This can be done by controlling the leverages to allow the RD probability of drawdown at a low level, and choose leverages that produce the best GHPR among low probability of drawdown. Because as leverages increase probability of drawdown also increase greatly. So choose a good set leverages f before continue on trading.

Keeping probability of drawdown to be low does not mean we could never get drawdowns in trading. So when we losing money, we want to modify the leverages/fdollars the martingale way.

Now we have researched the financial instruments. Binned data, computed joint probability, chose leverages f, and made educated guesses on the z. These are the initial setups.

MktSysA=c(-150.00,-45.33,-45.33,13.00,13.00,13.00,13.00,13.00,
          79.67,79.67,79.67,136)
MktSysB=c(253.00,-1000.00,-64.43,-64.43,-64.43,253.00 ,253.00,
          448.00,-64.43,-64.43,-64.43,253)
MktSysC=c(533.00,220.14,220.14,-500.00,533.00,220.14,799.00,
          220.14,-325.00,220.14,533.00,220.14)

p=c(0.076923077,0.076923077,0.153846154,0.076923077,0.076923077,
    0.076923077,0.076923077,0.076923077,0.076923077,0.076923077,
    0.076923077,0.076923077)

PL=cbind(MktSysA,MktSysB,MktSysC)
BL=apply(PL,2,min)

z=c(-0.992,-0.76)
f=c(0.085,0.015,0.129)

Here is fdollar function to apply z values.

fdollar<-function(BL,f){
res=0
if(current_equity > starting_equity){
 res=(abs(BL)/ f)/((starting_equity/current_equity)^((1/(1 + z[1])) -1))
}else{ 
 if(current_equity < starting_equity){
  res=(abs(BL)/ f)/((starting_equity/current_equity)^((1/(1 + z[2])) -1))
 }else{
  res=abs(BL)/ f
 }
}
return(res)
}

First month, we lost some money.

starting_equity=1000000
current_equity=starting_equity

fdollars=fdollar(BL,f)
fdollars
##   MktSysA   MktSysB   MktSysC 
##  1764.706 66666.667  3875.969
units=as.integer(starting_equity/fdollars+.00001)#round to 14, not good.
units
## [1] 566  15 258
gains1=c(13.00,-64.43,-500)
PL_month1=gains1%*%units#-$122,608.45

current_equity=as.numeric(current_equity+PL_month1)#877391.55

Second month, units were increased to make up losses.

fdollars=fdollar(BL,f)
fdollars
##   MktSysA   MktSysB   MktSysC 
##  1166.232 44057.650  2561.491
units=as.integer(current_equity/fdollars)
units
## [1] 752  19 342
gains2=c(13, 253, 799)
current_equity=as.numeric(current_equity+gains2%*%units)#1,165,232.55

Trading stopped, because we had sufficient profits from the 2nd month.

fdollars=fdollar(BL,f)#3.032744e+11 1.145703e+13 6.661065e+11
fdollars
##      MktSysA      MktSysB      MktSysC 
## 3.032744e+11 1.145703e+13 6.661065e+11
#extremely small values, no units means no trading
units=as.integer(current_equity/fdollars)
units
## [1] 0 0 0