<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Feng Yu</title>
    <description>The latest articles on DEV Community by Feng Yu (@fengyugbt).</description>
    <link>https://dev.to/fengyugbt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4113833%2Ffa0629ad-e957-46e6-8316-f702368a55dc.jpg</url>
      <title>DEV Community: Feng Yu</title>
      <link>https://dev.to/fengyugbt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fengyugbt"/>
    <language>en</language>
    <item>
      <title>I Built a Stock Market Crash Simulator Using Insurance Catastrophe Modeling</title>
      <dc:creator>Feng Yu</dc:creator>
      <pubDate>Mon, 07 Sep 2026 11:59:33 +0000</pubDate>
      <link>https://dev.to/fengyugbt/i-built-a-stock-market-crash-simulator-using-insurance-catastrophe-modeling-3c47</link>
      <guid>https://dev.to/fengyugbt/i-built-a-stock-market-crash-simulator-using-insurance-catastrophe-modeling-3c47</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why your portfolio falls apart exactly when you need it most — and what hurricane pricing can teach us about it.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;March 2020. The S&amp;amp;P 500 lost 34% in 33 days. Bitcoin fell with it. Gold fell with it. Even the "defensive" dividend stocks fell with it. Every asset class that your portfolio theory told you was "uncorrelated" suddenly moved in perfect lockstep — down.&lt;/p&gt;

&lt;p&gt;This is not a bug in the market. It's a feature of how markets behave in a crisis. And it's the exact moment that every standard risk model — the ones built on normal distributions — quietly goes blind.&lt;/p&gt;

&lt;p&gt;I spent months building a tool that doesn't go blind. Here's what I learned along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with normal distributions
&lt;/h2&gt;

&lt;p&gt;Most portfolio risk tools assume returns follow a normal distribution. The math is elegant, the tails are thin, and the models are tractable. There's just one problem: &lt;strong&gt;markets don't read the textbooks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In normal times, the correlation between asset classes sits somewhere around 0.3–0.6. In a crisis, it converges toward 1.0. Everything falls together. Your "diversified" portfolio suddenly behaves like a single concentrated bet.&lt;/p&gt;

&lt;p&gt;Standard Value-at-Risk (VaR) models compute something like "the worst 1% of outcomes." But when the true distribution has fat tails — when the 1% event is far worse than any normal distribution would ever allow — that number is dangerously optimistic. The model tells you the bridge can hold. The bridge collapses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where insurance comes in
&lt;/h2&gt;

&lt;p&gt;I come from a manufacturing and quality-engineering background, where you learn early that the &lt;strong&gt;unlikely event is the one that kills you&lt;/strong&gt;. A part that fails 0.1% of the time is fine — until it's the part holding an aircraft together.&lt;/p&gt;

&lt;p&gt;Insurance companies solved this problem a long time ago. When an insurer prices a hurricane policy, they don't ask "what's the average hurricane damage?" They ask something far more specific:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Hazard&lt;/strong&gt; — how do hurricanes actually happen? (frequency, intensity, path)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exposure&lt;/strong&gt; — what's in the path? (the houses, the people, the assets)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vulnerability&lt;/strong&gt; — how fragile is each thing to a given storm? (roof type, construction quality)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loss&lt;/strong&gt; — what's the dollar damage? (and the probability of exceeding any given loss level)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the &lt;strong&gt;catastrophe model&lt;/strong&gt; — the four-layer framework that lets insurers price the unpriceable. The key move is separating &lt;em&gt;how disasters happen&lt;/em&gt; from &lt;em&gt;what they destroy&lt;/em&gt;. Financial crashes are disasters too. So I built the same framework for equity portfolios.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four layers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Layer 1: Hazard — how crashes happen
&lt;/h3&gt;

&lt;p&gt;I built a hazard layer that generates crash scenarios in three ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Six historical crashes&lt;/strong&gt;: 2008 financial crisis, 2020 COVID crash, the 2022 China-ADR meltdown, and three more. Real events, real magnitude, real sector patterns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SDE jump-diffusion models&lt;/strong&gt;: crashes don't creep; they jump. A stochastic differential equation with a jump component captures both the slow drift of normal times and the violent jumps of crisis. I used the &lt;code&gt;yuima&lt;/code&gt; R package to estimate the parameters from real market data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;System dynamics&lt;/strong&gt;: the hidden feedback loop. When leveraged players get margin-called, they're forced to sell. Forced selling drives prices down. Falling prices trigger more margin calls. This loop — not "the news" — is what turns a correction into a crash. I modeled it as an explicit feedback system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Layer 2: Exposure — what you hold
&lt;/h3&gt;

&lt;p&gt;Your portfolio, decomposed: holdings, sectors, market caps. Nothing exotic — but it matters enormously, because the same crash hits a bank stock and a utility stock very differently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 3: Vulnerability — how fragile your portfolio is
&lt;/h3&gt;

&lt;p&gt;This is where the interesting math lives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Downside beta with industry fixed effects&lt;/strong&gt;: not "how volatile is this stock," but "how much does it fall when the market falls, controlling for its industry."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vine copula tail dependence&lt;/strong&gt;: this is the answer to the "correlations converge to 1" problem. A vine copula models the dependency structure between assets explicitly — including the &lt;em&gt;tail&lt;/em&gt; dependency that says "when things get bad, they get bad together." This is the piece that replaces the broken normal-distribution assumption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;XBRL financial fragility&lt;/strong&gt;: I parse SEC filings (XBRL format) and score each company's financial fragility from its actual reported numbers. Leverage, liquidity, debt maturity — the fundamentals that determine whether a company survives a downturn or becomes a forced seller.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentiment calibration&lt;/strong&gt;: because markets are also narratives. NLP on retail-investor comments adjusts model parameters when sentiment gets euphoric (peak risk) or panicked.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Layer 4: Loss — what you lose
&lt;/h3&gt;

&lt;p&gt;Monte Carlo simulation across 10,000+ crash events, producing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Expected Loss&lt;/li&gt;
&lt;li&gt;VaR at 95% and 99%&lt;/li&gt;
&lt;li&gt;CVaR (the average loss &lt;em&gt;in&lt;/em&gt; the tail — the number that actually matters)&lt;/li&gt;
&lt;li&gt;Maximum drawdown&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;Exceedance Probability (EP) curve&lt;/strong&gt;: the probability of losing more than X, for every X. This is the insurance-industry curve, transplanted to portfolios.&lt;/li&gt;
&lt;li&gt;Sector-level loss attribution: &lt;em&gt;which&lt;/em&gt; holdings are doing the damage.&lt;/li&gt;
&lt;li&gt;Position-sizing advice from a risk budget: the more volatile the environment, the smaller the position the model tells you to hold.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the tool taught me
&lt;/h2&gt;

&lt;p&gt;Building this was a running argument with my own assumptions. The V1 → V8 history is basically a list of lessons learned the hard way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;V1&lt;/strong&gt;: The core framework. Monte Carlo + historical crashes + downside beta + VaR/CVaR + EP curve. It worked. It was also naive — a single historical crash is not a distribution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;V4 (system dynamics)&lt;/strong&gt;: The "aha" moment. Adding the leverage feedback loop changed the loss numbers dramatically — because crashes &lt;em&gt;cascade&lt;/em&gt;, and single-shot simulations can't see that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;V5 (vine copula)&lt;/strong&gt;: Replacing the correlation assumption. This is the layer that made the tool honest about crisis behavior. Normal-times models said "you're fine." The vine copula said "you're not."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;V6 (SDE jump-diffusion)&lt;/strong&gt;: Modeling the jumps explicitly. Crashes are not just big moves; they're &lt;em&gt;discontinuous&lt;/em&gt; moves. Different mathematics entirely.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;V7 (XBRL + sentiment)&lt;/strong&gt;: Adding the fundamentals and the narratives. The market is a machine &lt;em&gt;and&lt;/em&gt; a crowd.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;V8&lt;/strong&gt;: The full Streamlit web app — because a model nobody can run is a paper, not a tool.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Three things I'd tell my past self
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Thin-tail models are not "simplifications"; they're lies.&lt;/strong&gt; Use them for convenience, never for crisis planning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cascades are the story.&lt;/strong&gt; The difference between a bad day and a crash is feedback loops. If your model doesn't have them, it's modeling a different event.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tail dependency is the whole game.&lt;/strong&gt; Diversification works in normal times and fails exactly when you need it. Model the dependency structure directly, don't assume it away.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;The tool is open-source, fully documented, and runs locally with one command. There's a web UI, example portfolios, and the full V1→V8 development history in the repo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub: &lt;a href="https://github.com/fengyuGbt/crash_simulator" rel="noopener noreferrer"&gt;github.com/fengyuGbt/crash_simulator&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm now working on AI-driven contract generation and automated risk-analysis agents — tools that &lt;em&gt;write&lt;/em&gt; the models, then &lt;em&gt;verify&lt;/em&gt; them with automated tests, so the quality bar isn't a human staring at a chart.&lt;/p&gt;

&lt;p&gt;If you're building risk tools, quant models, or AI automation for financial data — I'd love to hear what's biting you right now. The comments are open.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built with Python, Streamlit, R (yuima), SDE jump-diffusion, vine copulas, system dynamics, XBRL, and a healthy respect for fat tails.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>webdev</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
