Spaces:
Sleeping
Sleeping
Create market_simulator.py
Browse files- market_simulator.py +15 -0
market_simulator.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class MarketSimulator:
|
| 2 |
+
def __init__(self, initial_balance=100.0):
|
| 3 |
+
self.balance = initial_balance
|
| 4 |
+
|
| 5 |
+
def simulate(self, data, predictor):
|
| 6 |
+
for i in range(len(data) - 1):
|
| 7 |
+
current_data = data.iloc[:i+1]
|
| 8 |
+
next_price, confidence = predictor.predict_next_price(current_data)
|
| 9 |
+
|
| 10 |
+
if confidence > 70:
|
| 11 |
+
self.balance -= 1
|
| 12 |
+
if next_price > current_data['Close'].iloc[-1]:
|
| 13 |
+
self.balance += 2 # Gain $1 for each successful prediction
|
| 14 |
+
|
| 15 |
+
return self.balance
|