Fix MIS Earnings Penalty Bug
Codified from Gmail draft
19dc11344cb608b1· Apr 24 2026
Honest answer first
Open in CONTEXT.md as "Fix earnings penalty bug."
60–90 min depending on how cleanly the bug localizes.
Most likely culprit: edge case at market close on earnings day, or sign error in penalty application.
Step 1 — Reproduce the bug (15 min)
- Open MIS v7.1 sheet
- Find a recent earnings event where penalty applied incorrectly
- Document:
- Ticker
- Earnings date + time (BMO/AMC)
- What the penalty SHOULD be (per rules)
- What the penalty ACTUALLY was
- Delta in $ or % - Save screenshot to
/audits/2026-04_mis-earnings-bug/
Step 2 — Find the logic (15 min)
Three places to check:
A) MIS sheet itself
- Find the named range for earnings adjuster
- Likely tab: Earnings_Adjuster or Adjustments
- Trace formula path
B) Apps Script
- Extensions → Apps Script
- Search for: earnings, penalty, EPS, adjustment
- Note any function names
C) Repo history
cd MIS
git log --oneline | grep -iE "(earnings|penalty|adjust)"
Find when this logic was last touched. Read commit messages for context.
Step 3 — Hypothesis check (most likely culprits, in probability order)
-
DATE COMPARISON edge case
- Earnings released after market close vs before next open
- Timezone handling (UTC vs ET)
- Test: simulate earnings at 4:00:01 PM ET — does it count as today or tomorrow? -
SIGN ERROR
- Penalty being added when should be subtracted (or vice versa)
- Test: stock that beat earnings — is penalty positive or zero? -
MAGNITUDE / UNITS
- % vs basis points mix-up (100x error)
- Decimal vs whole number (e.g., 0.05 vs 5) -
LOOKUP RETURNING WRONG ROW
- Earnings calendar source returning wrong ticker
- Date join failing silently -
THRESHOLD BOUNDARY
->=vs>comparison errors at exact threshold values
Step 4 — Debug in Apps Script (20 min)
- Open the offending function
- Add
console.log()at every decision point:
- Inputs received
- Lookup results
- Conditional branches taken
- Final value before return - Run with the test case from Step 1
- View → Logs (or Executions in newer UI)
- Trace where reality diverges from expected
Step 5 — Apply fix (10 min)
Make minimum-necessary code change. Add comment explaining the bug + fix:
// BUGFIX 2026-04-XX: handle earnings released after 4:00 PM ET
// Previous logic compared dates only, missing intra-day boundary
Step 6 — Regression test (15 min)
Test against 3 historical earnings events with known correct outputs:
- One BMO earnings (released before open)
- One AMC earnings (released after close)
- One that previously triggered the bug
All three should now produce correct penalty values.
Step 7 — Commit + deploy (10 min)
cd MIS
git add .
git commit -m "Fix earnings penalty bug — handle intra-day boundary correctly
- Issue: penalty mis-applied for earnings released within market hours
- Root cause: [whatever you found]
- Fix: [what you changed]
- Tested against: AAPL Q1, MSFT Q4, NVDA Q3"
git push
Verify next morning's MIS Morning Brief runs clean.
Step 8 — Update CONTEXT.md
Remove "Fix earnings penalty bug" from Project Status table.
Or move to "Recently Closed" if you track that.
Done state
Bug fixed. Regression test in place. MIS runs clean for next 5 trading days. CONTEXT.md updated.