SPX Correlation with HYG For ThinkOrSwim

antwerks

Member
VIP
dwtomR1.png


The BofA Merrill Lynch US High Yield Master II Option-Adjusted Spread (OAS) can be correlated to the S&P 500 (SPX) or SPDR S&P 500 ETF (SPY), as it serves as a measure of credit risk in the market, and changes in credit risk often impact equity markets.
How the Correlation Works:
  • High Yield Spread (OAS) represents the risk premium investors demand to hold high-yield corporate bonds (junk bonds) over risk-free government bonds. When the spread widens, it suggests rising credit risk or fear of default, indicating financial stress in the economy.
  • Stock Market Impact (SPY/SPX): A widening spread typically signals market concerns about the health of corporations, which often leads to falling stock prices, particularly in economically sensitive sectors. Conversely, a narrowing spread indicates investor confidence in corporate credit and is often associated with rising stock prices.
Typical Correlation Behavior:
  1. Widening Credit Spread (OAS increases):
  2. Narrowing Credit Spread (OAS decreases):
Correlation Analysis:
  • Historical data shows that during periods of economic stress, such as the 2008 financial crisis or the COVID-19 pandemic in 2020, the OAS spread widened, and stock markets (SPX/SPY) simultaneously declined.
The inverse relationship between rising OAS and falling stock prices is a key element for contrarian investors to watch.

Correlations of the SPY 100 300 400 500 600 can also help pick stock sectors on the move accordingly.
Code:
declare lower;

# Calculate mean and standard deviation
def spx_mean = Average(close(symbol = "SPX"), 50);
def spx_stddev = StDev(close(symbol = "SPX"), 50);
def hyg_mean = Average(close(symbol = "HYG"), 50);
def hyg_stddev = StDev(close(symbol = "HYG"), 50);

# Normalize using Z-score transformation
def spx_standardized = (close(symbol = "SPX") - spx_mean) / spx_stddev;
def hyg_standardized = (close(symbol = "HYG") - hyg_mean) / hyg_stddev;

plot SPX_Close = spx_standardized;
SPX_Close.SetDefaultColor(Color.CYAN);
SPX_Close.SetLineWeight(2);
SPX_Close.SetPaintingStrategy(PaintingStrategy.LINE);

plot HYG_Close = hyg_standardized;
HYG_Close.SetDefaultColor(Color.RED);
HYG_Close.SetLineWeight(2);
HYG_Close.SetPaintingStrategy(PaintingStrategy.LINE);

# Add correlation plot
def correlationLength = 20;
plot Correlation = correlation(spx_standardized, hyg_standardized, correlationLength);
Correlation.SetDefaultColor(Color.YELLOW);
Correlation.SetLineWeight(1);
Correlation.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
301 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top