{"slug":"iron-condor-screener-from-the-free-sql-api","qid":"persistence","label":"persistence","post_title":"iron-condor-screener-from-the-free-sql-api","post_url":"/blog/iron-condor-screener-from-the-free-sql-api#q-persistence","columns":["week","week_of","candidates","still_clearing","survival_pct"],"rows":[{"week":"2026-07-06","week_of":"Jul 6","candidates":15,"still_clearing":0,"survival_pct":0},{"week":"2026-07-13","week_of":"Jul 13","candidates":32,"still_clearing":0,"survival_pct":0},{"week":"2026-07-20","week_of":"Jul 20","candidates":22,"still_clearing":2,"survival_pct":9},{"week":"2026-07-27","week_of":"Jul 27","candidates":24,"still_clearing":0,"survival_pct":0},{"week":"2026-08-03","week_of":"Aug 3","candidates":14,"still_clearing":2,"survival_pct":14},{"week":"2026-08-10","week_of":"Aug 10","candidates":14,"still_clearing":0,"survival_pct":0},{"week":"2026-08-17","week_of":"Aug 17","candidates":22,"still_clearing":6,"survival_pct":27},{"week":"2026-08-24","week_of":"Aug 24","candidates":19,"still_clearing":4,"survival_pct":21},{"week":"2026-08-31","week_of":"Aug 31","candidates":16,"still_clearing":0,"survival_pct":0},{"week":"2026-09-07","week_of":"Sep 7","candidates":22,"still_clearing":3,"survival_pct":14},{"week":"2026-09-14","week_of":"Sep 14","candidates":17,"still_clearing":9,"survival_pct":53}],"shape":"series","sql":"WITH\n    weeks AS\n    (\n        SELECT toMonday(date) AS wk, max(date) AS session\n        FROM global_markets.options_greeks\n        WHERE underlying_symbol = 'SPY'\n          AND date >= today() - 84\n        GROUP BY wk\n    ),\n    legs AS\n    (\n        SELECT\n            toMonday(g.date)                          AS wk,\n            g.expiration_date                         AS expiration_date,\n            toFloat64(g.strike_price)                 AS k,\n            if(toFloat64(g.delta) < 0, 'put', 'call') AS side,\n            max(g.days_to_expiry)                     AS dte,\n            avg(toFloat64(g.option_close))            AS px,\n            avg(toFloat64(g.delta))                   AS d\n        FROM global_markets.options_greeks AS g\n        INNER JOIN weeks AS w ON g.date = w.session\n        WHERE g.underlying_symbol = 'SPY'\n          AND g.date >= today() - 84\n          AND g.iv_converged = 1\n          AND g.volume > 0\n          AND toFloat64(g.option_close) > 0\n          AND toUInt32(round(toFloat64(g.strike_price) * 100)) % 500 = 0\n        GROUP BY wk, expiration_date, k, side\n    ),\n    verticals AS\n    (\n        SELECT\n            s.wk              AS wk,\n            s.wk + 7          AS next_wk,\n            s.expiration_date AS expiration_date,\n            s.side            AS side,\n            s.k               AS short_k,\n            s.dte             AS dte,\n            s.px - l.px       AS credit\n        FROM legs AS s\n        INNER JOIN legs AS l\n            ON s.wk = l.wk AND s.expiration_date = l.expiration_date AND s.side = l.side\n        WHERE ((s.side = 'put'  AND s.d BETWEEN -0.20 AND -0.12 AND abs(l.k - (s.k - 5)) < 0.01)\n            OR (s.side = 'call' AND s.d BETWEEN  0.12 AND  0.20 AND abs(l.k - (s.k + 5)) < 0.01))\n    ),\n    condors AS\n    (\n        SELECT\n            p.wk                                                                AS wk,\n            p.next_wk                                                           AS next_wk,\n            p.expiration_date                                                   AS expiration_date,\n            p.short_k                                                           AS short_put,\n            c.short_k                                                           AS short_call,\n            p.dte                                                               AS dte,\n            round(100 * (p.credit + c.credit) / (5 - (p.credit + c.credit)), 1) AS credit_pct\n        FROM verticals AS p\n        INNER JOIN verticals AS c\n            ON p.wk = c.wk AND p.expiration_date = c.expiration_date\n        WHERE p.side = 'put'\n          AND c.side = 'call'\n          AND p.credit + c.credit BETWEEN 0.05 AND 4.0\n    )\nSELECT\n    toString(a.wk)                                        AS week,\n    formatDateTime(a.wk, '%b %e')                         AS week_of,\n    count()                                               AS candidates,\n    countIf(b.credit_pct >= 20)                           AS still_clearing,\n    round(100 * countIf(b.credit_pct >= 20) / count(), 0) AS survival_pct\nFROM condors AS a\nLEFT JOIN condors AS b\n    ON a.next_wk = b.wk\n   AND a.expiration_date = b.expiration_date\n   AND a.short_put = b.short_put\n   AND a.short_call = b.short_call\nWHERE a.dte BETWEEN 25 AND 45\n  AND a.credit_pct >= 20\n  AND a.next_wk <= toMonday((\n        SELECT max(date)\n        FROM global_markets.options_greeks\n        WHERE underlying_symbol = 'SPY'\n      ))\nGROUP BY a.wk\nORDER BY a.wk","computed_at":"2026-09-28T15:36:15.278973+00:00","elapsed":158.236500492}