AlirezaX2 commited on
Commit
dbaa3f1
·
1 Parent(s): 18c2ef0

add kelly methods

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -8,9 +8,15 @@ import hvplot.pandas
8
 
9
  pn.extension('bokeh', template='bootstrap')
10
 
11
- def simulate(initialcapital , bet_chance , betsize , rewardrisk, riskpercent, max_rounds, max_profit , num_realization):
12
  hv.extension('bokeh')
13
-
 
 
 
 
 
 
14
  bet = lambda cash: cash * (betsize/100)
15
 
16
  all_profits = []
@@ -44,7 +50,7 @@ def simulate(initialcapital , bet_chance , betsize , rewardrisk, riskpercent, ma
44
  Reach Max profit: {round(len(rich) / len(all_profits) * 100):.1f} %
45
  Avg time to reach max profit:, {np.mean([ len(x) for x in rich ]):.1f}
46
  Challenge from {initialcapital}$ to {max_profit}$
47
- intial bet {betsize*initialcapital/100}$ with winrate={bet_chance}% reward to risk={rewardrisk} and possible reward/loss={riskpercent/100*betsize*initialcapital/100}
48
  """
49
  if round(len(bust) / len(all_profits)) > .5:
50
  alert_type="danger"
@@ -60,9 +66,9 @@ riskpercent = pn.widgets.FloatSlider(name='Risk %', start=0, end=100.0, step=1,
60
  max_rounds = pn.widgets.IntSlider(name='Max Rounds', start=1000, end=10000, step=1000, value=1000)
61
  max_profit = pn.widgets.IntSlider(name='Max Profit', start=10000, end=10000000, step=1000, value=1000000)
62
  num_realization = pn.widgets.IntSlider(name='Number of Realization', start=100, end=10000, step=100, value=100)
63
- selectedmethod = pn.widgets.Select(name='Select Method', value='Mean', options=['Full Kelly Criterion' , 'Half Kelly Criterion' , 'Fractional Kelly Criterion','Constant Proportion Betting','Martingale Betting System'])
64
 
65
- bound_plot = pn.bind(simulate, initialcapital= initialcapital, bet_chance =bet_chance , betsize=betsize , rewardrisk=rewardrisk, riskpercent=riskpercent, max_rounds=max_rounds, max_profit=max_profit , num_realization=num_realization)
66
 
67
  pn.Row(pn.Column(initialcapital, bet_chance, betsize, rewardrisk, riskpercent, max_rounds, max_profit, num_realization,selectedmethod),bound_plot).servable(title="Bet Size Optimizer - Simulation Account Growth")
68
 
 
8
 
9
  pn.extension('bokeh', template='bootstrap')
10
 
11
+ def simulate(initialcapital , bet_chance , betsize , rewardrisk, riskpercent, max_rounds, max_profit, num_realization, selectedmethod):
12
  hv.extension('bokeh')
13
+ if selectedmethod=='Full Kelly Criterion':
14
+ betsize = 2 * bet_chance-100
15
+ elif selectedmethod== 'Half Kelly Criterion':
16
+ betsize = 0.5 * ( 2*bet_chance-100)
17
+ elif selectedmethod=='Fractional Kelly Criterion':
18
+ betsize = 0.25 * (2*bet_chance-100)
19
+
20
  bet = lambda cash: cash * (betsize/100)
21
 
22
  all_profits = []
 
50
  Reach Max profit: {round(len(rich) / len(all_profits) * 100):.1f} %
51
  Avg time to reach max profit:, {np.mean([ len(x) for x in rich ]):.1f}
52
  Challenge from {initialcapital}$ to {max_profit}$
53
+ intial bet {betsize*initialcapital/100}$ with winrate={bet_chance}% reward to risk={rewardrisk}:1 and possible reward/loss={riskpercent/100*betsize*initialcapital/100}$ and betsize = betsize %
54
  """
55
  if round(len(bust) / len(all_profits)) > .5:
56
  alert_type="danger"
 
66
  max_rounds = pn.widgets.IntSlider(name='Max Rounds', start=1000, end=10000, step=1000, value=1000)
67
  max_profit = pn.widgets.IntSlider(name='Max Profit', start=10000, end=10000000, step=1000, value=1000000)
68
  num_realization = pn.widgets.IntSlider(name='Number of Realization', start=100, end=10000, step=100, value=100)
69
+ selectedmethod = pn.widgets.Select(name='Select Method', value='Mean', options=['Full Kelly Criterion' , 'Half Kelly Criterion' , 'Fractional Kelly Criterion','Constant Proportion Betting'])
70
 
71
+ bound_plot = pn.bind(simulate, initialcapital= initialcapital, bet_chance =bet_chance , betsize=betsize , rewardrisk=rewardrisk, riskpercent=riskpercent, max_rounds=max_rounds, max_profit=max_profit , num_realization=num_realization,selectedmethod=selectedmethod)
72
 
73
  pn.Row(pn.Column(initialcapital, bet_chance, betsize, rewardrisk, riskpercent, max_rounds, max_profit, num_realization,selectedmethod),bound_plot).servable(title="Bet Size Optimizer - Simulation Account Growth")
74