Optimize rebalance threshold for low volatility

This commit is contained in:
2025-12-21 22:49:28 +01:00
parent 73c77521d9
commit 1a12fde839
3 changed files with 183 additions and 10 deletions

View File

@ -88,6 +88,11 @@ MIN_ORDER_VALUE_USD = Decimal("10.0")
DYNAMIC_THRESHOLD_MULTIPLIER = Decimal("1.2")
MIN_TIME_BETWEEN_TRADES = 25
MAX_HEDGE_MULTIPLIER = Decimal("1.25")
# Rebalance Threshold (Base)
# Adjust this based on expected volatility:
# - Low Volatility (Weekend/Chop): 0.08 - 0.10 (8-10%) to reduce churn
# - High Volatility (Events): 0.05 (5%) to track price closely
BASE_REBALANCE_THRESHOLD_PCT = Decimal("0.08")
# Edge Protection
EDGE_PROXIMITY_PCT = Decimal("0.04")
@ -693,11 +698,7 @@ class ScalperHedger:
logger.info(f"[FILL] {fill['side']} {fill['sz']} @ {fill['px']} | Fee: {fees} | PnL: {pnl}")
if new_activity:
# Convert back to float for JSON compatibility
update_position_stats(self.active_position_id, {
"hedge_pnl_realized": round(float(self.accumulated_pnl), 2),
"hedge_fees_paid": round(float(self.accumulated_fees), 2)
})
logger.info(f"Fills tracked. Total Price PnL: {self.accumulated_pnl:.2f} | Total Fees: {self.accumulated_fees:.2f}")
except Exception as e:
logger.error(f"Error tracking fills: {e}")
@ -800,8 +801,11 @@ class ScalperHedger:
current_equity = pos_data['equity']
# Update JSON with latest equity stats
net_pnl = self.accumulated_pnl - self.accumulated_fees
update_position_stats(self.active_position_id, {
"hedge_equity_usd": float(current_equity)
"hedge_equity_usd": float(current_equity),
"hedge_pnl_realized": round(float(net_pnl), 2),
"hedge_fees_paid": round(float(self.accumulated_fees), 2)
})
# 3. Calculate Logic
@ -835,7 +839,7 @@ class ScalperHedger:
range_width_pct = (self.strategy.high_range - self.strategy.low_range) / self.strategy.low_range
# Ensure we satisfy PRICE_BUFFER_PCT (0.15%) minimum
base_threshold_pct = max(Decimal("0.05"), PRICE_BUFFER_PCT / range_width_pct if range_width_pct > 0 else Decimal("0.05"))
base_threshold_pct = max(BASE_REBALANCE_THRESHOLD_PCT, PRICE_BUFFER_PCT / range_width_pct if range_width_pct > 0 else BASE_REBALANCE_THRESHOLD_PCT)
# 4. Apply Multiplier
target_threshold_pct = base_threshold_pct * vol_multiplier
@ -968,7 +972,8 @@ class ScalperHedger:
self.last_idle_log_time = time.time()
else:
if time.time() - self.last_idle_log_time > 30:
logger.info(f"[IDLE] Px: {price:.2f} | Diff: {diff_abs:.4f} < {rebalance_threshold:.4f} (Vol: {vol_pct*100:.3f}% x{vol_multiplier:.1f} | Thresh: {final_threshold_pct*100:.1f}%) | TotPnL: {self.accumulated_pnl:.2f}")
net_pnl = self.accumulated_pnl - self.accumulated_fees
logger.info(f"[IDLE] Px: {price:.2f} | Diff: {diff_abs:.4f} < {rebalance_threshold:.4f} (Vol: {vol_pct*100:.3f}% x{vol_multiplier:.1f} | Thresh: {final_threshold_pct*100:.1f}%) | TotPnL: {net_pnl:.2f}")
self.last_idle_log_time = time.time()
self.track_fills_and_pnl()