Force Index On Python
The force index (FI) is an indicator used in technical analysis to illustrate how strong the actual buying or selling pressure is. High positive values mean there is a strong rising trend, and low values signify a strong downward trend.
The FI is calculated by multiplying the difference between the last and previous closing prices by the volume of the commodity, yielding a momentum scaled by the volume. The strength of the force is determined by a larger price change or by a larger volume.
The Formula for the Force Index Is:
#Technical indicator Force index
import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt
def ForceIndex(data,ndays):
ForceIndex=pd.Series(data['Close'].diff(ndays)* data['Volume'],name='ForceIndex')
data=data.join(ForceIndex)
return data
data=web.DataReader('^NSEI',data_source='yahoo',start='1/1/2018', end='24/03/2021')
data=pd.DataFrame(data)
n=1
NSEI_ForceIndex = ForceIndex(data,n)
ForceIndex = NSEI_ForceIndex['ForceIndex']
fig=plt.figure(figsize=(11,9))
ax=fig.add_subplot(2,1,1)
ax.set_xticklabels([])
plt.plot(data['Close'],lw=1)
plt.title('NSEI Price Chart')
plt.ylabel('Close Price')
plt.grid(True)
bx=fig.add_subplot(2,1,2)
plt.plot(ForceIndex,'k',lw=0.75,linestyle='-',label='ForceIndex')
plt.legend(loc=2,prop={'size':9.5})
plt.ylabel('ForceIndex values')
plt.grid(True)
plt.setp(plt.gca().get_xticklabels(),rotation=30)
plt.show()
Comments
Post a Comment