import React, { useState } from "react"; import { checkAlerts } from "../api"; const METRICS = [ { value: "sharpe_ratio", label: "Sharpe Ratio" }, { value: "annual_return", label: "Annual Return" }, { value: "annual_volatility", label: "Annual Volatility" }, { value: "max_drawdown", label: "Max Drawdown" }, { value: "sortino_ratio", label: "Sortino Ratio" }, { value: "VaR_95_daily", label: "VaR (95% Daily)" }, ]; const OPERATORS = [ { value: "lt", label: "< (less than)" }, { value: "gt", label: "> (greater than)" }, { value: "lte", label: "<= (at most)" }, { value: "gte", label: ">= (at least)" }, ]; export default function AlertsPanel({ portfolio }) { const [rules, setRules] = useState([ { id: "1", metric: "sharpe_ratio", operator: "lt", threshold: 0.5, label: "Low Sharpe" }, ]); const [results, setResults] = useState(null); const [checking, setChecking] = useState(false); const addRule = () => { setRules([...rules, { id: String(rules.length + 1), metric: "sharpe_ratio", operator: "lt", threshold: 0, label: "", }]); }; const updateRule = (idx, field, value) => { const updated = [...rules]; updated[idx] = { ...updated[idx], [field]: value }; setRules(updated); }; const removeRule = (idx) => { setRules(rules.filter((_, i) => i !== idx)); }; const handleCheck = async () => { setChecking(true); try { const data = await checkAlerts(portfolio, rules); setResults(data); } catch (e) { setResults({ error: e.message }); } setChecking(false); }; return (
Set metric thresholds and check if your portfolio triggers them.
{rules.map((rule, i) => (| Alert | Metric | Condition | Current |
|---|---|---|---|
| {t.label || t.rule_id} | {t.metric} | {t.operator} {t.threshold} | {typeof t.current_value === "number" ? t.current_value.toFixed(4) : t.current_value} |