本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Growth / Inflation Quadrant", shorttitle = "G/I Quadrant", precision = 2)
// =====================================================================
// 05 | GROWTH / INFLATION QUADRANT
// Source: Ch. 12 (Fig 12.2, based on Ilmanen-Maloney-Ross 2014).
// Equities did best with growth up / inflation down and worst in
// stagflation. Government bonds did best with growth down /
// inflation down. Commodities had precisely the opposite pattern
// to bonds.
//
// WHAT IT MEASURES
// The book uses macro surprise data. This is a market-based proxy:
// Growth = 3-month change in the copper/gold ratio (cyclical vs safe metal).
// Inflation = 3-month change in 10y breakeven inflation (FRED T10YIE).
//
// HOW TO READ IT (column colour / background)
// Green 1 = GOLDILOCKS growth up, inflation down -> equities best
// Orange 2 = REFLATION growth up, inflation up -> commodities, value, cyclicals
// Red 3 = STAGFLATION growth down, inflation up -> worst for stocks AND bonds
// Blue 4 = DEFLATION / SLOWDOWN growth down, inflation down -> bonds best
// The columns show the two raw proxies, so you can see how strong each
// side is: positive bar = rising. The table names the current regime.
//
// CAVEATS
// Market proxies flip faster than real macro data. Use the "Persistence"
// input to demand the regime holds for N bars before it shows.
// Breakeven data starts 2003. Daily chart.
// =====================================================================
cuSym = input.symbol("COMEX:HG1!", "Copper")
auSym = input.symbol("COMEX:GC1!", "Gold")
beSym = input.symbol("FRED:T10YIE", "10y breakeven inflation")
len = input.int(63, "Change window (bars, 63 ~ 3m)", minval = 5)
persist = input.int(5, "Persistence (bars)", minval = 1)
cu = request.security(cuSym, "D", close)
au = request.security(auSym, "D", close)
ratio = cu / au
be = request.security(beSym, "D", close)
growthChg = (ratio / ratio[len] - 1.0) * 100 // % change
inflChg = (be - be[len]) * 100 // basis points
rawRegime = growthChg > 0 and inflChg <= 0 ? 1 : growthChg > 0 and inflChg > 0 ? 2 : growthChg <= 0 and inflChg > 0 ? 3 : 4
var int regime = 4
stable = ta.lowest(rawRegime, persist) == ta.highest(rawRegime, persist)
if stable
regime := rawRegime
regCol = regime == 1 ? color.green : regime == 2 ? color.orange : regime == 3 ? color.red : color.blue
regName = regime == 1 ? "GOLDILOCKS" : regime == 2 ? "REFLATION" : regime == 3 ? "STAGFLATION" : "DEFLATION / SLOWDOWN"
regBest = regime == 1 ? "Equities, growth, credit" : regime == 2 ? "Commodities, value, cyclicals" : regime == 3 ? "Cash, commodities, gold; avoid stocks+bonds" : "Government bonds, defensives"
plot(growthChg, "Growth proxy: copper/gold 3m %", color.new(color.lime, 30), style = plot.style_columns)
plot(inflChg / 10, "Inflation proxy: breakeven 3m change (bp/10)", color.new(color.fuchsia, 0), 2)
hline(0, "Zero", color.gray)
bgcolor(color.new(regCol, 85), title = "Regime")
var table tbl = table.new(position.top_right, 2, 4, bgcolor = color.new(color.black, 80), border_width = 1)
if barstate.islast
table.cell(tbl, 0, 0, "Growth (Cu/Au 3m)", text_color = color.white, text_size = size.small)
table.cell(tbl, 1, 0, str.tostring(growthChg, "+#.#;-#.#") + " %", text_color = color.white, text_size = size.small)
table.cell(tbl, 0, 1, "Inflation (BE 3m)", text_color = color.white, text_size = size.small)
table.cell(tbl, 1, 1, str.tostring(inflChg, "+#;-#") + " bp", text_color = color.white, text_size = size.small)
table.cell(tbl, 0, 2, "Regime", text_color = color.white, text_size = size.small)
table.cell(tbl, 1, 2, regName, text_color = color.white, bgcolor = regCol, text_size = size.small)
table.cell(tbl, 0, 3, "Historically best", text_color = color.white, text_size = size.small)
table.cell(tbl, 1, 3, regBest, text_color = color.white, text_size = size.small)
alertcondition(regime != regime[1], "Regime change", "Growth/inflation regime changed")