Getting caught in loops - R

Posted by user334898 on Stack Overflow See other posts from Stack Overflow or by user334898
Published on 2010-05-06T22:18:06Z Indexed on 2010/05/07 9:48 UTC
Read the original article Hit count: 204

Filed under:

I am looking at whether or not certain 'systems' for betting really do work as claimed, namely, that they have a positive expectation. One such system is based on the rebate on loss. You basically have a large master pot, say $1 million. Your bankroll for each game is $50k.

The way it works, is as follows: 1) Start with $50k, always bet on banker 2) If you win, add the money to the master pot. Then play again with $50k. 3) If you lose(now you're at $30k) play till you either: (a) hit 0, you get a rebate of 10%. Begin playing again with $50k+5k=$55k. (b) If you win more than the initial bankroll, add the money to the master pot. Then play again with $50k. 4) Continue until you double the master pot.

I just cant find an easy way of programming out the possible cases in R, since you can eventually go down an improbable path.

For example, you start at 50k, lose 20, win 19, now you're at 49, now you lose 20, lose 20, now youre at 9, you either lose 9 and get back 5k or you win and this cycle continues until you either end up with more than 50k or hit 0 and get the rebate on the 50k and start again with $50k +5k.

Here's some code i started, but i havent figured out a good way of handling the cases where you get stuck and keeping track of the number of games played. Thanks again for your help. Obviously, I understand you may be busy and not have time.

p.loss <- .4462466
p.win <- .4585974
p.tie <- 1 - (p.win+p.loss)

prob <- c(p.win,p.tie,p.loss)


bet<-20
x <- c(19,0,-20)

r <- 10 # rebate = 20%

br.i <- 50
br<-200


#for(i in 1:100){
# cbr.i<-0
y <- sample(x,1,replace=T,prob)

cbr.i<-y+br.i

if(cbr.i > br.i){

    br<-br+(cbr.i-br.i);
    cbr.i<-br.i;

    }else{       

      y <- sample(x,2,replace=T,prob);
      if( sum(y)< cbr.i ){ cbr.i<-br.i+(1/r)*br.i; br<-br-br.i}
      cbr.i<-y+
      }else{

      cbr.i<- sum(y) + cbr.i;

      }if(cbr.i <= bet){

        y <- sample(x,1,replace=T,prob)

        if(abs(y)>cbr.i){  cbr.i<-br.i+(1/r)*br.i  }  }

© Stack Overflow or respective owner

Related posts about r