Main Page > Articles > William Gann > William Gann's Generating Polynomial and Interaction Features for Non-Linear Market Dynamics

William Gann's Generating Polynomial and Interaction Features for Non-Linear Market Dynamics

From TradingHabits, the trading encyclopedia · 5 min read · February 28, 2026
The Black Book of Day Trading Strategies
Free Book

The Black Book of Day Trading Strategies

1,000 complete strategies · 31 chapters · Full trade plans

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.

python
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.

PriceVolumePrice^2Volume^2Price * Volume
1001000100001000000100000
1021200104041440000122400
1018001020164000080800

Mathematical Formulation

A second-degree polynomial with two variables, x1 and x2, is given by the formula:

f(x1,x2)=w0+w1x1+w2x2+w3x12+w4x22+w5x1x2f(x_1, x_2) = w_0 + w_1x_1 + w_2x_2 + w_3x_1^2 + w_4x_2^2 + w_5x_1x_2

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.