Skip to content

Atomic writes, improved sentiment, dynamic calendar, 10Y yield#117

Open
mikejamescalvert wants to merge 2 commits intomainfrom
fix/qa-final-batch
Open

Atomic writes, improved sentiment, dynamic calendar, 10Y yield#117
mikejamescalvert wants to merge 2 commits intomainfrom
fix/qa-final-batch

Conversation

@mikejamescalvert
Copy link
Copy Markdown
Owner

Summary

Final batch from the comprehensive QA audit. Addresses infrastructure, data quality, and forward-compatibility issues.

Atomic JSON Writes

  • New atomic_write() utility in utils/io.py — writes to .tmp file then uses os.replace() for atomic swap
  • Applied to all 3 persistence files: thesis store, equity tracker, trade journal
  • Prevents JSON corruption when two agents (trading + review) write concurrently or process crashes mid-write

News Sentiment Improvements

  • Expanded word lists: 7 → 27 words per polarity. Added verb forms (surges, crashes), common financial terms (rally, plunge, layoffs, outperform, bullish/bearish)
  • Negation handling: "Stock does NOT surge" now correctly scores negative. Tracks negation state word-by-word and flips polarity of the next sentiment word.

Dynamic Economic Calendar

  • Replaced hardcoded 2026 calendar with dynamic date calculation:
    • Jobs Report: first Friday of current month
    • CPI Release: ~12th of month
    • FOMC: generic reminder (schedule varies)
  • Works across years without manual updates (old code would silently return empty events in 2027+)

10-Year Treasury Yield

  • Was always None despite field existing in MacroContext model
  • Now fetched from Yahoo Finance (^TNX) alongside VIX and SPY
  • Gives the AI critical context for rate-sensitive trades (financials, REITs, growth vs value rotation)

Files Changed (6)

File Change
utils/io.py New atomic write utility
persistence/thesis_store.py Use atomic writes
persistence/equity_tracker.py Use atomic writes
performance/benchmarking.py Use atomic writes
data/news.py Expanded sentiment + negation
data/macro.py Dynamic calendar + 10Y yield

Test plan

  • All 270 tests pass
  • Ruff lint clean
  • mypy strict clean (39 source files)
  • Verify 10Y yield appears in trading agent macro context logs
  • Verify sentiment scores change for negated headlines
  • Verify atomic writes produce valid JSON after concurrent agent runs

🤖 Generated with Claude Code

mikejamescalvert and others added 2 commits March 27, 2026 08:05
Infrastructure:
- Add atomic_write() utility (temp file + os.replace) to prevent
  JSON corruption from concurrent agent writes or crashes
- Apply atomic writes to all 3 persistence files: thesis store,
  equity tracker, and trade journal

News sentiment:
- Expand word lists from 7 to 27 words per polarity (covers verb
  forms, common financial terms like rally/plunge/layoffs)
- Add negation handling: "not surge" now scores negative instead
  of positive. Tracks negation state across words.

Macro data:
- Replace hardcoded 2026 economic calendar with dynamic date
  calculation (first Friday = Jobs Report, ~12th = CPI). Works
  across years without manual updates.
- Fetch 10-year Treasury yield from Yahoo Finance (^TNX). Was
  always None despite field existing in model. Critical for
  rate-sensitive trade decisions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant