73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""Signal Router visualization tab — live on slider change."""
|
|
|
|
import numpy as np
|
|
import streamlit as st
|
|
|
|
from src.primitives.signal_router import (
|
|
AdaptiveParams,
|
|
SignalRouterConfig,
|
|
simulate_signal_routing,
|
|
)
|
|
from dashboard.charts import fig_signal_routing
|
|
|
|
|
|
def render():
|
|
st.header("Signal Router")
|
|
st.caption("Parameters update live — no button needed (sub-ms computation).")
|
|
|
|
config = st.session_state.get("myco_config")
|
|
|
|
col1, col2 = st.columns(2)
|
|
with col1:
|
|
trajectory = st.selectbox(
|
|
"Price trajectory",
|
|
["stable", "bull", "crash", "volatile"],
|
|
index=3,
|
|
)
|
|
steps = st.slider("Steps", 50, 500, 200)
|
|
with col2:
|
|
k_vol_flow = st.slider("k_vol_flow", 0.0, 5.0, 1.0, 0.1)
|
|
k_dev_alpha = st.slider("k_dev_alpha", 0.0, 5.0, 2.0, 0.1)
|
|
k_vol_fee = st.slider("k_vol_fee", 0.0, 5.0, 1.5, 0.1)
|
|
k_oracle_vel = st.slider("k_oracle_vel", 0.0, 0.1, 0.01, 0.001, format="%.3f")
|
|
|
|
# Generate trajectory
|
|
t = np.linspace(0, 1, steps)
|
|
traj_map = {
|
|
"stable": lambda: [1.0] * steps,
|
|
"bull": lambda: (1.0 + t * 0.5).tolist(),
|
|
"crash": lambda: (1.0 - 0.4 * t + 0.1 * np.sin(t * 20)).tolist(),
|
|
"volatile": lambda: (1.0 + 0.3 * np.sin(t * 30) + 0.1 * np.cos(t * 7)).tolist(),
|
|
}
|
|
prices = traj_map[trajectory]()
|
|
|
|
# Use config's fee/flow params as base adaptive params
|
|
base_flow = config.flow_threshold if config else 0.1
|
|
base_alpha = config.pamm_params.alpha_bar if config else 10.0
|
|
base_surge = config.surge_fee_rate if config else 0.05
|
|
|
|
base = AdaptiveParams(
|
|
flow_threshold=base_flow,
|
|
pamm_alpha_bar=base_alpha,
|
|
surge_fee_rate=base_surge,
|
|
oracle_multiplier_velocity=0.0,
|
|
)
|
|
router_config = SignalRouterConfig(
|
|
k_vol_flow=k_vol_flow,
|
|
k_dev_alpha=k_dev_alpha,
|
|
k_vol_fee=k_vol_fee,
|
|
k_oracle_vel=k_oracle_vel,
|
|
)
|
|
|
|
result = simulate_signal_routing(base, router_config, prices)
|
|
result["prices"] = prices # Add for chart
|
|
|
|
st.plotly_chart(fig_signal_routing(result), use_container_width=True)
|
|
|
|
# Summary metrics
|
|
m1, m2, m3, m4 = st.columns(4)
|
|
m1.metric("Final Flow Threshold", f"{result['flow_threshold'][-1]:.6f}")
|
|
m2.metric("Final Alpha Bar", f"{result['pamm_alpha_bar'][-1]:.2f}")
|
|
m3.metric("Final Surge Fee", f"{result['surge_fee_rate'][-1]:.6f}")
|
|
m4.metric("Final Volatility", f"{result['volatility'][-1]:.6f}")
|