# # Written by: # -- # John L. Weatherwax 2006-12-31 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- u = 0.5 d = 0.5 p = 0.6 L = 260 n_star = ceiling( - L * log( 1 - d ) / log( (1+u)/(1-d) ) ) p_win = 1 - pbinom( n_star-1, L, p ) # pbinom is the binomial cummulative distribution print( sprintf( "p_win= %10.6f", p_win ) ) pWinL = c() for( ll in 1:500 ){ n_star = ceiling( - ll * log( 1 - d ) / log( (1+u)/(1-d) ) ) p_win = 1 - pbinom( n_star-1, ll, p ) pWinL = c(pWinL,p_win) } #postscript("../../WriteUp/Graphics/ChapterXXX/", onefile=FALSE, horizontal=FALSE) matplot( 1:500, pWinL ) #dev.off() spot = match( max(pWinL), pWinL ) # what index gives the largest P_win print( sprintf( "p_win is largest for L= %d with p_win= %10.6f", spot, pWinL[spot] ) )