Linear Regression Predictor
systemic:core-lrpMachine learningInputs
| Name | Type | Description |
|---|---|---|
| History Window Size | Whole number | The number of bars in a row that the model looks at to predict the next bar. |
| Predictions count | Whole number | How many bars ahead each forecast looks. |
| Feature Matrix | Several number series | A matrix with one row per bar and one column per feature, used to train the linear regression model. |
Outputs
| Name | Type | Description |
|---|---|---|
| Predicted values | Number series | The forecast of the target made on each bar, using only data from that bar and earlier. |
| Model Score | Number series | The coefficient of determination (R²): how well the linear model fits its training data. |
Cost
0.194 + 0.0209·n + 0.0000162·n² credits for n bars, rounded up. The marks are each plan's limit of bars.
At a Glance
Linear Regression Predictor is a machine learning module. It fits a linear model to historical data and forecasts future values. Most indicators describe past behavior. LRP is a predictive tool: it tries to extend trends into the future with a statistical model.
The Mathematics of Linear Regression
Core Concept
Linear regression finds the "best-fit" line (or plane, with several features) through the data points. It minimizes the sum of squared errors between predicted and actual values:
The solution gives the coefficients that define the linear relationship between the features and the target.
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 module outputs an R² score (coefficient of determination). It measures how well the linear model explains the variance in the data it was trained on:
| 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 |
How LRP Works in Systemic
Input Structure
LRP takes a feature matrix: several series that may influence the target. For example:
- Price data from several 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 forecast the target N bars ahead (N = Predictions count)
Window-Based Learning
The History Window Size sets how many bars in a row the model sees at once. Each training example is that many bars, used to predict the target on the next bar. A larger window can capture longer patterns, but it needs more history and can overfit.
Practical Applications
1. Short-Term Price Forecasting
Use LRP to project where an asset's price might be in the next few bars. This is useful for:
- Setting profit targets
- Anticipating resistance/support levels
- Planning entry/exit timing
Caveat: Financial markets are very hard to predict. Linear models work best when trends are stable and the relationships are linear.
2. Feature Importance Analysis
Try different combinations of features to see which ones have the strongest linear relationship with your target. This guides further research and strategy design.
3. Trend Extrapolation
Combined with trend-following indicators, LRP can project where a trend might lead if current conditions continue. This is useful for scenario planning.
Important Considerations
Linearity Assumption
Linear regression assumes that relationships are linear. Financial markets often show:
- Non-linear dynamics
- Regime changes
- Sudden volatility shifts
LRP works best in stable, trending conditions. Combine it with other tools that detect regime changes.
Overfitting Risk
With too many features or too little history, the model may "memorize" past patterns that do not hold on new data. Watch the R² score: if it is near 1.0 but the predictions fail, overfitting is likely.
Prediction Horizon
Short-term predictions (1-3 bars ahead) are generally more reliable than long-term forecasts. The further ahead you predict, the more the uncertainty grows.
Data Alignment in Systemic
LRP takes a Feature Matrix: one input with a row per bar and a column per feature. The first column is the prediction target. A missing cell (closed market, no data yet) stays empty. LRP never fills it.
Multi-Input Alignment
The series are aligned by time when the matrix is built, before LRP runs. A bar where a series has no value is an empty cell in that series' column.
Parameter Behavior
- Predictions count: A constant integer. It sets how many bars ahead each forecast looks. The forecast is built one step at a time: each step uses the forecast of the step before, and the other features keep their latest values.
predictionson a bar uses only data from that bar and earlier. - History Window Size: A constant integer. It is the number of bars in a row (bars with data) in each training example and in the input of each forecast.
Missing Data
predictions and score are computed only from bars with data (rows with no empty cell). The calculation never looks past the current bar:
- The model for a bar is trained on all bars with data before it. Each training example is
windowbars in a row, used to predict the target on the next bar. The forecast starts from the lastwindowbars with data, up to and including the current bar. A bar with a missing cell (e.g. a weekend on a business-day series) is skipped, so the model sees the trading days one after another. - An output is empty when the bar itself has a missing cell, when there is too little history (the first
window+ 2 bars with data), or when the fit's R² is not a finite number.
Indicator Profile
This chart compares how useful LRP is for stocks and for cryptocurrencies:
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
- Khan Academy: R-squared — Understanding the R² metric
Glossary
| Term | Definition |
|---|---|
| Feature Matrix | Several input series, one per column, 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 bars ahead the forecast looks |
| History Window | Number of bars in a row in each training example |
| Overfitting | When a model learns noise rather than signal |
This documentation is for educational purposes only and is not investment advice. Predictions are uncertain. Always validate them with other methods.