Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +78 -30
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,88 @@
|
|
| 1 |
-
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
})
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
+
import random
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
st.title("Stake Dice Strategy Simulator: ZachXBT vs ZachXBT+")
|
| 7 |
|
| 8 |
+
# Sidebar inputs
|
| 9 |
+
st.sidebar.header("Simulation Settings")
|
| 10 |
+
initial_balance = st.sidebar.number_input("Starting Balance (USD)", value=200.0, step=10.0)
|
| 11 |
+
base_bet = st.sidebar.number_input("Base Bet (USD)", value=0.0001, step=0.0001, format="%.4f")
|
| 12 |
+
num_rounds = st.sidebar.number_input("Number of Bets", value=5000, step=1000)
|
| 13 |
+
seed = st.sidebar.number_input("Random Seed (optional)", value=42)
|
| 14 |
|
| 15 |
+
random.seed(seed)
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Constants
|
| 18 |
+
multiplier_2_02 = 49.5
|
| 19 |
+
multiplier_5_00 = 19.0
|
| 20 |
+
win_chance_2_02 = 0.0202
|
| 21 |
+
win_chance_5_00 = 0.05
|
| 22 |
|
| 23 |
+
def simulate(improved=False):
|
| 24 |
+
balance = initial_balance
|
| 25 |
+
bet = base_bet
|
| 26 |
+
win_chance = win_chance_2_02
|
| 27 |
+
current_multiplier = multiplier_2_02
|
| 28 |
+
results = []
|
| 29 |
+
losses = 0
|
| 30 |
+
profit = 0.0
|
| 31 |
+
win_streak = 0
|
| 32 |
|
| 33 |
+
for _ in range(num_rounds):
|
| 34 |
+
roll = random.random()
|
| 35 |
+
if roll < win_chance:
|
| 36 |
+
win = bet * current_multiplier
|
| 37 |
+
balance += win - bet
|
| 38 |
+
profit += win - bet
|
| 39 |
+
bet = base_bet
|
| 40 |
+
win_streak += 1
|
| 41 |
+
losses = 0
|
| 42 |
|
| 43 |
+
if improved:
|
| 44 |
+
if profit > 0.05:
|
| 45 |
+
bet = max(base_bet, bet * 0.5)
|
| 46 |
+
if profit < -0.10:
|
| 47 |
+
win_chance = win_chance_5_00
|
| 48 |
+
current_multiplier = multiplier_5_00
|
| 49 |
+
else:
|
| 50 |
+
win_chance = win_chance_2_02
|
| 51 |
+
current_multiplier = multiplier_2_02
|
| 52 |
+
else:
|
| 53 |
+
balance -= bet
|
| 54 |
+
profit -= bet
|
| 55 |
+
losses += 1
|
| 56 |
+
win_streak = 0
|
| 57 |
+
if losses % 10 == 0:
|
| 58 |
+
bet *= 2
|
| 59 |
|
| 60 |
+
results.append(balance)
|
| 61 |
+
return results
|
| 62 |
+
|
| 63 |
+
# Run simulations
|
| 64 |
+
original = simulate(improved=False)
|
| 65 |
+
improved = simulate(improved=True)
|
| 66 |
+
|
| 67 |
+
# Plotting
|
| 68 |
+
st.line_chart({
|
| 69 |
+
"Original ZachXBT": original,
|
| 70 |
+
"Improved ZachXBT+": improved
|
| 71 |
})
|
| 72 |
|
| 73 |
+
# Summary
|
| 74 |
+
def summarize(data, label):
|
| 75 |
+
return {
|
| 76 |
+
"Strategy": label,
|
| 77 |
+
"Final Balance": round(data[-1], 2),
|
| 78 |
+
"Max Balance": round(max(data), 2),
|
| 79 |
+
"Min Balance": round(min(data), 2),
|
| 80 |
+
"Profit": round(data[-1] - initial_balance, 2),
|
| 81 |
+
"Max Drawdown": round(max(data) - min(data), 2),
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
st.subheader("Simulation Summary")
|
| 85 |
+
st.write(pd.DataFrame([
|
| 86 |
+
summarize(original, "Original ZachXBT"),
|
| 87 |
+
summarize(improved, "Improved ZachXBT+")
|
| 88 |
+
]))
|