{"slug":"us-stock-margin-for-taiwan-investors","qid":"drawdown_lines","label":"drawdown_lines","post_title":"us-stock-margin-for-taiwan-investors","post_url":"/blog/lang/zh-hant/us-stock-margin-for-taiwan-investors#q-drawdown_lines","columns":["threshold_label","episode_count","below_count","sample_from","sample_to"],"rows":[{"threshold_label":"-10%","episode_count":108,"below_count":2755,"sample_from":"2003-09-10","sample_to":"2026-10-08"},{"threshold_label":"-20%","episode_count":41,"below_count":1480,"sample_from":"2003-09-10","sample_to":"2026-10-08"},{"threshold_label":"-25%","episode_count":47,"below_count":1008,"sample_from":"2003-09-10","sample_to":"2026-10-08"},{"threshold_label":"-33%","episode_count":25,"below_count":343,"sample_from":"2003-09-10","sample_to":"2026-10-08"},{"threshold_label":"-40%","episode_count":4,"below_count":152,"sample_from":"2003-09-10","sample_to":"2026-10-08"},{"threshold_label":"-50%","episode_count":5,"below_count":42,"sample_from":"2003-09-10","sample_to":"2026-10-08"}],"shape":"table","sql":"WITH\n    daily AS\n    (\n        SELECT\n            date                  AS d,\n            toFloat64(max(close)) AS px\n        FROM global_markets.stocks_daily_aggs\n        WHERE ticker = 'MSFT'\n          AND date >= '2003-03-01'\n        GROUP BY d\n    ),\n    pathed AS\n    (\n        SELECT\n            d,\n            round((px / max(px) OVER (ORDER BY d ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) - 1) * 100, 2) AS dd_pct\n        FROM daily\n    ),\n    stepped AS\n    (\n        SELECT\n            d,\n            dd_pct,\n            lagInFrame(dd_pct) OVER (ORDER BY d ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS prev_dd_pct\n        FROM pathed\n    ),\n    grid AS\n    (\n        SELECT arrayJoin([10., 20., 25., 33., 40., 50.]) AS threshold\n    )\nSELECT\n    concat('-', toString(toUInt8(g.threshold)), '%')                       AS threshold_label,\n    countIf(s.dd_pct <= -g.threshold AND s.prev_dd_pct > -g.threshold)     AS episode_count,\n    countIf(s.dd_pct <= -g.threshold)                                      AS below_count,\n    toString(min(s.d))                                                     AS sample_from,\n    toString(max(s.d))                                                     AS sample_to\nFROM stepped AS s\nCROSS JOIN grid AS g\nGROUP BY g.threshold\nORDER BY g.threshold","computed_at":"2026-10-08T15:57:02.174861+00:00","elapsed":0.187543726}