En el documento de Respuesta a Paul Samuelson las cartas y documentos sobre Kelly Crecimiento del Capital a la Estrategia de Inversión de las páginas 5 y 6 Dr. William T Ziemba, da un praticle ejemplo en Kelly Crecimiento.
Estoy tratando de replicar la simulación se explica allí en R :
Paso 1 : Crear la Tabla da los Datos.Marco
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)
Paso 2 : Crear la función que se replica la simulación
# 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)
}
Paso 3 : Ejecutar la Simulación y el Atributo de la Matriz Resultante en una Variable llamada kelly.sim con 700 pasos y 1000 simulaciones y Fracción = 1
kelly.sim <- kelly.simulation(InitialWealth=1000,SimulationNumber=1000,SimulationSteps=700,KellyFraction=1)
Paso 4 : Comprobar los resultados de la última fila de las simulaciones (en el ejemplo número de fila 701)
max(kelly.sim[701,])
[1] 47800703
mean(kelly.sim[701,])
[1] 270680.9
min(kelly.sim[701,])
[1] 3.377048
En su opinión estos código de repeticiones de la simulación que se describe en el documento ?