Spaces:
Running
Running
add app.py
Browse files- Dockerfile +16 -0
- app.py +68 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
RUN python3 -m pip install --no-cache-dir --upgrade pip
|
| 7 |
+
RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
CMD ["panel", "serve", "/code/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
|
| 12 |
+
|
| 13 |
+
RUN mkdir /.cache
|
| 14 |
+
RUN chmod 777 /.cache
|
| 15 |
+
RUN mkdir .chroma
|
| 16 |
+
RUN chmod 777 .chroma
|
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import math
|
| 5 |
+
|
| 6 |
+
import hvplot as hv
|
| 7 |
+
import panel as pn
|
| 8 |
+
import hvplot.pandas
|
| 9 |
+
|
| 10 |
+
hv.extension('bokeh')
|
| 11 |
+
|
| 12 |
+
def simulate(initialcapital , bet_chance , betsize , rewardrisk, riskpercent, max_rounds, max_profit , num_realization):
|
| 13 |
+
|
| 14 |
+
bet = lambda cash: cash * betsize
|
| 15 |
+
|
| 16 |
+
all_profits = []
|
| 17 |
+
for i in range(0, num_realization):
|
| 18 |
+
profits = []
|
| 19 |
+
cash = initialcapital
|
| 20 |
+
for i in range(0, max_rounds):
|
| 21 |
+
if cash <= 1: # went blowout
|
| 22 |
+
break
|
| 23 |
+
|
| 24 |
+
if cash >= max_profit:
|
| 25 |
+
break
|
| 26 |
+
|
| 27 |
+
bet_value = bet(cash)
|
| 28 |
+
if np.random.rand() < bet_chance:
|
| 29 |
+
cash += bet_value *rewardrisk * riskpercent #*.1
|
| 30 |
+
else:
|
| 31 |
+
cash -= bet_value *riskpercent #* .05
|
| 32 |
+
|
| 33 |
+
profits.append(cash)
|
| 34 |
+
|
| 35 |
+
all_profits.append(profits)
|
| 36 |
+
df = pd.DataFrame(all_profits).T
|
| 37 |
+
plot1 = df.hvplot.line( logy=True, height=600, width=1200).opts(show_grid=True, ylabel='Profit', xlabel='Bet')
|
| 38 |
+
|
| 39 |
+
bust = [ x for x in all_profits if x[-1] <= 1 ]
|
| 40 |
+
rich = [ x for x in all_profits if x[-1] >= max_profit ]
|
| 41 |
+
text = f"""Blowout: {round(len(bust) / len(all_profits) * 100)} %
|
| 42 |
+
Avg time to go Blowout: {np.mean([ len(x) for x in bust ]):.1f}
|
| 43 |
+
Reach Max profit: {round(len(rich) / len(all_profits) * 100):.1f} %
|
| 44 |
+
Avg time to reach max profit:, {np.mean([ len(x) for x in rich ]):.1f}
|
| 45 |
+
Challenge from {initialcapital}$ to {max_profit}$
|
| 46 |
+
"""
|
| 47 |
+
if round(len(bust) / len(all_profits)) > .5:
|
| 48 |
+
alert_type="danger"
|
| 49 |
+
else:
|
| 50 |
+
alert_type="success"
|
| 51 |
+
return pn.Column(plot1, pn.pane.Alert(text, alert_type=alert_type, height=150, width=1200, sizing_mode="fixed"))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
initialcapital = pn.widgets.IntSlider(name='Initial Capital', start=0, end=100000, step=1000, value=2000)
|
| 55 |
+
bet_chance = pn.widgets.FloatSlider(name='Win Rate', start=0, end=1.0, step=0.1, value=0.60)
|
| 56 |
+
betsize = pn.widgets.FloatSlider(name='Bet Size', start=0, end=1.0, step=0.1, value=0.50)
|
| 57 |
+
rewardrisk = pn.widgets.FloatSlider(name='Reward Risk', start=0, end=1.0, step=0.1, value=1.0)
|
| 58 |
+
riskpercent = pn.widgets.FloatSlider(name='risk percent', start=0, end=1.0, step=0.1, value=1.0)
|
| 59 |
+
max_rounds = pn.widgets.IntSlider(name='Max Rounds', start=1000, end=10000, step=1000, value=1000)
|
| 60 |
+
max_profit = pn.widgets.IntSlider(name='Max Profit', start=10000, end=10000000, step=1000, value=1000000)
|
| 61 |
+
num_realization = pn.widgets.IntSlider(name='Number of Realization', start=100, end=10000, step=100, value=100)
|
| 62 |
+
# selectedmethod = pn.widgets.Select(name='Select Method', value='Mean', options=['Mean' , 'Min' , 'Max'])
|
| 63 |
+
|
| 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),bound_plot).servable(title="Bet Size Optimizer - Simulation Account Growth")
|
| 68 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
panel
|
| 2 |
+
hvplot
|
| 3 |
+
bokeh
|