I am trying to answer the question:
Given a game of chance with a "house edge" E (defined below), what is the maximum "amount ahead" A (defined below) when I should exit the game, if I want to achieve probability P that I will not run out of money if I bring bankroll B (defined below)?
E is defined as the average amount lost per bet, as a proportion of the amount of the bet. (e.g. 2%)
B is defined the amount you bring to the game (the maximum you are willing to lose, e.g. $500)
A is the amount you are ahead of your starting amount, e.g. A=$50 means that you have won $50, e.g., you started with $500 and now have $550.
P is the probability of not losing all my money (B) before getting ahead by A that I am willing to tolerate (e.g. 90%)
I am trying to define function f, such that A = f(P,B,E)
For example, in this statement:
With a house edge of 2%, and a bankroll of $500, you should leave when you are $50 ahead, if you want a 90% probability of not running out of money
the variables would be:
E=0.02, B=500, A=50, P=0.9 for A=f(P,B,E)
NOTE: I'm not sure if this question belongs on this site or on mathematics.