feat(sandbox): deploy Phase 1 and Phase 2 of Portfolio Sandbox including Swamy-Arora GLS solver and stress-test visualization

This commit is contained in:
Antigravity Agent
2026-06-12 12:16:53 +02:00
parent 96f7643f8a
commit 36ac9e8397
17 changed files with 20956 additions and 510 deletions

View File

@@ -5,9 +5,11 @@ import { useSandboxStore } from '@/lib/store';
import { predictCryptoTrend, calculateBetaPosterior } from '@/lib/math/statistics';
import 'katex/dist/katex.min.css';
import { BlockMath, InlineMath } from 'react-katex';
import CryptoMathModal from './CryptoMathModal';
import {
Cpu, Search, RefreshCw, BarChart2, TrendingUp, AlertCircle, Info,
ChevronDown, ChevronUp, ArrowUpRight, ArrowDownRight, Compass, ShieldAlert, Sparkles
ChevronDown, ChevronUp, ArrowUpRight, ArrowDownRight, Compass, ShieldAlert, Sparkles,
BookOpen
} from 'lucide-react';
interface CoinData {
@@ -74,6 +76,7 @@ export default function CryptoDemo() {
const [customCoins, setCustomCoins] = useState<Record<string, CoinData>>({});
const [searchError, setSearchError] = useState(false);
const [showMathAccordion, setShowMathAccordion] = useState(false);
const [isMathModalOpen, setIsMathModalOpen] = useState(false);
const [simulatedTrialLogged, setSimulatedTrialLogged] = useState(false);
const [lastTrialSuccess, setLastTrialSuccess] = useState(false);
@@ -181,13 +184,23 @@ export default function CryptoDemo() {
Predictive Krypto-Modelle & Bayes Self-Correction
</h2>
</div>
<div className="bg-slate-900 border border-slate-800 rounded-xl px-4 py-2 flex items-center gap-3">
<Cpu className="text-cyan-400 w-5 h-5 animate-spin-slow" />
<div>
<p className="text-slate-400 text-xs">A-Priori Genauigkeit</p>
<p className="font-mono text-sm font-bold text-cyan-400">
{priorAccuracy.toFixed(1)}% (n={totalTrials})
</p>
<div className="flex flex-wrap items-center gap-3">
<button
onClick={() => setIsMathModalOpen(true)}
className="flex items-center gap-1.5 px-4 py-2 rounded-xl bg-slate-950/80 hover:bg-slate-900 border border-slate-800 hover:border-slate-700 transition-all font-semibold text-xs tracking-wider text-cyan-400 justify-center h-11"
>
<BookOpen className="w-3.5 h-3.5" />
<span>📖 Modulerklärung</span>
</button>
<div className="bg-slate-900 border border-slate-800 rounded-xl px-4 py-2 flex items-center gap-3 h-11">
<Cpu className="text-cyan-400 w-5 h-5 animate-spin-slow" />
<div>
<p className="text-slate-400 text-xs">A-Priori Genauigkeit</p>
<p className="font-mono text-sm font-bold text-cyan-400">
{priorAccuracy.toFixed(1)}% (n={totalTrials})
</p>
</div>
</div>
</div>
</div>
@@ -482,6 +495,8 @@ export default function CryptoDemo() {
</div>
)}
</div>
<CryptoMathModal isOpen={isMathModalOpen} onClose={() => setIsMathModalOpen(false)} />
</div>
);
}

View File

@@ -0,0 +1,109 @@
import React from 'react';
import { BookOpen } from 'lucide-react';
import 'katex/dist/katex.min.css';
import { BlockMath, InlineMath } from 'react-katex';
interface CryptoMathModalProps {
isOpen: boolean;
onClose: () => void;
}
export default function CryptoMathModal({ isOpen, onClose }: CryptoMathModalProps) {
React.useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
onClose();
}
};
if (isOpen) {
window.addEventListener('keydown', handleKeyDown);
}
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [isOpen, onClose]);
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/85 backdrop-blur-md p-4 sm:p-6 md:p-8">
<div className="bg-slate-900 border border-slate-800/80 rounded-3xl w-full max-w-4xl h-[80vh] flex flex-col overflow-hidden shadow-2xl relative text-slate-300">
{/* Modal Header */}
<div className="flex justify-between items-center px-6 py-4 bg-slate-950/40 border-b border-slate-800/60">
<div>
<h2 className="text-base font-bold bg-gradient-to-r from-cyan-400 to-sky-400 bg-clip-text text-transparent flex items-center gap-2">
<BookOpen className="w-5 h-5 text-cyan-400" /> Crypto Bayesian Markov - Math & Logic Specification
</h2>
<p className="text-[10px] text-slate-500 font-mono">Institutional Specification Manual</p>
</div>
<button
onClick={onClose}
className="text-slate-400 hover:text-slate-200 bg-slate-950/50 border border-slate-800 hover:border-slate-700 px-3 py-1.5 rounded-lg text-xs font-semibold font-mono transition-all cursor-pointer"
>
Schließen (ESC)
</button>
</div>
{/* Modal Body */}
<div className="flex-1 overflow-y-auto p-6 sm:p-8 space-y-6 text-slate-300 scrollbar-thin">
<div className="space-y-6">
<div className="border-b border-slate-800/80 pb-3">
<h3 className="text-base font-bold text-slate-200">4. Crypto Bayesian Markov Engine</h3>
<p className="text-xs text-slate-400 mt-1">Models momentum regimes and updates transition probabilities using on-chain alpha inputs.</p>
</div>
<div className="space-y-3">
<h4 className="text-xs font-bold text-cyan-400 uppercase tracking-wider font-mono">A. Markov Chain State Space</h4>
<p className="text-xs leading-relaxed text-slate-400">
The asset return state space is mapped into 3 momentum regimes:
</p>
<div className="grid grid-cols-3 gap-3 text-xs text-slate-400 font-mono text-center">
<div className="bg-slate-950/40 p-3 rounded-lg border border-slate-800/50">
<span className="block text-rose-400 font-bold">State 1 (S1)</span>
<span>Bearish Squeeze / Crackdown</span>
</div>
<div className="bg-slate-950/40 p-3 rounded-lg border border-slate-800/50">
<span className="block text-slate-300 font-bold">State 2 (S2)</span>
<span>Consolidation / Mean Reversion</span>
</div>
<div className="bg-slate-950/40 p-3 rounded-lg border border-slate-800/50">
<span className="block text-emerald-400 font-bold">State 3 (S3)</span>
<span>Parabolic Bull Run</span>
</div>
</div>
</div>
<div className="space-y-3">
<h4 className="text-xs font-bold text-cyan-400 uppercase tracking-wider font-mono">B. Transition Matrix (P)</h4>
<p className="text-xs leading-relaxed text-slate-400">
Calculates transition probabilities over rolling 90-day return vectors:
</p>
<div className="bg-slate-950/40 p-4 rounded-xl border border-slate-800/60 my-2">
<BlockMath math="P = \begin{bmatrix} p_{11} & p_{12} & p_{13} \\ p_{21} & p_{22} & p_{23} \\ p_{31} & p_{32} & p_{33} \end{bmatrix}" />
<p className="text-[11px] text-slate-400 font-mono mt-2 text-center">
where <InlineMath math="p_{ij} = P(X_{t+1} = S_j \mid X_t = S_i)" /> represents the frequency probability of moving from State i to State j.
</p>
</div>
</div>
<div className="space-y-3">
<h4 className="text-xs font-bold text-cyan-400 uppercase tracking-wider font-mono">C. Bayesian Update Engine</h4>
<p className="text-xs leading-relaxed text-slate-400">
When external alpha inputs (e.g. Funding Rate anomalies, Whale inflows) occur, state probabilities are updated using Bayes' theorem:
</p>
<div className="bg-slate-950/40 p-4 rounded-xl border border-slate-800/60 my-2">
<BlockMath math="P(S_i \mid \text{Alpha}) = \frac{P(\text{Alpha} \mid S_i) \times P(S_i)}{\sum_{j=1}^3 P(\text{Alpha} \mid S_j) \times P(S_j)}" />
<p className="text-[11px] text-slate-400 mt-2 font-mono leading-relaxed">
Where:<br/>
- <InlineMath math="P(S_i)" /> is the prior state probability from the Markov transition matrix.<br/>
- <InlineMath math="P(\text{Alpha} \mid S_i)" /> is the conditional likelihood of observing this whale spike / funding squeeze in State i.
</p>
</div>
</div>
</div>
</div>
</div>
</div>
);
}