Linear Regression Predictor
systemic:core-lrpMachine learningfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| History Window Size | integer | The number of past data points used to inform each prediction. |
| Predictions count | integer | The number of future data points to forecast beyond the current time. |
| Feature Matrix | floatmatrix | The collection of input data series used to train the linear regression model. |
Outputs
| Name | Type | Description |
|---|---|---|
| Predicted values | floatarray | A 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 Score | floatarray | The coefficient of determination measuring how well the linear model fits the training data. |
At a Glance
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:
The solution yields coefficients 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:
| R² Value | Interpretation |
|---|---|
| 1.0 | Perfect fit—model explains all variance |
| 0.7 - 0.9 | Strong fit—good predictive power |
| 0.4 - 0.7 | Moderate fit—some predictive value |
| < 0.4 | Weak fit—limited predictive reliability |
| Negative | Model 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:
- Creates sliding windows of historical data
- Trains a linear regression model on these windows
- 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 beforet). - 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
windowconsecutive observed bars strictly beforet; the forecast seed uses the lastwindowobserved bars up to and includingt. 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
Nonewhen:titself 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
| Dimension | Stocks | Crypto | Notes |
|---|---|---|---|
| Popularity | 3.5/10 | 4.0/10 | Linear regression is well-known but rarely used for direct price prediction in professional settings. More popular in crypto retail trading. |
| Reliability | 5.0/10 | 4.0/10 | Moderate in stable trending markets; poor during volatility. Crypto's non-linear dynamics reduce reliability. |
| Complexity | 4.0/10 | 4.0/10 | Relatively simple math but requires understanding of feature selection, windows, and overfitting. |
| Versatility | 6.5/10 | 6.0/10 | Applicable to any numerical time series. More useful for trend extrapolation than precise forecasting. |
| Recent Interest | 5.0/10 | 5.5/10 | Renewed interest due to ML/AI hype. Crypto traders experiment more with predictive models. |
References and Further Reading
- Investopedia: Linear Regression — Fundamentals of linear regression
- Scikit-learn: Linear Regression — Technical implementation details
- Khan Academy: R-squared — Understanding the R² metric
Glossary
| Term | Definition |
|---|---|
| Feature Matrix | Multiple input series used to train the model |
| Coefficients (β) | Weights learned by the model for each feature |
| R² Score | Measure of how well the model fits the data (0 to 1, higher is better) |
| Prediction Horizon | How many future periods to forecast |
| History Window | Number of past periods used to train each prediction |
| Overfitting | When 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.