OPEN-SOURCE SCRIPT
CNOOC Oil-Following Study | Extremes + DY Regime + 2-Factor

What It Does
Your indicator is a 2-factor return attribution model with extreme event analysis and dividend yield regime conditioning. It answers one core question: When oil moves — especially violently — does CNOOC follow, and does its dividend yield affect that behavior?
The Architecture
Layer 1 — Rolling 2-Factor Regression
Every week, the model runs a rolling OLS regression: CNOOC return = β₁ × Brent + β₂ × SSE50 + residual. This decomposes CNOOC's performance into three streams: what came from oil, what came from the China market, and what is company-specific alpha. The auto-lag feature tests 0–8 week delays on Brent to find the strongest fit.
Layer 2 — Extreme Oil Detection
It computes a rolling Z-score of Brent returns. Any week where |Z| exceeds your threshold (default 2.0) gets flagged as an extreme oil event, classified as either up-extreme or down-extreme, and highlighted on the chart with green or red backgrounds.
Layer 3 — Conditional Beta Accumulation
This is the study's core innovation. Instead of just one rolling beta, it maintains separate running OLS accumulators for different market conditions: all bars, normal bars, extreme bars, up extremes only, down extremes only. This produces a conditional beta table showing how CNOOC's oil sensitivity changes depending on whether oil is behaving normally or experiencing a tail event.
Layer 4 — Dividend Yield Regime
It estimates CNOOC's trailing dividend yield (annual dividend / price) and classifies each week into High DY, Low DY, or Mid using rolling percentile thresholds. It then cross-tabulates this with the oil regime to produce betas for combinations like High DY + Extreme Oil, Low DY + Oil Down, etc. This tests whether valuation level affects oil sensitivity.
Layer 5 — Cumulative Decomposition
From a fixed start date, it geometrically compounds the oil contribution, index contribution, and residual separately, producing four cumulative return lines that visually show how much of CNOOC's total return came from each source.
Layer 6 — Event Window
Around any anchor date you choose, it accumulates returns within ± N weeks and reports the decomposition for that specific period, plus how many extreme oil bars fell within the window.
Your indicator is a 2-factor return attribution model with extreme event analysis and dividend yield regime conditioning. It answers one core question: When oil moves — especially violently — does CNOOC follow, and does its dividend yield affect that behavior?
The Architecture
Layer 1 — Rolling 2-Factor Regression
Every week, the model runs a rolling OLS regression: CNOOC return = β₁ × Brent + β₂ × SSE50 + residual. This decomposes CNOOC's performance into three streams: what came from oil, what came from the China market, and what is company-specific alpha. The auto-lag feature tests 0–8 week delays on Brent to find the strongest fit.
Layer 2 — Extreme Oil Detection
It computes a rolling Z-score of Brent returns. Any week where |Z| exceeds your threshold (default 2.0) gets flagged as an extreme oil event, classified as either up-extreme or down-extreme, and highlighted on the chart with green or red backgrounds.
Layer 3 — Conditional Beta Accumulation
This is the study's core innovation. Instead of just one rolling beta, it maintains separate running OLS accumulators for different market conditions: all bars, normal bars, extreme bars, up extremes only, down extremes only. This produces a conditional beta table showing how CNOOC's oil sensitivity changes depending on whether oil is behaving normally or experiencing a tail event.
Layer 4 — Dividend Yield Regime
It estimates CNOOC's trailing dividend yield (annual dividend / price) and classifies each week into High DY, Low DY, or Mid using rolling percentile thresholds. It then cross-tabulates this with the oil regime to produce betas for combinations like High DY + Extreme Oil, Low DY + Oil Down, etc. This tests whether valuation level affects oil sensitivity.
Layer 5 — Cumulative Decomposition
From a fixed start date, it geometrically compounds the oil contribution, index contribution, and residual separately, producing four cumulative return lines that visually show how much of CNOOC's total return came from each source.
Layer 6 — Event Window
Around any anchor date you choose, it accumulates returns within ± N weeks and reports the decomposition for that specific period, plus how many extreme oil bars fell within the window.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。