DEV Community

Cover image for My Investment Bot's Sell Rule Was Broken: How I Added SEC EDGAR Filings to Catch 'Pre-Bankruptcy' Signals Sooner
oji - building AI in public
oji - building AI in public

Posted on

My Investment Bot's Sell Rule Was Broken: How I Added SEC EDGAR Filings to Catch 'Pre-Bankruptcy' Signals Sooner

Hey dev.to! Grandpa here. I'm a 38-year-old tinkering with AI agents and automated trading bots on weeknights and weekends.

Today, I'm sharing a critical design flaw I found in my custom U.S. stock investment bot and how I fixed it. Specifically, my sell rule had a massive hole that could have let a stock plummet to near-bankruptcy before the bot took any action. Pretty scary stuff.

What Was Going On?

My bot's sell logic was incredibly simple. Essentially, if a company missed earnings (EPS, revenue) consensus several times in a row, or if its growth rate significantly decelerated, the bot would sell. It was triggered by deteriorating fundamentals.

On the surface, this seems reasonable. But the fragility of this logic became painfully clear when one of my monitored stocks took a sudden nosedive. The stock price started falling, and only much later did the news break that "terrible quarterly results" had come out.

If I had owned that stock, my bot would have done nothing until the earnings report, just watching my capital evaporate. In hindsight, there were clear "pre-signals" long before the actual earnings deterioration: a CEO suddenly resigning, or an announcement of a capital raise that would significantly dilute shareholder value.

As humans, we'd pick up on these signals: "Hmm, something's off with this company." But a bot only acts on programmed rules. And my rules were solely based on "earnings"—a lagging indicator that only appears after the event. This was a brutal design flaw.

The Root Cause: Relying Only on Lagging Indicators

The core of the problem was that I only considered "deteriorating business performance" as a single layer for my sell rules.

I believe there are two main types of events that can destroy a company's value:

  1. Deteriorating Business Performance (Tier A): Sales or profits don't meet targets. This is a result, which appears in numbers with a delay.
  2. Capital/Governance Collapse (Tier B): Management leaves, fundraising that shakes the financial foundation, or delisting risk emerges. These are "anomalies" and can be leading indicators, often occurring before business performance shows up.

My bot was only looking at Tier A. So, any Tier B event was completely ignored. It could only react defensively, realizing "something happened?" only after the stock price moved. This defeats the purpose of automated trading.

The Fix: Monitoring Specific EDGAR Forms

To address this, I decided to add a mechanism to mechanically detect these Tier B events.

For U.S. stocks, companies are required to submit documents to the SEC (U.S. Securities and Exchange Commission) via the EDGAR system when significant events occur. Specifically, the "Form 8-K," an unscheduled material event report, describes major corporate changes in near real-time.

However, reading through the massive volume of daily disclosures is impossible. So, I decided to monitor only specific Items within these forms that signal particularly critical events.

Here's how I defined these rules in a Python dictionary:

# Tier B: Capital & Governance related sell triggers
RULES_TIER_B = {
    # Sudden departure of management is a significant risk
    'C-4': {
        'trigger_doc': '8-K Item 5.02',
        'event': 'Departure of Directors or Certain Officers (e.g., CEO, CFO)',
        'action': 'FLAG_FOR_REVIEW'
    },
    # Capital raises that can significantly dilute existing shareholder value
    'C-2': {
        'trigger_doc': '8-K Item 3.02',
        'event': 'Unregistered Sales of Equity Securities',
        'action': 'FLAG_FOR_REVIEW'
    },
    # Delisting notice. This requires immediate attention.
    'C-6': {
        'trigger_doc': '8-K Item 3.01',
        'event': 'Notice of Delisting or Failure to Satisfy a Continued Listing Rule or Standard',
        'action': 'FLAG_FOR_REVIEW'
    }
}
Enter fullscreen mode Exit fullscreen mode

I integrated these rules into my monitoring bot. Now, if any of my holdings or watchlist stocks file these specific forms, I get an immediate notification.

One crucial point here is that I didn't set 'action' to SELL_IMMEDIATELY. I kept it as FLAG_FOR_REVIEW.

Why? Because a CEO's resignation, for example, could be a positive generational change rather than a scandal. Making the rules too rigid can lead to missed opportunities. When a trigger fires, I leave room for human judgment to assess the final context. This intermediary step is quite important for operating a personal bot.

Learnings and Next Steps

The lessons from this failure were significant:

  1. Design Sell Rules in Layers: If you don't monitor across different layers—like "performance (lagging)" and "governance (leading)"—you'll be caught off guard.
  2. Codify Human Intuition: The key is how to translate an investor's gut feeling, like "a CEO resignation is bad," into objective triggers (specific disclosure documents) that a bot can interpret.
  3. Position Sizing Discipline is the Strongest Defense: Ultimately, no matter how refined your rules, unknown risks always exist. That's why enforcing position sizing discipline—not concentrating assets in a single stock—is the best damage control, enforced by the system itself.

Moving forward, my next challenge is to incorporate even harder-to-detect risks into the rules, like warrant liabilities hidden in financial statement footnotes (which are also time bombs for shareholder value).

Personal development is a continuous cycle of trial and error. But because I'm operating with my own money, each failure becomes a valuable lesson. If I mess up again, I'll be sure to log it.

Until next time,
Grandpa

Top comments (0)