Rainbow Test
The Rainbow Test of Utts (1982) fits the regression on the central half of the sample and asks whether that fit describes the outer observations as well. A non-linear relation, or one that changes, is approximated better by a straight line over a narrow range than over the whole sample, so the outer observations fit worse.
The formula for the Rainbow Test takes the central \(n_{c}\) observations, from Start on:
\[\text{Start} = \left\lceil \frac{n}{4}\right\rceil\] \[n_{c} = \left\lfloor \frac{n}{2}\right\rfloor\]It compares the residual sum of squares of the full sample with that of the central fit:
\[F = \frac{\frac{\text{SSR} - \text{SSR}_{c}}{n - n_{c}}}{\frac{\text{SSR}_{c}}{n_{c} - k}}\]Where n is the number of observations, SSR and \(\text{SSR}_{c}\) the residual sums of squares of the regression fitted on the full sample and on the central part, and k the number of parameters. F follows an \(F (n - n_{c} , n_{c} - k)\) distribution under the null: the linear form is rejected when the p-value is below the significance level (0.05 for the 5% level). Here the centre is a span of time, so the test also rejects when the relation changed over the sample, and a variance that is higher at the ends moves it too.
A test of the functional form asks whether a linear regression describes the relation correctly, the null hypothesis, or misses a non-linear term, a transformation or a relevant variable, the alternative. A misspecified form biases the coefficients and leaves structure in the residuals. The tests say that something is missing, not what: a rejection is a signal to reconsider the specification, for example with a squared or interaction term or a log transformation, not a prescription.
Also known as: Utts test, Utts rainbow test, lack of fit test.
In the Finance Toolkit this is get_ramsey_reset_test with method="rainbow", the same function as Ramsey RESET Test.
Example · NKE, ADS.DE · 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_ramsey_reset_test:
from financetoolkit import Toolkit
toolkit = Toolkit(
["NKE", "ADS.DE"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2025-01-01",
end_date="2025-12-31",
)
# NKE (the first ticker) is dependent; ADS.DE is independent
toolkit.econometrics.get_ramsey_reset_test(method="rainbow")
| Parameter | Type | Description | Example |
|---|---|---|---|
dependent_ticker | str | None | The dependent (predicted) asset. Defaults to None, meaning the Toolkit instance’s first ticker. | "AAPL" |
independent_tickers | str | list[str] | None | The independent (predictor) asset(s). Defaults to None, meaning every other ticker in the Toolkit instance besides dependent_ticker. | ["MSFT", "Benchmark"] |
include_benchmark | bool | Whether to include “Benchmark” in the default independent ticker(s) (has no effect when independent_tickers is given explicitly). Defaults to False. | True |
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to regress on. Defaults to “Return”. | "Return" |
add_constant | bool | Whether to include an intercept in the underlying regression. Defaults to True. | False |
method | str | The test. Options are: “reset” (Ramsey RESET Test), “rainbow” (Rainbow Test), “harvey_collier” (Harvey-Collier Test). Defaults to “reset”. | "reset" |
power | int | The highest power of the fitted values to add, for “reset” only. Defaults to 3. | 2 |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
Which returns:
| Item | 0 |
|---|---|
| Rainbow F-Statistic | 0.5975 |
| P-Value | 0.9976 |
| Reject Correct Specification (5%) | 0 |
Using Your Own Data
get_ramsey_reset_test runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_ramsey_reset_test()
References
- Paper Utts, J.M. (1982). “The Rainbow Test for Lack of Fit in Regression.” Communications in Statistics - Theory and Methods, 11(24), 2801-2815.
- Library Referenced against statsmodels’ linear_rainbow (Rainbow Test)