Skip to content

Rate of change Percentage

ROCP calculates the percentage change in price between two periods. It is calulated as (price-prevPrice)/prevPrice.

Method

tm.ta.rocp(source, timeperiod)

Inputs

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

Outputs

OutputType
rocpnp.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 Percentage: (price-prevPrice)/prevPrice
rocp = tm.ta.rocp(data.close, timeperiod=10)
# Get the last value and print
last_value = rocp.iloc[-1]
tm.log(f"Last value of Rate of change Percentage: (price-prevPrice)/prevPrice is {last_value}")
# Plot the values of rocp
tm.plot(rocp, title="Rate of change Percentage: (price-prevPrice)/prevPrice", overlay=False)