Jump to content

Function with update result


wladoD
 Share

Recommended Posts

Hi Guys,

I am new here, hope you are all well. I am very new in php. I would like to ask a question.

 

I am trying to calculate my bets.

Basically you start with 500 EUR, you bet 10 % with avg odds 2. It all fine. How can i run this function 500 times for example with update bankroll?
Please help me, Thank you.

<?php
function betting($bankroll, $betPerc, $odds)
{
  
$number = rand(0,1);
$bet = $bankroll * $betPerc;


if($number == 1){
   
  return  $bankroll =  $bet * $odds - $bet + $bankroll;
   
}else

  return  $bankroll - $bet;
}


echo betting(500, 0.1, 2);

?>

Link to comment
Share on other sites

3 minutes ago, Barand said:

Clarification required.

  • Your bet is 10%. Does that mean that, if you start with 500.00, you will always bet 50.00, or will your next bet be 10% of your current bankroll?
  • You say 500 times, but what if you are unlucky and run out of cash?

hey, always 10% of bankroll, so if you win first bet your bankroll will be 550 hence next bet will be 55 EUR.
yes, very true, it would be great to indicate in which occurrence it happens. lets say 349 bet for example.

Big Thanks

Link to comment
Share on other sites

I thought the same at begging but consider this;

500 Bankroll
1. Bet is 50 EURO / 2.00 ODDS (possible winning 100 EURO)

When you place the bet, you bankroll became 450 EURO and will stay the same if you loose; however if you win you bankroll is now 450 + 100 = 550 EUR.

Thank you

 

 

 

Link to comment
Share on other sites

Yes, sure as  i mentioned above.

500 Bankroll
1. Bet is 50 EURO / 2.00 ODDS (possible winning 100 EURO)

When you place the bet, you bankroll became 450 EURO and will stay the same if you loose; however if you win you bankroll is now 450 + 100 = 550 EUR.

Link to comment
Share on other sites

Something like this?

<?php
const BETS = 500;

$bankroll = 500;
$pcent    = 0.1;
$odds     = 2;


function betting(&$bankroll, $betPerc, $odds)
{
    for ($i=1; $i <= BETS; $i++) {
        if ($bankroll < 0.5) break;
        $win = rand(0,1);
        $bet = $bankroll * $betPerc;
        $bankroll +=  ($win ? $bet * $odds - $bet : - $bet);
        printf("| %3d | %20.2f | %s  | %20s |<br>", $i, $bet, $win ? '&check;' : '&times;', number_format($bankroll,2));
    }
}


echo '<pre>';
printf("| %54.2f |<br>", $bankroll);
betting($bankroll, $pcent, $odds); 

?>

 

Link to comment
Share on other sites

3 hours ago, Barand said:

Something like this?

Amazing, looks pretty straight forward, how could i see PROFIT for each winning unit ? Plus one more question how to calculate how many wins in 500 in % please ?

Big Thanks

3 hours ago, Barand said:
<?php
const BETS = 500;

$bankroll = 500;
$pcent    = 0.1;
$odds     = 2;


function betting(&$bankroll, $betPerc, $odds)
{
    for ($i=1; $i <= BETS; $i++) {
        if ($bankroll < 0.5) break;
        $win = rand(0,1);
        $bet = $bankroll * $betPerc;
        $bankroll +=  ($win ? $bet * $odds - $bet : - $bet);
        printf("| %3d | %20.2f | %s  | %20s |<br>", $i, $bet, $win ? '&check;' : '&times;', number_format($bankroll,2));
    }
}


echo '<pre>';
printf("| %54.2f |<br>", $bankroll);
betting($bankroll, $pcent, $odds); 

?>

 

 

Link to comment
Share on other sites

When you place the bet, you bankroll became 450 EURO and will stay the same if you loose; however if you win you bankroll is now 450 + 100 = 550 EUR.

If you loose profit is 0, if you win your profit is 50 EUR - so basically you could see profit next to each bet.

Thank you

Link to comment
Share on other sites

Hello there,

Not sure why it is wrong as i have bet before; maybe its different in each country but i doubt it.

Bank = 500 EURO
Bet 50 x 2 (odss) = 100 EURO
Bank After bet = 450 EURO and if win = 550 EURO.

This is how it works in my country. You never get back your bet + winnings as you mention above.

Thank you

 

 

Edited by wladoD
Link to comment
Share on other sites

You never get back your money that you wagered.  So what you are using as an example is NOT correct still.  If the odds are 2 to 1 that means you win twice as much as  you bet.  So the result is 100  But in actually all you did was get your money back and a 50 profit which is a 1 to 1 bet, not 2 to 1.

So if the odds are even (1 to 1), what do you get back?  Just the 50 that you bet?

Are you sure about this?  What county is there, cause I never want to gamble there!

Edited by ginerjm
  • Like 1
Link to comment
Share on other sites

@ginerjm That was my argument too, but I relented when I ran the simulation over 500 runs

If I took out the - $bet from a winning payout (so you weren't losing your stake money) but keeping the odds = 2 and the chance of win = rand(0, 1) then the accumulated bankroll would have made Elon Musk green with envy. EG

image.png.5618914d4ce535029338936f45f55c2e.png

Thinking about it, the odds of winning are even but you are being paid out at 2-1. So not surprising the gains are exponential.

To get it back on an even keel I then changed the chance of a win to $win = rand(0, $odds)==1 so the chance matched the odds.

Going back to the original method I decided was a matter of interpretation. The OP's odds of "2", I guess, is actually 1 in 2 (evens) so the OP's formaula works if the stake is lost but double is paid back.

Link to comment
Share on other sites

7 hours ago, ginerjm said:

You never get back your money that you wagered.  So what you are using as an example is NOT correct still.  If the odds are 2 to 1 that means you win twice as much as  you bet.  So the result is 100  But in actually all you did was get your money back and a 50 profit which is a 1 to 1 bet, not 2 to 1.

So if the odds are even (1 to 1), what do you get back?  Just the 50 that you bet?

Are you sure about this?  What county is there, cause I never want to gamble there!

Morning,

i get your point, we are from different part of the world, hence you guys are using different betting odds.

Quote

Fractional Odds
Fractional odds are displayed as 10/1 or 7/2.  There are several ways to try and understand them but the easiest way is “how much you will win”/”how much you stake”. So for example if you stake £1 at 10/1 you will win £10 (remember that’s your profit, you will receive your pound back too!). If you stake £2 at 7/2 then you will win £7 and get your £2 stake back.

I was always talking about decimal odds;
 

Quote

Decimal Odds
Now fractional odds are confusing and just by writing the above section I am wondering why on earth anyone still uses fractional odds! In the opinion of this bookmaker, decimal odds are far easier to understand. If I asked you quickly to say which is the bigger price, 7/4 or 9/5? You’d have to think about it, right? But if I asked which is the bigger number 2.75 or 2.80?  It’s not so hard. 

With decimal odds your stake is automatically included in your returns and it makes for a far easier calculation
So the equation for calculating returns from decimal odds (which are written as 1.80 or 4.50) the equation is so much simpler:

Thank you

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.