RainbowStats™ · Command reference · Model discovery

DISCOVER_MODEL

Discover predictors and observation lags, interrogate nonlinear structure with a Random Forest, compare with OLS, and evaluate the selected specification on a reserved chronological test period.

Syntax

D=DISCOVER_MODEL(LIST(Y,X1,X2,X3))
D=DISCOVER_MODEL(LIST(Y,X1,X2,X3),MIN_LAG:1,MAX_LAG:6,MAX_VARIABLES:2,SEED:42)

The first series is the dependent variable. Remaining series are candidate predictors. At least one predictor is required. The result is a D3 slideshow; assign it to a variable to inspect its extracts.

The discovery pipeline

StageQuestionWhat to examine
1. Genetic searchWhich predictors and lags merit attention?Selected specification, alternative candidates, validation performance
2. Random ForestIs there nonlinear structure?Forest versus OLS, consolidated threshold regimes
3. OLSCan a simpler equation describe the relationship?Coefficients, residuals, diagnostics; post-selection inference is exploratory
4. Chronological testDoes it generalize?Test RMSE, historical-mean baseline, test R²
5. Forest compressionHow much forest complexity is redundant?Representative-tree fidelity, consolidated rules and regimes

Named options

OptionUse
MIN_LAG:1Require at least one observation lag in the genetic search. Use when contemporaneous predictor values would not be available at forecast time. Added in the updated implementation.
MAX_LAG:6Largest candidate observation lag.
MAX_VARIABLES:2Maximum predictors selected.
SEED:42Repeatable stochastic search.
POPULATION, GENERATIONS, MAX_EVALUATIONSGenetic-search breadth and computational budget.
TREES, MAX_DEPTH, MIN_LEAFForest size and complexity.
TRAIN_PCT, VALIDATION_PCT, PENALTY_PCTChronological sample allocation and predictor penalty.

Extracts and slideshow

EXTRACT(D,slideshow)
EXTRACT(D,selected)
EXTRACT(D,test_rmse)
EXTRACT(D,test_baseline_rmse)
EXTRACT(D,test_r_squared)
EXTRACT(D,compression_chart)

The slideshow includes genetic search, leading candidates, forest-versus-OLS comparison, nonlinear regimes, regression and residual diagnostics, and the reserved test period. compression_chart displays representative-tree agreement with the fitted full forest. For forest-specific extracts, consult RANDOM_FOREST.

Forest pruning: simplification without a forecasting claim

Representative trees are chosen to approximate the full forest. The compression chart measures the training-sample RMSE between the representative ensemble and the original forest, alongside the number of exact consolidated rules and broad threshold regimes. Lower compression RMSE means greater agreement with the original model—not necessarily lower future forecast error.

Representative treesGBP/EUR fidelity RMSEExact consolidated rulesThreshold regimes
50.00043219916
100.00027846717
200.00015792417
500.0000622,41219

The number of broad regimes changes relatively little while detailed rules multiply. Regimes are descriptions of the fitted forest, not causal effects or statistically identified economic states. These figures are illustrative results from the linked GBP/EUR analysis, not fixed output of the command.

Example: GBP/EUR daily returns

# Exchange-rate example: use only lagged predictors
g=ECB(EXR.D.GBP.EUR.SP00.A)
r=LOGDIFF(SERIES_SINCE(g,20200101))
a=LAG(r,1)
b=LAG(r,2)
m=DISCOVER_MODEL(LIST(r,a,b),MIN_LAG:1,MAX_LAG:6,MAX_VARIABLES:1,SEED:42)
EXTRACT(m,slideshow)
EXTRACT(m,selected)
EXTRACT(m,test_rmse)
EXTRACT(m,test_baseline_rmse)
EXTRACT(m,test_r_squared)
EXTRACT(m,compression_chart)

In the documented experiment, the model's chronological test RMSE was 0.002240, versus 0.002142 for the historical-mean baseline; test R² was −0.094. The discovered specification did not improve the baseline forecast.

Example: U.S. monthly employment changes

# Monthly employment example
y=DIFF(SERIES_SINCE(PAYEMS,20000101))
a=LAG(DIFF(SERIES_SINCE(INDPRO,20000101)),1)
b=LAG(DIFF(SERIES_SINCE(TCU,20000101)),1)
c=LAG(DIFF(SERIES_SINCE(CPIAUCSL,20000101)),1)
d=LAG(DIFF(SERIES_SINCE(UNRATE,20000101)),1)
m=DISCOVER_MODEL(LIST(y,a,b,c,d),MIN_LAG:1,MAX_LAG:6,MAX_VARIABLES:3,SEED:42)
EXTRACT(m,slideshow)
EXTRACT(m,compression_chart)

The documented payroll experiment reported test RMSE of 457.90 thousand jobs, versus 277.03 thousand for the baseline. Historical revised macroeconomic data should not be mistaken for a point-in-time forecast backtest.

Interpretation and limitations

Model selection is not causal identification. Genetic search and Random Forest can reveal associations, but they do not establish causal relationships. OLS standard errors following adaptive selection are exploratory. A reserved test sample reduces—but does not eliminate—the risk of overfitting when researchers repeatedly revise their designs after seeing results.

Forecast accuracy is not trading profit. The output does not include a trading strategy, transaction costs, slippage, financing, or realized P&L. Good in-sample fidelity is not evidence of profitable trades.

Further reading and replication

Run the complete RainbowStats study · Why Bother? — AI and market efficiency · GENETIC_MODEL documentation · RANDOM_FOREST documentation