Fix: Guaranteed price movement in offline mode by tightening spreads and increasing agent aggression
Browse files- app.py +1 -1
- engine/simulation.py +10 -10
app.py
CHANGED
|
@@ -302,7 +302,7 @@ def run_simulation(n_mom, n_mr, n_fund, n_noise, n_mm,
|
|
| 302 |
log_to_csv=False,
|
| 303 |
base_volatility=volatility,
|
| 304 |
warmup_ticks=int(warmup_ticks),
|
| 305 |
-
enable_seed_liquidity=
|
| 306 |
fee_per_trade=0.01
|
| 307 |
)
|
| 308 |
|
|
|
|
| 302 |
log_to_csv=False,
|
| 303 |
base_volatility=volatility,
|
| 304 |
warmup_ticks=int(warmup_ticks),
|
| 305 |
+
enable_seed_liquidity=True,
|
| 306 |
fee_per_trade=0.01
|
| 307 |
)
|
| 308 |
|
engine/simulation.py
CHANGED
|
@@ -272,10 +272,10 @@ class SimulationEngine:
|
|
| 272 |
if len(prices) >= 3:
|
| 273 |
trend = prices[-1] - prices[-3]
|
| 274 |
if trend > 0.1:
|
| 275 |
-
price = round(mid * 1.
|
| 276 |
orders.append(Order(agent.agent_id, Side.BUY, price, random.randint(1, 5), self.tick))
|
| 277 |
elif trend < -0.1:
|
| 278 |
-
price = round(mid * 0.
|
| 279 |
orders.append(Order(agent.agent_id, Side.SELL, price, random.randint(1, 5), self.tick))
|
| 280 |
|
| 281 |
elif agent_type == "MeanReversion":
|
|
@@ -285,10 +285,10 @@ class SimulationEngine:
|
|
| 285 |
std = math.sqrt(variance) if variance > 0 else 0.01
|
| 286 |
z = (mid - mean) / std if std > 0 else 0
|
| 287 |
if z > 1.5:
|
| 288 |
-
price = round(mid * 0.
|
| 289 |
orders.append(Order(agent.agent_id, Side.SELL, price, random.randint(1, 4), self.tick))
|
| 290 |
elif z < -1.5:
|
| 291 |
-
price = round(mid * 1.
|
| 292 |
orders.append(Order(agent.agent_id, Side.BUY, price, random.randint(1, 4), self.tick))
|
| 293 |
|
| 294 |
elif agent_type == "Fundamental":
|
|
@@ -297,19 +297,19 @@ class SimulationEngine:
|
|
| 297 |
fv = agent.fair_value
|
| 298 |
gap = (mid - fv) / fv
|
| 299 |
if gap < -0.03:
|
| 300 |
-
price = round(mid * 1.
|
| 301 |
orders.append(Order(agent.agent_id, Side.BUY, price, random.randint(1, 3), self.tick))
|
| 302 |
elif gap > 0.03:
|
| 303 |
-
price = round(mid * 0.
|
| 304 |
orders.append(Order(agent.agent_id, Side.SELL, price, random.randint(1, 3), self.tick))
|
| 305 |
|
| 306 |
elif agent_type == "MarketMaker":
|
| 307 |
# Always post both sides
|
| 308 |
-
bid_price = round(mid * 0.
|
| 309 |
-
ask_price = round(mid * 1.
|
| 310 |
-
qty =
|
| 311 |
if abs(agent.state.position) > 20:
|
| 312 |
-
qty =
|
| 313 |
orders.append(Order(agent.agent_id, Side.BUY, bid_price, qty, self.tick))
|
| 314 |
orders.append(Order(agent.agent_id, Side.SELL, ask_price, qty, self.tick))
|
| 315 |
|
|
|
|
| 272 |
if len(prices) >= 3:
|
| 273 |
trend = prices[-1] - prices[-3]
|
| 274 |
if trend > 0.1:
|
| 275 |
+
price = round(mid * 1.003, 2) # More aggressive
|
| 276 |
orders.append(Order(agent.agent_id, Side.BUY, price, random.randint(1, 5), self.tick))
|
| 277 |
elif trend < -0.1:
|
| 278 |
+
price = round(mid * 0.997, 2) # More aggressive
|
| 279 |
orders.append(Order(agent.agent_id, Side.SELL, price, random.randint(1, 5), self.tick))
|
| 280 |
|
| 281 |
elif agent_type == "MeanReversion":
|
|
|
|
| 285 |
std = math.sqrt(variance) if variance > 0 else 0.01
|
| 286 |
z = (mid - mean) / std if std > 0 else 0
|
| 287 |
if z > 1.5:
|
| 288 |
+
price = round(mid * 0.997, 2)
|
| 289 |
orders.append(Order(agent.agent_id, Side.SELL, price, random.randint(1, 4), self.tick))
|
| 290 |
elif z < -1.5:
|
| 291 |
+
price = round(mid * 1.003, 2)
|
| 292 |
orders.append(Order(agent.agent_id, Side.BUY, price, random.randint(1, 4), self.tick))
|
| 293 |
|
| 294 |
elif agent_type == "Fundamental":
|
|
|
|
| 297 |
fv = agent.fair_value
|
| 298 |
gap = (mid - fv) / fv
|
| 299 |
if gap < -0.03:
|
| 300 |
+
price = round(mid * 1.003, 2)
|
| 301 |
orders.append(Order(agent.agent_id, Side.BUY, price, random.randint(1, 3), self.tick))
|
| 302 |
elif gap > 0.03:
|
| 303 |
+
price = round(mid * 0.997, 2)
|
| 304 |
orders.append(Order(agent.agent_id, Side.SELL, price, random.randint(1, 3), self.tick))
|
| 305 |
|
| 306 |
elif agent_type == "MarketMaker":
|
| 307 |
# Always post both sides
|
| 308 |
+
bid_price = round(mid * 0.998, 2) # Tighter spread
|
| 309 |
+
ask_price = round(mid * 1.002, 2) # Tighter spread
|
| 310 |
+
qty = 10
|
| 311 |
if abs(agent.state.position) > 20:
|
| 312 |
+
qty = 5 # reduce size when inventory is large
|
| 313 |
orders.append(Order(agent.agent_id, Side.BUY, bid_price, qty, self.tick))
|
| 314 |
orders.append(Order(agent.agent_id, Side.SELL, ask_price, qty, self.tick))
|
| 315 |
|