Algo Trading: Technical Indicators Rate of Change(ROC) implementation in Python Programming.


The Rate of Change(ROC) is a technical indicator is used to measure the percentage change between the most recent price and the price "n" days ago.The indicator fluctuates around the zero line say we take 12 days Moving Average and predict the next 12 days within in a prior.As we all know that trading days are of a year basically 12 months which get's divide in 2 parts 6 months and it's of months get a long term prediction with the help of "n" days moving average which we consider.

In short term we can utilized 2 days Moving Average in which below if it trades then it is to be considered as sell and above trade to be considered as buy.It basically consider Close price and in prior to yesterday's 12 days or 2 days moving average close and with the help of it we can analyse the after 2 days or after 12 days effect and this basically get multiplied with the days's it required to show the result of it ROC basically help's in to gauge the short-term momentum or long-term momentum.

Rising ROC gives bullish signal while a falling ROC gives a bearish signal.


ROC=[((Close price today - Close price "n" days ago)/Close price "n" days ago))]

Below we will Consider Video for Proper Instructions and python code to compute the Rate of Change(ROC) technical indicator.

Example code:2-day ROC for Nifty

In the code below we are using Series,shift,diff and then join functions.

In this we are considering Series which is a one dimensional array-like object containing array of data. In diff function to compute we consider current price close and then we diffirentiate with "n" days in which we want to consider it in prior for prediction which is used to get to fetch with the help of shift functions.Then we joins a given series with a specified series/data frame them in the end for the computation using join function .

Technical Indicators Rate of Change(ROC) for NIFTY implementation in Python Code as follows:

#import library modules
import pandas as pd
import as web
import matplotlib.pyplot as plt

#Compute Roc
def ROC(data,n):
 ROC=pd.Series(N/D,name='Rate of Change')
 return data


ROC=ROC_Nifty['Rate of Change']

#represent them in chart
plt.title('NSE Price Chart')
plt.ylabel('Close Price')
plt.ylabel('ROC Values')
--End of Code Input--