OPEN-SOURCE SCRIPT
Shift Share - Full Diagnostics & R2

📄 Shift Share: Full Diagnostics & R²
Indicator Purpose:
To perform a "Multivariate Regression" on a stock's returns to see what is driving the price.
█ THE FOUR PERFORMANCE COMPONENTS
The indicator breaks down every price movement into four distinct buckets:
* Market (Beta): Returns driven by the broad market (e.g., SPY).
* Sector (Beta): Returns driven by your specific industry (e.g., XLF for Banks).
* Interaction: Returns caused by the market and sector moving in tandem (synergy).
* Unique (Idiosyncratic): Returns purely specific to the company (news, earnings, management).
█ CORE LOGIC & MATH
The script uses Log Returns and a Rolling Window (default 60 days) to calculate:
* Rolling Beta: It calculates how sensitive the stock is to the Market, Sector, and Interaction over time. This isn't a static number; it adapts as the stock's relationship with the market changes.
* T-Stats: This is a statistical "truth detector." It checks if the relationship is mathematically significant or just "noise."
* R-Squared ($R^2$): A measure of "Model Confidence." An $R^2$ of 0.80 means 80% of the stock's movement is explained by the Market and Sector, while 20% is random or unique.
█ HOW TO INTERPRET THE OUTCOME
1. The Cumulative Lines (The Visual Chart)
* Total (White): The actual price performance of the stock.
* Unique (Red): This is the most important line for stock pickers. If the red line is trending up, the company is outperforming its peers regardless of the economy. If it's trending down, the company is "bleeding" value despite what the market is doing.
* Market/Sector (Blue/Orange): If these are the primary movers, the stock is a "Beta play"—it’s just a passenger on the macro boat.
2. The Diagnostics Table (The Data)
* Share %: Tells you what percentage of the total return was contributed by that specific source.
* [SIG] vs [n.s.]: * [SIG]: Statistically Significant. You can trust that this factor (e.g., the Sector) is actually driving the price.
* [n.s.]: Not Significant. The relationship is weak; the price moves are likely random noise.
* Model Confidence ($R^2$): If this is low (e.g., < 30%), the "Unique" component is high, meaning the stock is "decoupled" from the market and doing its own thing.
█ LIMITATIONS
* Lookback Bias: Because it uses a rolling window (60 bars), it may take time to "notice" a sudden change in a stock's behavior.
* ETF Choice: The accuracy depends entirely on choosing the correct Sector ETF in the settings. If you use a Tech ETF (XLK) for a Bank stock, the data will be meaningless.
Indicator Purpose:
To perform a "Multivariate Regression" on a stock's returns to see what is driving the price.
█ THE FOUR PERFORMANCE COMPONENTS
The indicator breaks down every price movement into four distinct buckets:
* Market (Beta): Returns driven by the broad market (e.g., SPY).
* Sector (Beta): Returns driven by your specific industry (e.g., XLF for Banks).
* Interaction: Returns caused by the market and sector moving in tandem (synergy).
* Unique (Idiosyncratic): Returns purely specific to the company (news, earnings, management).
█ CORE LOGIC & MATH
The script uses Log Returns and a Rolling Window (default 60 days) to calculate:
* Rolling Beta: It calculates how sensitive the stock is to the Market, Sector, and Interaction over time. This isn't a static number; it adapts as the stock's relationship with the market changes.
* T-Stats: This is a statistical "truth detector." It checks if the relationship is mathematically significant or just "noise."
* R-Squared ($R^2$): A measure of "Model Confidence." An $R^2$ of 0.80 means 80% of the stock's movement is explained by the Market and Sector, while 20% is random or unique.
█ HOW TO INTERPRET THE OUTCOME
1. The Cumulative Lines (The Visual Chart)
* Total (White): The actual price performance of the stock.
* Unique (Red): This is the most important line for stock pickers. If the red line is trending up, the company is outperforming its peers regardless of the economy. If it's trending down, the company is "bleeding" value despite what the market is doing.
* Market/Sector (Blue/Orange): If these are the primary movers, the stock is a "Beta play"—it’s just a passenger on the macro boat.
2. The Diagnostics Table (The Data)
* Share %: Tells you what percentage of the total return was contributed by that specific source.
* [SIG] vs [n.s.]: * [SIG]: Statistically Significant. You can trust that this factor (e.g., the Sector) is actually driving the price.
* [n.s.]: Not Significant. The relationship is weak; the price moves are likely random noise.
* Model Confidence ($R^2$): If this is low (e.g., < 30%), the "Unique" component is high, meaning the stock is "decoupled" from the market and doing its own thing.
█ LIMITATIONS
* Lookback Bias: Because it uses a rolling window (60 bars), it may take time to "notice" a sudden change in a stock's behavior.
* ETF Choice: The accuracy depends entirely on choosing the correct Sector ETF in the settings. If you use a Tech ETF (XLK) for a Bank stock, the data will be meaningless.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.