Skip to content

Rate of change

ROC measures the percentage change in price over a specified period. It is calculated by ((price/prevPrice)-1)*100.

Method

tm.ta.roc(source, timeperiod)

Inputs

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

Outputs

OutputType
rocnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Rate of change : ((price/prevPrice)-1)*100
roc = tm.ta.roc(data.close, timeperiod=10)
# Get the last value and print
last_value = roc.iloc[-1]
tm.log(f"Last value of Rate of change : ((price/prevPrice)-1)*100 is {last_value}")
# Plot the values of roc
tm.plot(roc, title="Rate of change : ((price/prevPrice)-1)*100", overlay=False)