William Gann's Generating Polynomial and Interaction Features for Non-Linear Market Dynamics
Financial markets are notoriously complex and non-linear. Linear models, while simple and interpretable, often fail to capture the intricate relationships between different market variables. To address this, we can generate polynomial and interaction features to model these non-linear dynamics.
Polynomial Features
Polynomial features are generated by raising the existing features to a certain power. For example, if we have a feature x, we can generate polynomial features x^2, x^3, and so on. This can help capture non-linear relationships between the features and the target variable.
Scikit-Learn's PolynomialFeatures transformer makes it easy to generate these features.
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
X = np.arange(6).reshape(3, 2)
poly = PolynomialFeatures(degree=2)
poly.fit_transform(X)
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
X = np.arange(6).reshape(3, 2)
poly = PolynomialFeatures(degree=2)
poly.fit_transform(X)
Interaction Features
Interaction features are generated by multiplying two or more features together. This can help capture the synergistic effects between different features. For example, the interaction between a momentum indicator and a volatility indicator might be a effective predictor of future price movements.
PolynomialFeatures can also generate interaction features by setting interaction_only=True.
A Practical Example
Let's consider a simple example of using polynomial and interaction features to model the relationship between a stock's price and its volume.
| Price | Volume | Price^2 | Volume^2 | Price * Volume |
|---|---|---|---|---|
| 100 | 1000 | 10000 | 1000000 | 100000 |
| 102 | 1200 | 10404 | 1440000 | 122400 |
| 101 | 800 | 10201 | 640000 | 80800 |
Mathematical Formulation
A second-degree polynomial with two variables, x1 and x2, is given by the formula:
By generating polynomial and interaction features, we can transform a linear model into a non-linear model, allowing it to capture more complex patterns in the data.
