OPEN-SOURCE SCRIPT

Shift Share - Full Diagnostics & R2

230
📄 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.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.