Skip to content

Linear Regression

LINEARREG calculates the linear regression of a security’s closing prices.

Method

tm.ta.linearreg(source, timeperiod)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
timeperiodintNumber of periods for the indicator14

Outputs

OutputType
linearregnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Linear Regression
linearreg = tm.ta.linearreg(data.close, timeperiod=14)
# Get the last value and print
last_value = linearreg.iloc[-1]
tm.log(f"Last value of Linear Regression is {last_value}")
# Plot the values of linearreg
tm.plot(linearreg, title="Linear Regression", overlay=False)