Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

In the paper Response to Paul A Samuelson letters and papers onthe Kelly Capital Growth Investment Strategy pages 5 and 6 Dr William T Ziemba, gives a praticle example on Kelly Growth.

I’m trying to replicate the simulation explained there on R :

Step 1 : Create the Table as da Data.Frame

Win.Prob <- c(0.57,0.38,0.285,0.228,0.19)
Odds <- c("1-1","2-1","3-1","4-1","5-1")
Implied.Odds <-c(0.5,0.333,0.25,0.2,0.167)
Edge <- c(0.07,0.0467,0.035,0.028,0.0233)
Advantage <- c(0.14,0.14,0.14,0.14,0.14)
Opt.Kelly <- c(0.14,0.07,0.0467,0.035,0.028)
Prob.Chose.Bet <- c(0.1,0.3,0.3,0.2,0.1)
Cum.Prob.Bet <- c(0.1,0.4,0.7,0.9,1)
Kelly.Example <- data.frame(Win.Prob,Odds,Implied.Odds,Edge,Advantage,Opt.Kelly,Prob.Chose.Bet,Cum.Prob.Bet)
remove(Win.Prob,Odds,Implied.Odds,Edge,Advantage,Opt.Kelly,Prob.Chose.Bet,Cum.Prob.Bet)

Step 2 : Create the function that replicates the simulation

# Initiate the function that takes 3 variables (Initial Wealth, Decision Points, Number of Simulations)

kelly.simulation <- function(InitialWealth,SimulationNumber,SimulationSteps,KellyFraction) {

  #Initiate a Matrix that generates SimulationSteps*SimulationNumber random numbers and Attribute to the Bet choice
  simu_bets <- matrix(sample.int(5, size = SimulationSteps*SimulationNumber, replace = TRUE, prob = c(.1,.3,.3,.2,.1)),nrow=SimulationSteps,ncol=SimulationNumber)

  #Take the chosen bet in simu_bets and create a new matrix of Optimal Kelly Bets based on the table in Kelly.Example
  simu_kellybets <- ifelse(simu_bets == 1,Kelly.Example$Opt.Kelly[1],
                           ifelse(simu_bets == 2,Kelly.Example$Opt.Kelly[2],
                              ifelse(simu_bets == 3,Kelly.Example$Opt.Kelly[3],
                                         ifelse(simu_bets == 4,Kelly.Example$Opt.Kelly[4],Kelly.Example$Opt.Kelly[5]))))

  #Take the chosen bet in simu_bets and create a new matrix of Winning Probability based on the table in Kelly.Example
   simu_prob <- ifelse(simu_bets == 1,Kelly.Example$Win.Prob[1],
                      ifelse(simu_bets == 2,Kelly.Example$Win.Prob[2],
                         ifelse(simu_bets == 3,Kelly.Example$Win.Prob[3],
                                    ifelse(simu_bets == 4,Kelly.Example$Win.Prob[4],Kelly.Example$Win.Prob[5]))))

  #Generate a new matrix of random number and compare to the prob of winning 1 means you won the bet 0 means you lost
  simu_rnd <- matrix(runif(SimulationSteps*SimulationNumber,0,1),nrow=SimulationSteps,ncol=SimulationNumber)
  simu_results <- ifelse(simu_prob>=simu_rnd,1,0)

  #Generate a new matrix simu_results * simu_bets and creat the wealth simulation over each timestep
  bet_combined <- simu_results * simu_bets
  bet_combined[bet_combined==0] <- -1
  multiplier <- 1 + simu_kellybets * bet_combined*KellyFraction
  Wealth_Matrix <- apply(rbind(InitialWealth, multiplier), 2, cumprod)
  row.names(Wealth_Matrix) <- NULL 

  #return the variation of wealth over each step for the defined number of simulations (Rows = Each Bet Decision Point / Column = Each simulation)
  return(Wealth_Matrix)
}

Step 3 : Run the Simulation and Attribute the Resulting Matrix to a Variable called kelly.sim with 700 steps and 1000 simulations and Fraction = 1

 kelly.sim <- kelly.simulation(InitialWealth=1000,SimulationNumber=1000,SimulationSteps=700,KellyFraction=1)

Step 4 : Check the results of the last row of the simulations (in the example row number 701)

max(kelly.sim[701,])
 [1] 47800703
mean(kelly.sim[701,])
 [1] 270680.9
min(kelly.sim[701,])
 [1] 3.377048

In your oppinion these code replicates the simulation described in the paper ?

share|improve this question
    
Sorry, i forgot to update the data frame name, and column names. Now it should work, first create a data frame called Kelly.Example exact as it shows on the example (same column names) and run again the function. Just tested and everything worked for me. –  RiskTech Jul 8 at 19:06
    
The code is correct, just tested again. you have to call the function into a variable kelly.sim in order to create the wealth matrix kelly.sim <- kelly.simulation(InitialWealth=1000,SimulationNumber=1000,SimulationSteps=700) then you can use max, min and mean with kelly.sim –  RiskTech Jul 8 at 19:16
    
Added the code to generate the first data.frame –  RiskTech Jul 8 at 19:34
    
Now it runs - what is your exact question? Whether this replicates the algorithm described in the paper? –  vonjd Jul 11 at 15:05
1  
what are your numbers relative to the data he has published? –  user12348 Jul 11 at 15:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.