Skip to content

Commit 82f6575

Browse files
Enhance Gemini AI Integration with Static Fallbacks
Added static fallback scenarios for AI integration failures.
1 parent 615f78c commit 82f6575

1 file changed

Lines changed: 101 additions & 4 deletions

File tree

showcase/data/adam_daily/2026-05-28/apollo.html

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ <h2 class="text-2xl md:text-3xl font-bold mb-4 flex items-center gap-3">
755755
initCharts();
756756
});
757757

758-
// 5. Gemini AI Integration
758+
// 5. Gemini AI Integration with Static Fallbacks
759759
const apiKey = ""; // Exec environment provides this
760760

761761
async function fetchWithRetry(url, options, maxRetries = 5) {
@@ -787,6 +787,80 @@ <h2 class="text-2xl md:text-3xl font-bold mb-4 flex items-center gap-3">
787787
}, 500);
788788
}
789789

790+
function getStaticFallbackHtml(input) {
791+
const lowerInput = input.toLowerCase();
792+
let html = "";
793+
794+
if (lowerInput.includes("150bps widening") || lowerInput.includes("high-yield spreads")) {
795+
html = `
796+
<div class="flex items-center gap-2 mb-4">
797+
<span class="text-brand-alert bg-red-100 p-1 rounded">⚠️</span>
798+
<span class="text-xs font-mono text-brand-secondary bg-gray-200 px-2 py-1 rounded">STATIC MODE SIMULATION</span>
799+
</div>
800+
<h3 class="text-xl font-bold text-brand-primary mb-4">Scenario: High-Yield Spread Shock</h3>
801+
<div class="space-y-4">
802+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
803+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">1. NAV Impact</h4>
804+
<p>Estimated mark-to-market drop of <strong class="text-brand-alert">-6.5% to -8.2%</strong> across diversified private credit vehicles. The daily pricing model immediately prices in the spread widening, destroying the historical quarterly lag buffer that previously insulated NAVs.</p>
805+
</div>
806+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
807+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">2. BSL Collateral Quality</h4>
808+
<p>CLO structures face severe stress. The sudden spread widening triggers MVOC (Market Value Overcollateralization) test failures in marginal CLOs. CCC-rated buckets instantly breach 7.5% limits as downgrades cascade, forcing cash flow diversions from equity tranches.</p>
809+
</div>
810+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
811+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">3. Sector Vulnerability</h4>
812+
<p><strong>Tech/SaaS</strong> (due to high leverage multiples) and <strong>Healthcare Rollups</strong> face the most severe repricing, with secondary bids dropping into the low 80s as broad index liquidity evaporates.</p>
813+
</div>
814+
</div>
815+
`;
816+
} else if (lowerInput.includes("10b in redemptions") || lowerInput.includes("cre sectors")) {
817+
html = `
818+
<div class="flex items-center gap-2 mb-4">
819+
<span class="text-brand-alert bg-red-100 p-1 rounded">⚠️</span>
820+
<span class="text-xs font-mono text-brand-secondary bg-gray-200 px-2 py-1 rounded">STATIC MODE SIMULATION</span>
821+
</div>
822+
<h3 class="text-xl font-bold text-brand-primary mb-4">Scenario: Redemption Liquidity Crunch</h3>
823+
<div class="space-y-4">
824+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
825+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">1. NAV Impact</h4>
826+
<p>Estimated mark-to-market drop of <strong class="text-brand-alert">-5.0% to -7.5%</strong>. Forced selling to meet the massive $10B redemption queue drives down bids aggressively across the entire credit platform as the illiquidity premium is stripped away.</p>
827+
</div>
828+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
829+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">2. BSL Collateral Quality</h4>
830+
<p>"Reverse adverse selection" takes hold. Managers are forced to liquidate their most liquid, highest-quality first-lien loans just to meet the redemption gate, leaving the remaining portfolio heavily concentrated in toxic, illiquid, and lower-rated tranches.</p>
831+
</div>
832+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
833+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">3. Sector Vulnerability</h4>
834+
<p><strong>CRE Mezzanine</strong> debt functionally marks to zero in clearing scenarios. <strong>SaaS</strong> cash flow loans see valuation multiples compress rapidly from 15x to 9x, triggering technical defaults across the covenant-heavy portions of the book.</p>
835+
</div>
836+
</div>
837+
`;
838+
} else {
839+
html = `
840+
<div class="flex items-center gap-2 mb-4">
841+
<span class="text-brand-alert bg-red-100 p-1 rounded">⚠️</span>
842+
<span class="text-xs font-mono text-brand-secondary bg-gray-200 px-2 py-1 rounded">STATIC MODE SIMULATION</span>
843+
</div>
844+
<h3 class="text-xl font-bold text-brand-primary mb-4">Scenario: Custom Market Shock</h3>
845+
<div class="space-y-4">
846+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
847+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">1. NAV Impact</h4>
848+
<p>Baseline algorithmic stress test indicates an immediate <strong class="text-brand-alert">-3.0% to -5.5%</strong> repricing event under the daily mark-to-market regime, wiping out YTD yield generation instantly.</p>
849+
</div>
850+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
851+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">2. BSL Collateral Quality</h4>
852+
<p>Increased volatility pressures interest coverage ratios (ICRs) across the board. CLO equity tranches halt distributions as overcollateralization cushions thin out, forcing mezzanine tranches to absorb the shock.</p>
853+
</div>
854+
<div class="bg-white p-4 rounded border border-gray-200 shadow-sm">
855+
<h4 class="font-bold text-brand-text mb-2 border-b pb-1">3. Sector Vulnerability</h4>
856+
<p>Highly leveraged sectors relying on forward EBITDA add-backs and those with significant duration mismatches face immediate downgrades and bid-ask spread blowouts.</p>
857+
</div>
858+
</div>
859+
`;
860+
}
861+
return html;
862+
}
863+
790864
async function runAiSimulation() {
791865
const input = document.getElementById('scenario-input').value;
792866
const errorMsg = document.getElementById('ai-error-msg');
@@ -808,6 +882,24 @@ <h2 class="text-2xl md:text-3xl font-bold mb-4 flex items-center gap-3">
808882
loading.classList.add('flex');
809883
resultsDiv.classList.add('hidden');
810884

885+
// --- STATIC MODE CHECK ---
886+
const isOfflineMode = !apiKey || apiKey.trim() === "";
887+
888+
if (isOfflineMode) {
889+
// Simulate network/processing delay for static mode
890+
await new Promise(resolve => setTimeout(resolve, 1500));
891+
892+
resultsDiv.innerHTML = getStaticFallbackHtml(input);
893+
resultsDiv.classList.remove('hidden');
894+
895+
btn.disabled = false;
896+
btn.classList.remove('opacity-50', 'cursor-not-allowed');
897+
loading.classList.add('hidden');
898+
loading.classList.remove('flex');
899+
return;
900+
}
901+
// --- END STATIC MODE CHECK ---
902+
811903
const systemPrompt = `You are a Senior Risk Analyst evaluating a Private Credit portfolio. Apollo Global Management has just transitioned its $830B credit platform to 100% daily pricing, destroying the traditional "illiquidity premium" and exposing actual market volatility.
812904
813905
The user will provide a macroeconomic shock scenario. Your job is to predict the immediate fallout on the Broadly Syndicated Loan (BSL) market and Private Credit NAVs under this new transparent DAILY pricing model.
@@ -840,9 +932,14 @@ <h2 class="text-2xl md:text-3xl font-bold mb-4 flex items-center gap-3">
840932
resultsDiv.innerHTML = text;
841933
resultsDiv.classList.remove('hidden');
842934
} catch (error) {
843-
console.error("Simulation Error:", error);
844-
errorMsg.innerHTML = "Error connecting to the AI Simulation Engine. Please try again later.";
845-
errorMsg.classList.remove('hidden');
935+
console.error("Simulation API Error, routing to static fallback:", error);
936+
937+
// Route to static fallback if live API fails
938+
let fallbackHtml = getStaticFallbackHtml(input);
939+
fallbackHtml += `<p class="mt-4 text-xs text-brand-alert border-t border-gray-200 pt-2 text-right">Note: Live API connection failed. Displaying simulated static fallback data.</p>`;
940+
941+
resultsDiv.innerHTML = fallbackHtml;
942+
resultsDiv.classList.remove('hidden');
846943
} finally {
847944
btn.disabled = false;
848945
btn.classList.remove('opacity-50', 'cursor-not-allowed');

0 commit comments

Comments
 (0)