It seems that the *beta* is the important part here

```
import pandas as pd
import backtrader as bt
class OLS_Beta(bt.indicators.PeriodN):
_mindatas = 2 # ensure at least 2 data feeds are passed
lines = (('beta'),)
params = (('period', 30),)
def next(self):
y, x = (d.get(size=self.p.period) for d in (self.data0, self.data1))
r_beta = pd.ols(y=y, x=x, window_type='rolling', window=self.p.period)
self.lines.beta[0] = r_beta.beta['x']
```

or the *spread* directly

```
import pandas as pd
import backtrader as bt
class Spread(bt.indicators.PeriodN):
_mindatas = 2 # ensure at least 2 data feeds are passed
lines = (('spread'),)
params = (('period', 30),)
def next(self):
y, x = (d.get(size=self.p.period) for d in (self.data0, self.data1))
r_beta = pd.ols(y=y, x=x, window_type='rolling', window=self.p.period)
self.lines.spread[0] = self.data1[0] - r_beta.beta['x'] * self.data0[0]
```

Is this in line?