andyst-dev/thermocline

โ˜… 0Forks 0PythonGitHub โ†—Compare

README

๐ŸŒก๏ธ Thermocline / Weather Edge

Weather-market intelligence for Polymarket.

Thermocline scans weather contracts, turns forecasts into calibrated probabilities, simulates execution quality on the CLOB, and observes PolyDekos-style adjacent-bucket ladders before any capital is put at risk.

It is built to answer one practical question:

Is this weather market actually mispriced after forecast uncertainty, liquidity, calibration, and event exposure are accounted for?

The current release is a production observation build: cron-ready, tested, snapshotting live market conditions, but deliberately not live trading.


Current Status

Area Status
Runtime System cron every 30 min from /home/builder/weather-edge
Latest validation PYTHONPATH=src pytest tests/ -q โ†’ 205 passed on 2026-06-01
Trading mode No live trading
Paper opening Tiny observation experiment only: cron may open max 5 SHADOW/PAPER positions at 1 USDC under explicit env flags
Calibration gate Currently blocking true PASS/PAPER readiness; paper/live should stay constrained
Empirical forecast result Poor so far: 31 paper trades, 26 closed, 4 wins / 22 losses, about -20.03 USDC closed PnL as of 2026-06-01
Candidate observation candidate_observations table records SHADOW/PAPER/PASS/REJECT outcomes for future Gamma resolution
PolyDekos ladder Implemented for read-only observation, fill simulation, and reporting
Ladder readiness Not tradable yet: missing historical fill-level replay, realized PnL/ROI/drawdown, and ladder-level calibration

Bottom line: this is an observation/calibration build. The forecast edge is not proven. Keep live trading disabled and keep any paper experiment tiny until calibration and ladder readiness gates are explicitly green and the operator authorizes it.

For a complete project handoff, read docs/weather-forecast-handoff-2026-06-01.md.


Safety Rules

  1. Live trading remains disabled. Paper opening, if enabled, must stay tiny and explicitly bounded by environment flags.

  2. Safest default when in doubt:

    export WEATHER_EDGE_DISABLE_PAPER_OPEN=1
  3. Calibration gate blocks risk-taking when Brier score / bucket calibration are outside thresholds.

  4. Ladder fill simulation is read-only: it calls order-book simulation, writes snapshots, and places no orders.

  5. No secrets belong in the repo or README. Keep credentials in the runtime environment only.

  6. Do not commit runtime artifacts: DBs, logs, reports, snapshots, backups, locks, and generated datasets are ignored.


What the System Does

Thermocline targets weather binary markets such as:

โ€œWill the high in Tokyo be 22ยฐC or higher on May 3?โ€

The pipeline:

  1. discovers Polymarket weather markets;
  2. parses temperature buckets / thresholds;
  3. fetches weather forecasts and context;
  4. computes probabilities with uncertainty;
  5. rejects unsafe or poorly calibrated opportunities;
  6. tracks paper accounting and settlement;
  7. records order-book snapshots and fill simulations;
  8. produces reports for calibration, risk, and ladder readiness.

Architecture

Polymarket Gamma/CLOB
        โ”‚
        โ–ผ
Market discovery + parsing
        โ”‚
        โ–ผ
Forecast/context layer
  - Open-Meteo forecasts
  - ensemble / horizon features
  - Weather.com / METAR settlement sources
  - NASA GISTEMP baseline with cache/fallback for global-temperature markets
        โ”‚
        โ–ผ
Scanner + probability model
  - Gaussian bucket probability
  - uncertainty / horizon / regime adjustments
  - candidate scoring
        โ”‚
        โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ               โ–ผ
Single-bucket       PolyDekos-style ladder observation
candidate flow      - adjacent buckets
                    - deterministic ladder_id
                    - parent_ladder_id per leg
                    - token_id per leg
                    - read-only fill simulation
                    - ladder order-book snapshots
        โ”‚               โ”‚
        โ–ผ               โ–ผ
Risk and gates       Ladder backtest report
  - calibration gate  - qualitative hit-rate only for now
  - event exposure    - no historical fill/PnL yet
  - sizing caps
        โ”‚
        โ–ผ
Reports + paper accounting + settlement audit
        โ”‚
        โ–ผ
Cron heartbeat + DB backup + runtime snapshots

Key Modules

src/weather_edge/
โ”œโ”€โ”€ main.py                    # CLI entry point and paper-cycle orchestration
โ”œโ”€โ”€ scanner.py                 # Market scan and probability computation
โ”œโ”€โ”€ candidates.py              # PASS/PAPER/REJECT scoring
โ”œโ”€โ”€ calibration.py             # Calibration reports/gates
โ”œโ”€โ”€ risk.py                    # Risk sizing logic
โ”œโ”€โ”€ event_exposure.py          # Event-level exposure caps
โ”œโ”€โ”€ uncertainty.py             # Horizon/regime uncertainty adjustments
โ”œโ”€โ”€ weather_features.py        # Forecast/weather feature extraction
โ”œโ”€โ”€ ladder.py                  # PolyDekos-style adjacent-bucket ladders
โ”œโ”€โ”€ ladder_fill.py             # Read-only per-leg fill simulation + snapshots
โ”œโ”€โ”€ ladder_backtest.py         # Qualitative ladder-vs-single report
โ”œโ”€โ”€ closed_trades_audit.py     # Settlement/accounting audit
โ”œโ”€โ”€ research_dataset.py        # Export research dataset artifacts
โ”œโ”€โ”€ settlement.py              # Resolution via weather sources
โ”œโ”€โ”€ db.py                      # SQLite schema and persistence
โ””โ”€โ”€ clients/
    โ”œโ”€โ”€ clob.py                # CLOB order-book / fill simulation helpers
    โ”œโ”€โ”€ polymarket.py          # Market discovery
    โ”œโ”€โ”€ weathercom.py          # Weather.com / Wunderground observations
    โ”œโ”€โ”€ aviationweather.py     # METAR observations
    โ”œโ”€โ”€ openmeteo.py           # Forecast API
    โ””โ”€โ”€ nasa_gistemp.py        # GISTEMP baseline with timeout/cache/fallback

Docs:

docs/weather-forecast-handoff-2026-06-01.md  # Complete forecast handoff / restart guide
docs/polydekos-ladder-roadmap.md             # Ladder strategy roadmap
docs/ladder-paper-readiness-guide.md         # Go/no-go checklist before paper ladder
docs/v1-spec.md                              # Earlier system spec

Runtime artifacts are under data/, reports/, and logs/ and are intentionally ignored by Git.


Common Commands

Install / setup

pip install -e .
PYTHONPATH=src python3 -m weather_edge.main init-db

Run tests

PYTHONPATH=src pytest tests/ -q

Targeted safety/ladder checks:

PYTHONPATH=src pytest \
  tests/test_ladder.py \
  tests/test_ladder_fill.py \
  tests/test_ladder_backtest.py \
  tests/test_nasa_gistemp.py \
  tests/test_scanner_global.py \
  -q

Safe candidate verification

PYTHONPATH=src \
WEATHER_EDGE_DISABLE_PAPER_OPEN=1 \
python3 -m weather_edge.main verify-candidates

Outputs include reports/verified_candidates.json and policy flags such as:

{
  "ladder_fill_simulation_read_only": true,
  "ladder_fill_simulation_places_orders": false
}

Ladder readiness report

PYTHONPATH=src \
WEATHER_EDGE_DISABLE_PAPER_OPEN=1 \
python3 -m weather_edge.main ladder-backtest-report \
  --output /tmp/weather_edge_ladder_backtest_report.json

Current interpretation: useful for qualitative comparison, not sufficient for trading because historical fill-level replay and realized ladder PnL are not available yet.

Full paper cycle wrapper

bash scripts/paper_cycle.sh

Production cron currently runs:

*/30 * * * * builder cd /home/builder/weather-edge && bash scripts/paper_cycle.sh

The wrapper uses a project-local lock:

data/run/weather_edge_paper_cycle.lock

and writes heartbeat state to:

reports/paper_cycle_heartbeat.json

CLI Commands

Current CLI commands include:

init-db
fetch-markets
scan
verify-candidates
paper-open
paper-report
paper-settle
reconcile-sources
resolve-candidate-observations
paper-cycle
run-once
calibration-report
calibration-snapshot
audit-closed-trades
risk-sizing-report
export-research-dataset
ladder-backtest-report
recalibrate-sigma
backtest

paper-open exists for controlled experiments, but should not be used automatically while WEATHER_EDGE_DISABLE_PAPER_OPEN=1 and calibration gates are blocking.


Probability and Risk Model

Single-bucket probabilities use Gaussian bucket integration:

P(bucket) = ฮฆ((upper - ฮผ) / ฯƒ) - ฮฆ((lower - ฮผ) / ฯƒ)

where:

  • ฮผ = forecast temperature estimate;
  • ฯƒ = forecast uncertainty;
  • uncertainty is adjusted by horizon/regime/calibration context.

Risk controls include:

  • calibration gate;
  • event exposure caps;
  • conservative sizing / caps;
  • CLOB fill simulation;
  • rejection of candidates with insufficient liquidity or unstable inputs.

PolyDekos / Adjacent-Bucket Ladder

The ladder path is designed around a range/ladder thesis rather than betting only the exact most likely bucket.

Implemented now:

  • deterministic ladder_id;
  • parent_ladder_id on every leg;
  • token_id propagation for CLOB simulation;
  • adjacent buckets / narrow ranges;
  • read-only per-leg fill simulation via ladder_fill.py;
  • gzip snapshots for ladder books;
  • qualitative report comparing:
    • single_best_bucket,
    • ladder_pm_1c,
    • ladder_pm_2c.

Not ready yet:

  • historical fill-level replay by ladder_id;
  • realized ladder cost / payout / PnL / ROI / max drawdown;
  • ladder-level calibration gate;
  • enough resolved ladder observations to justify paper/live.

Go / No-Go Checklist Before Enabling Paper or Live

Do not enable automatic paper/live openings until all are true:

  • calibration gate allowed;
  • candidate reports show stable non-zero accepted candidates;
  • ladder fill snapshots have accumulated across many cycles;
  • historical ladder replay works by event_key + ladder_id;
  • ladder settlement maps each leg to realized outcomes;
  • PnL / ROI / drawdown are computed from real historical snapshots;
  • ladder-level calibration metrics are acceptable;
  • cron heartbeat remains stable;
  • explicit operator approval is given.

Git Hygiene

Useful code/docs/tests should be committed intentionally. Generated runtime artifacts should not.

Ignored by design:

  • data/backups/
  • data/cache/
  • data/run/
  • data/snapshots/
  • data/*.db*
  • data/research_dataset*.jsonl
  • data/sigma_calibration.json
  • reports/* except placeholders
  • logs/* except placeholders
  • .hermes/

Before any commit:

git status --short
PYTHONPATH=src pytest tests/ -q

Commit/push only after explicit operator approval.


Disclaimer

This is a research and observation system for prediction-market strategy development. It is not financial advice. Live trading should remain disabled until the system has proven calibration, execution quality, and risk behavior on resolved historical observations.

Contributors

andyst-dev

Issues