OPEN-SOURCE SCRIPT

Best Buffett Ratio w/ Std-Dev Offset + Conditional Plot

Summary:

This script provides a visually clear way to track the so-called “Buffett Ratio,”
a popular market valuation gauge which compares the total US stock market cap
to the country’s GDP. In addition, it plots a “hardcoded” long-term trend line,
along with fixed standard-deviation bands (in log space), and uses background colors
to signal potentially overvalued or undervalued zones.

快照

What Is the Buffett Ratio?

Often credited to Warren Buffett, the Buffett Ratio (or Buffett Indicator) measures:
(Total US Stock Market Capitalization) / (US GDP)

• A higher ratio typically means equities are more expensive relative to the size of the economy.
• A lower ratio suggests equities may be more attractively valued compared to GDP.

Historically, the ratio has tended to drift upward over many decades,
as the US economy and stock markets grow, but it still oscillates around some trend over time.

How to Use

1) Add to Chart:
- In TradingView, simply apply the indicator (it internally fetches CRSPTM1 & GDP data).

2) Tweak Inputs:
- Log Offset for 1σ: Adjust how wide the ±1σ/±2σ bands appear around the trend.
- Anchor Points: Edit startYear, endYear, startRatio, endRatio
if you want a different slope or different “fair value” anchors.

3) Interpretation:
- If the indicator is above +2σ (red line), it’s historically “very expensive,”
often leading to lower future returns over the long term.
- If it’s below –2σ (green line), it’s historically “deep undervaluation,”
often pointing to better future returns over time.
- The intermediate zones show degrees of mild over- or undervaluation.

How This Script Works

1) Buffett Ratio Calculation:
- The script requests data from TradingView’s built-in CRSPTM1 index (total US market cap).
- It also requests US GDP data via request.economic("US", "GDP").
- If GDP data is missing, the ratio becomes na on that bar.

2) Hardcoded Trend Line:
- Rather than a rolling average, the script uses two “anchors” (e.g. 1950 → 0.30 ratio, 2024 → 1.25 ratio)
and solves for a single log-growth rate to produce a steady upward slope.

3) Fixed Standard Deviations in Log Space:
- The script takes the log of the trend line, then applies a fixed offset for ±1σ and ±2σ,
creating proportional bands that do not “expand/contract” from a rolling window.

4) Conditional Plotting:
- The script only begins plotting once the Buffett Ratio actually has data (around 2011).

5) Color-Coded Zones:
- Above +2σ: red background (historically very expensive)
- Between +1σ and +2σ: yellow background (moderately expensive)
- Between –1σ and +1σ: no background color (around normal)
- Between –2σ and –1σ: aqua background (moderately undervalued)
- Below –2σ: green background (historically deep undervaluation)


Final Notes

Data Limitations: US GDP data and CRSPTM1 only go back so far, so this starts around 2011.
Long-Term vs. Short-Term: Best viewed on monthly/quarterly charts and interpreted over years.
Tuning: If you believe structural changes have shifted the ratio’s fair slope,
adjust the code’s anchors or log offsets.

Enjoy, and use responsibly!
buffetbuffet-indicatorbuffetindicatorbuffetstylebuffettindicatorforecastingstatisticsvalueinvesting

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明