Systemicalpha

Linear Regression Predictor

systemic:core-lrpMachine learningfunction1 cr

Inputs

NameTypeDescription
History Window SizeintegerThe number of past data points used to inform each prediction.
Predictions countintegerThe number of future data points to forecast beyond the current time.
Feature MatrixfloatmatrixThe collection of input data series used to train the linear regression model.

Outputs

NameTypeDescription
Predicted valuesfloatarrayA per-timestamp walk-forward series: `predictions[t]` is the H-step-ahead forecast (H = Predictions Count) built only from data observed at or before `t` — never a future timestamp. The last element is today's forecast.
Model ScorefloatarrayThe coefficient of determination measuring how well the linear model fits the training data.

At a Glance

y^=β0+β1x1+β2x2+⋯+βnxn\hat{y} = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_n x_n

Linear Regression Predictor is a machine learning module that fits a linear model to historical data and forecasts future values. Unlike reactive indicators that describe past behavior, LRP is a predictive tool—it attempts to extrapolate trends into the future using statistical modeling.


The Mathematics of Linear Regression

Core Concept

Linear regression finds the "best-fit" line (or hyperplane, in multiple dimensions) through data points by minimizing the sum of squared errors between predicted and actual values:

min⁡β∑i=1n(yi−y^i)2=min⁡β∑i=1n(yi−(β0+∑j=1pβjxij))2\min_{\beta} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 = \min_{\beta} \sum_{i=1}^{n} \left( y_i - (\beta_0 + \sum_{j=1}^{p} \beta_j x_{ij}) \right)^2

The solution yields coefficients β\beta that define the linear relationship between features and the target variable.

The Prediction Process

flowchart TD
    A[Feature Matrix] --> B[Create Sliding Windows]
    B --> C[Train Linear Model]
    C --> D[Compute Coefficients β]
    D --> E[Predict Future Values]
    E --> F[Output: Predictions + R² Score]

R² Score: Model Quality

The model outputs an R² score (coefficient of determination) that measures how well the linear model explains the variance in the data:

R2=1−∑(yi−y^i)2∑(yi−yˉ)2R^2 = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}
R² ValueInterpretation
1.0Perfect fit—model explains all variance
0.7 - 0.9Strong fit—good predictive power
0.4 - 0.7Moderate fit—some predictive value
< 0.4Weak fit—limited predictive reliability
NegativeModel performs worse than a horizontal line

How LRP Works in Systemic

Input Structure

LRP accepts a feature matrix—multiple data series that may influence the target variable. For example:

  • Price data from multiple correlated assets
  • Technical indicators (RSI, MACD values)
  • Volume data alongside price

The module:

  1. Creates sliding windows of historical data
  2. Trains a linear regression model on these windows
  3. Uses the trained model to predict the next N values

Window-Based Learning

The History Window Size parameter determines how much recent history informs each prediction. A larger window captures longer-term patterns but may be less responsive to recent changes.


Practical Applications

1. Short-Term Price Forecasting

Use LRP to project where an asset's price might be in the next few periods. This is particularly useful for:

  • Setting profit targets
  • Anticipating resistance/support levels
  • Planning entry/exit timing

Caveat: Financial markets are notoriously difficult to predict. Linear models work best when trends are relatively stable and linear relationships exist.

2. Feature Importance Analysis

By feeding different combinations of features, you can discover which variables have the strongest linear relationship with your target. This guides further research and system design.

3. Trend Extrapolation

When combined with trend-following indicators, LRP can project where a trend might lead if current conditions persist—useful for scenario planning.


Important Considerations

Linearity Assumption

Linear regression assumes relationships are... linear. Financial markets often exhibit:

  • Non-linear dynamics
  • Regime changes
  • Sudden volatility shifts

LRP works best in stable, trending conditions and should be combined with other tools that detect regime changes.

Overfitting Risk

With too many features or too small a window, the model may "memorize" historical patterns that don't generalize to new data. Monitor the R² score—if it's near 1.0 on historical data but predictions fail, overfitting is likely.

Prediction Horizon

Short-term predictions (1-3 periods ahead) are generally more reliable than long-term forecasts. The further into the future you predict, the more uncertainty compounds.


Data Alignment in Systemic

LRP accepts a Feature Matrix—one input carrying a row per timestamp, with the first column as the prediction target. A missing cell (closed market, no data yet) rides through as null; nothing is upsampled, repeated, or padded on your behalf.

Multi-Input Alignment

Systemic aligns every wired source to a common set of timestamps before LRP ever sees it — it does not fabricate values to fill gaps. A timestamp with no observation for a given source arrives as null in that source's column, not a repeated or interpolated value.

Parameter Behavior

  • Predictions count: A constant integer — how many recursive steps ahead the forecast at each timestamp looks (predictions[t] is the H-th step forecast built from data observed at or before t).
  • History Window Size: A constant integer — the number of consecutive OBSERVED (non-null) bars used to build each training window and each forecast seed. It cannot be wired from another module.

Missing Data

predictions[t] / score[t] are computed only from observed bars (rows with no null cell) — walk-forward, never looking past t:

  • Training uses window consecutive observed bars strictly before t; the forecast seed uses the last window observed bars up to and including t. A closed-market or gapped bar (e.g. a weekend on a business-day series) is skipped entirely rather than bridged with a stale value — the model sees actual trading days back-to-back.
  • A slot is None when: t itself is unobserved, too few observed history exists yet (warm-up), or the fit's R² is not a finite number.
  • Live mode returns exactly one value, gated on whether the CURRENT timestamp is observed — a historical gap earlier in the series never blocks a live answer.

Indicator Profile

The following chart compares LRP's utility across stocks and cryptocurrency markets:

quadrantChart
    title LRP Indicator Profile
    x-axis Low Popularity --> High Popularity
    y-axis Low Reliability --> High Reliability
    quadrant-1 High potential  
    quadrant-2 Established leaders
    quadrant-3 Niche tools
    quadrant-4 Popular but risky
    LRP - Stocks: [0.35, 0.50]
    LRP - Crypto: [0.40, 0.40]

Dimension Ratings

DimensionStocksCryptoNotes
Popularity3.5/104.0/10Linear regression is well-known but rarely used for direct price prediction in professional settings. More popular in crypto retail trading.
Reliability5.0/104.0/10Moderate in stable trending markets; poor during volatility. Crypto's non-linear dynamics reduce reliability.
Complexity4.0/104.0/10Relatively simple math but requires understanding of feature selection, windows, and overfitting.
Versatility6.5/106.0/10Applicable to any numerical time series. More useful for trend extrapolation than precise forecasting.
Recent Interest5.0/105.5/10Renewed interest due to ML/AI hype. Crypto traders experiment more with predictive models.

References and Further Reading


Glossary

TermDefinition
Feature MatrixMultiple input series used to train the model
Coefficients (β)Weights learned by the model for each feature
R² ScoreMeasure of how well the model fits the data (0 to 1, higher is better)
Prediction HorizonHow many future periods to forecast
History WindowNumber of past periods used to train each prediction
OverfittingWhen a model learns noise rather than signal

This documentation is for educational purposes only and does not constitute investment advice. Predictions are inherently uncertain—always validate with multiple methods.

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5