Home | Command Reference | Run Example

POLY_SCATTER Command

The POLY_SCATTER command creates a scatter plot between two time series and fits a polynomial curve through the relationship. It is designed for exploring nonlinear relationships between economic, financial, and market data series.

Unlike a simple linear scatter plot, POLY_SCATTER allows the fitted relationship to bend. This makes it useful when the relationship between two variables changes as the level of one variable rises or falls.

Example

POLY_SCATTER(LIST(SP500,NQAI),2)

This example compares the S&P 500 with the Nasdaq Global Artificial Intelligence and Big Data Index using a second-degree polynomial fit.

The chart plots the observed data points, the fitted polynomial curve, and standard-deviation bands around the fitted relationship.

Syntax

POLY_SCATTER(seriesList, degree)

The first argument is a list containing two time series. The second argument controls the degree of the polynomial fit.

A degree of 1 gives a straight-line fit. A degree of 2 gives a quadratic fit. Higher degrees allow more curvature, but may also overfit the data.

Output

The command produces a D3 scatter chart with:

The standard-deviation bands help show whether recent observations are close to the historical fitted relationship or unusually high or low relative to that relationship.

Interpretation

A polynomial scatter plot is useful when the relationship between two series is not perfectly linear. For example, the stock market may rise with an AI-related index, but the relationship may flatten or steepen at different levels of the index.

The fitted curve should be read as a historical relationship, not as a forecast. Points near the fitted curve are consistent with the past relationship between the two series. Points far above or below the curve may indicate a temporary divergence, valuation gap, regime change, or unusual market condition.

The +1σ, -1σ, +2σ, and -2σ bands provide a visual measure of how far the actual observations are from the fitted polynomial relationship.

Typical Use Cases

Additional Examples

POLY_SCATTER(LIST(SP500,NASDAQ100),2)

Compares the S&P 500 with the Nasdaq 100 using a quadratic fit.

POLY_SCATTER(LIST(WTI,OILSTOCKS),2)

Explores a nonlinear relationship between crude oil prices and oil-related equities.

POLY_SCATTER(LIST(DGS10,T10YIE),2)

Compares the 10-year Treasury yield with the 10-year breakeven inflation rate.

Note: Polynomial fits can be visually powerful, but they should be interpreted carefully. A higher polynomial degree can improve the visual fit while reducing the economic meaning of the curve. For most market and macroeconomic applications, degree 1 or 2 is usually the best starting point.

Related Commands