Install
openclaw skills install quant-risk-dashboardProfessional quantitative trading risk management dashboard. Real-time VaR/CVaR calculation, stress testing, position limits, exposure monitoring, drawdown alerts, and comprehensive risk metrics visualization.
openclaw skills install quant-risk-dashboardProfessional risk management system for quantitative trading.
pip install pandas numpy scipy plotly dash
from quant_risk import RiskDashboard
dashboard = RiskDashboard(
initial_capital=1000000,
var_confidence=0.95,
max_position_pct=0.15,
max_drawdown_pct=0.20
)
dashboard.add_position(
symbol='600519',
shares=1000,
entry_price=1800.0,
current_price=1850.0
)
dashboard.add_position(
symbol='000858',
shares=5000,
entry_price=45.0,
current_price=48.0
)
metrics = dashboard.get_risk_metrics()
print(f"VaR (95%): {metrics['var_95']:,.2f}")
print(f"CVaR (95%): {metrics['cvar_95']:,.2f}")
print(f"Sharpe Ratio: {metrics['sharpe_ratio']:.2f}")
print(f"Max Drawdown: {metrics['max_drawdown']:.2%}")
print(f"Total Exposure: {metrics['total_exposure']:,.0f}")
scenarios = {
'2008 Crash': -0.50,
'2020 Covid': -0.30,
'Rate Hike': -0.15,
'Custom': -0.25
}
results = dashboard.stress_test(scenarios)
for name, result in results.items():
print(f"{name}: P&L = {result['pnl']:,.2f}")
dashboard.start_dashboard(port=8050)
# Open http://localhost:8050
| Method | Description |
|---|---|
add_position(symbol, shares, entry, current) | Add position |
remove_position(symbol) | Close position |
update_price(symbol, price) | Update market price |
get_positions() | Get all positions |
get_risk_metrics() | Calculate risk metrics |
| Method | Description |
|---|---|
calculate_var(method='historical') | Calculate VaR |
calculate_cvar() | Calculate CVaR |
stress_test(scenarios) | Run stress tests |
factor_exposure() | Calculate factor exposure |
sector_allocation() | Get sector breakdown |
| Method | Description |
|---|---|
add_alert(condition, message) | Create alert |
get_alerts() | Get active alerts |
clear_alerts() | Clear alerts |
| Method | Description |
|---|---|
generate_report(format='pdf') | Generate report |
get_daily_summary() | Daily summary |
limits = {
'max_position_pct': 0.15, # 15% per position
'max_sector_pct': 0.30, # 30% per sector
'max_leverage': 1.5, # 1.5x leverage
'max_drawdown': 0.20, # 20% stop loss
'max_var_pct': 0.05, # 5% VaR limit
}
alerts = {
'drawdown_warning': 0.10, # 10% drawdown warning
'drawdown_critical': 0.15, # 15% critical
'var_warning': 0.03, # 3% VaR warning
'volatility_spike': 2.0, # 2x normal volatility
}
dashboard.start_dashboard()
# Features:
# - Real-time position table
# - P&L charts
# - Risk metrics gauges
# - Sector pie chart
# - Drawdown curve
# - Factor exposure bar chart
# P&L Chart
chart = dashboard.plot_pnl_history()
# Risk Decomposition
chart = dashboard.plot_risk_attribution()
# Scenario Comparison
chart = dashboard.plot_scenarios()
# From trading system
import asyncio
async def update_positions():
while True:
positions = await trading_system.get_positions()
for pos in positions:
dashboard.update_price(pos.symbol, pos.current_price)
await asyncio.sleep(60) # Update every minute
asyncio.run(update_positions())
# Send alerts to Slack/WeChat
def on_alert(alert):
send_webhook(
url=os.getenv('ALERT_WEBHOOK'),
message=f"Risk Alert: {alert['message']}"
)
dashboard.set_alert_callback(on_alert)