trump-code-market-signals
AI-powered analysis of Trump's social media posts to predict stock market movements using 31.5M brute-force tested rules
What this skill does
# Trump Code — Market Signal Analysis
> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.
Trump Code is an open-source system that applies brute-force computation to find statistically significant patterns between Trump's Truth Social/X posting behavior and S&P 500 movements. It has tested 31.5M model combinations, maintains 551 surviving rules, and has a verified 61.3% hit rate across 566 predictions (z=5.39, p<0.05).
## Installation
```bash
git clone https://github.com/sstklen/trump-code.git
cd trump-code
pip install -r requirements.txt
```
### Environment Variables
```bash
# Required for AI briefing and chatbot
export GEMINI_KEYS="key1,key2,key3" # Comma-separated Gemini API keys
# Optional: for Claude Opus deep analysis
export ANTHROPIC_API_KEY="your-key-here"
# Optional: for Polymarket/Kalshi integration
export POLYMARKET_API_KEY="your-key-here"
```
## CLI — Key Commands
```bash
# Today's detected signals from Trump's posts
python3 trump_code_cli.py signals
# Model performance leaderboard (all 11 named models)
python3 trump_code_cli.py models
# Get LONG/SHORT consensus prediction
python3 trump_code_cli.py predict
# Prediction market arbitrage opportunities
python3 trump_code_cli.py arbitrage
# System health check (circuit breaker state)
python3 trump_code_cli.py health
# Full daily report (trilingual)
python3 trump_code_cli.py report
# Dump all data as JSON
python3 trump_code_cli.py json
```
## Core Scripts
```bash
# Real-time Trump post monitor (polls every 5 min)
python3 realtime_loop.py
# Brute-force model search (~25 min, tests millions of combos)
python3 overnight_search.py
# Individual analyses
python3 analysis_06_market.py # Posts vs S&P 500 correlation
python3 analysis_09_combo_score.py # Multi-signal combo scoring
# Web dashboard + AI chatbot on port 8888
export GEMINI_KEYS="key1,key2,key3"
python3 chatbot_server.py
# → http://localhost:8888
```
## REST API (Live at trumpcode.washinmura.jp)
```python
import requests
BASE = "https://trumpcode.washinmura.jp"
# All dashboard data in one call
data = requests.get(f"{BASE}/api/dashboard").json()
# Today's signals + 7-day history
signals = requests.get(f"{BASE}/api/signals").json()
# Model performance rankings
models = requests.get(f"{BASE}/api/models").json()
# Latest 20 Trump posts with signal tags
posts = requests.get(f"{BASE}/api/recent-posts").json()
# Live Polymarket Trump prediction markets (316+)
markets = requests.get(f"{BASE}/api/polymarket-trump").json()
# LONG/SHORT playbooks
playbook = requests.get(f"{BASE}/api/playbook").json()
# System health / circuit breaker state
status = requests.get(f"{BASE}/api/status").json()
```
### AI Chatbot API
```python
import requests
response = requests.post(
"https://trumpcode.washinmura.jp/api/chat",
json={"message": "What signals fired today and what's the consensus?"}
)
print(response.json()["reply"])
```
## MCP Server (Claude Code / Cursor Integration)
Add to `~/.claude/settings.json`:
```json
{
"mcpServers": {
"trump-code": {
"command": "python3",
"args": ["/path/to/trump-code/mcp_server.py"]
}
}
}
```
Available MCP tools: `signals`, `models`, `predict`, `arbitrage`, `health`, `events`, `dual_platform`, `crowd`, `full_report`
## Open Data Files
All data lives in `data/` and is updated daily:
```python
import json, pathlib
DATA = pathlib.Path("data")
# 44,000+ Truth Social posts
posts = json.loads((DATA / "trump_posts_all.json").read_text())
# Posts with signals pre-tagged
posts_lite = json.loads((DATA / "trump_posts_lite.json").read_text())
# 566 verified predictions with outcomes
predictions = json.loads((DATA / "predictions_log.json").read_text())
# 551 active rules (brute-force + evolved)
rules = json.loads((DATA / "surviving_rules.json").read_text())
# 384 features × 414 trading days
features = json.loads((DATA / "daily_features.json").read_text())
# S&P 500 OHLC history
market = json.loads((DATA / "market_SP500.json").read_text())
# Circuit breaker / system health
cb = json.loads((DATA / "circuit_breaker_state.json").read_text())
# Rule evolution log (crossover/mutation)
evo = json.loads((DATA / "evolution_log.json").read_text())
```
## Download Data via API
```python
import requests
BASE = "https://trumpcode.washinmura.jp"
# List available datasets
catalog = requests.get(f"{BASE}/api/data").json()
# Download a specific file
raw = requests.get(f"{BASE}/api/data/surviving_rules.json").content
rules = json.loads(raw)
```
## Real Code Examples
### Parse Today's Signals
```python
import requests
signals_data = requests.get("https://trumpcode.washinmura.jp/api/signals").json()
today = signals_data.get("today", {})
print("Signals fired today:", today.get("signals", []))
print("Consensus:", today.get("consensus")) # "LONG" / "SHORT" / "NEUTRAL"
print("Confidence:", today.get("confidence")) # 0.0–1.0
print("Active models:", today.get("active_models", []))
```
### Find Top Performing Rules from Surviving Rules
```python
import json
rules = json.loads(open("data/surviving_rules.json").read())
# Sort by hit rate descending
top_rules = sorted(rules, key=lambda r: r.get("hit_rate", 0), reverse=True)
for rule in top_rules[:10]:
print(f"Rule: {rule['id']} | Hit Rate: {rule['hit_rate']:.1%} | "
f"Trades: {rule['n_trades']} | Avg Return: {rule['avg_return']:.3%}")
```
### Check Prediction Market Opportunities
```python
import requests
arb = requests.get("https://trumpcode.washinmura.jp/api/insights").json()
markets = requests.get("https://trumpcode.washinmura.jp/api/polymarket-trump").json()
# Markets sorted by volume
active = [m for m in markets.get("markets", []) if m.get("active")]
by_volume = sorted(active, key=lambda m: m.get("volume", 0), reverse=True)
for m in by_volume[:5]:
print(f"{m['title']}: YES={m['yes_price']:.0%} | Vol=${m['volume']:,.0f}")
```
### Correlate Post Features with Returns
```python
import json
import numpy as np
features = json.loads(open("data/daily_features.json").read())
market = json.loads(open("data/market_SP500.json").read())
# Build date-indexed return map
returns = {d["date"]: d["close_pct"] for d in market}
# Example: correlate post_count with next-day return
xs, ys = [], []
for day in features:
date = day["date"]
if date in returns:
xs.append(day.get("post_count", 0))
ys.append(returns[date])
correlation = np.corrcoef(xs, ys)[0, 1]
print(f"Post count vs same-day return: r={correlation:.3f}")
```
### Run a Backtest on a Custom Signal
```python
import json
posts = json.loads(open("data/trump_posts_lite.json").read())
market = json.loads(open("data/market_SP500.json").read())
returns = {d["date"]: d["close_pct"] for d in market}
# Find days with RELIEF signal before 9:30 AM ET
relief_days = [
p["date"] for p in posts
if "RELIEF" in p.get("signals", []) and p.get("hour", 24) < 9
]
hits = [returns[d] for d in relief_days if d in returns]
if hits:
print(f"RELIEF pre-market: n={len(hits)}, "
f"avg={sum(hits)/len(hits):.3%}, "
f"hit_rate={sum(1 for h in hits if h > 0)/len(hits):.1%}")
```
## Key Signal Types
| Signal | Description | Typical Impact |
|--------|-------------|----------------|
| `RELIEF` pre-market | "Relief" language before 9:30 AM | Avg +1.12% same-day |
| `TARIFF` market hours | Tariff mention during trading | Avg -0.758% next day |
| `DEAL` | Deal/agreement language | 52.2% hit rate |
| `CHINA` (Truth Social only) | China mentions (never on X) | 1.5× weight boost |
| `SILENCE` | Zero-post day | 80% bullish, avg +0.409% |
| Burst → silence | Rapid posting then goes quiet | 65.3% LONG signal |
## Model Reference
| Model | Strategy | Hit Rate | Avg Return |
|-------|----------|----------|------------|
| A3 | Pre-market RELIEF → surge | 72.7% | +1.206% |
| D3 | Volume spike → panic bottom | 70.2% | +0.306% |
| D2 | Signature switch → formal statement | 70.0% | +0.472% |Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.