Skip to content

Commit

Permalink
V-1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayal Chand Aichara committed Oct 29, 2019
1 parent 8f65231 commit e77ca9d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions PriceIndices/price_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class Indices:

def get_bvol_index(df):

"""
Expand Down Expand Up @@ -88,6 +89,7 @@ def get_rsi(df):
"""
try:
data = df
data = data.sort_values(by='date').reset_index(drop=True)
data['price_change'] = data['price'] - df['price'].shift(1)
data.dropna(inplace=True)
data['gain'] = data['price_change'].apply(lambda x: x if x >= 0 else 0)
Expand All @@ -107,8 +109,9 @@ def get_rsi(df):

data['RSI_2'] = 100 * (1 - (1 / (1 + data['RS_Smooth'])))
data = data.fillna(0).reset_index(drop=True)
data1 = data
data1 = data.sort_values(by='date', ascending=False).reset_index(drop=True)
return data1

except Exception as e:
return e

Expand Down Expand Up @@ -169,11 +172,12 @@ def get_bollinger_bands(df, days=20):

try:
data = df
data = data.sort_values(by='date').reset_index(drop=True)
data['SMA'] = data['price'].rolling(days).mean()
data['SD'] = data['price'].rolling(days).std()
data['pluse'] = data['SMA'] + data['SD']*2
data['minus'] = data['SMA'] - data['SMA']*2
data1 = data
data1 = data.sort_values(by='date', ascending=False).reset_index(drop=True)
fig, ax = plt.subplots(figsize=(16, 12))
plt.plot(data1['date'], data1['pluse'], color='g')
plt.plot(data1['date'], data1['minus'], color='g')
Expand All @@ -188,6 +192,7 @@ def get_bollinger_bands(df, days=20):
plt.savefig('bollinger_bands.png', bbox_inches='tight', facecolor='orange')
plt.show()
return data1

except Exception as e:
return e

Expand Down Expand Up @@ -227,6 +232,7 @@ def get_moving_average_convergence_divergence(df):
plt.show()

return data1

except Exception as e:
return print('MACD Error - {}'.format(e))

Expand All @@ -239,8 +245,10 @@ def get_simple_moving_average(df, days=15):
"""
try:
data = df
data = data.sort_values(by='date').reset_index(drop=True)
data['SMA'] = data['price'].rolling(days).mean()
data1 = data.dropna()
data1 = data1.sort_values(by='date', ascending=False).reset_index(drop=True)
fig, ax = plt.subplots(figsize=(14, 9))
plt.plot(data1['date'], data1['price'], color='r', label='Price')
plt.plot(data1['date'], data1['SMA'], color='b', label='SMA')
Expand All @@ -252,6 +260,7 @@ def get_simple_moving_average(df, days=15):
fig.set_facecolor('orange')
plt.show()
return data1

except Exception as e:
return print('SMA Error - {}'.format(e))

Expand Down Expand Up @@ -283,6 +292,7 @@ def get_exponential_moving_average(df, periods=[20]):
fig.set_facecolor('orange')
plt.show()
return data1

except Exception as e:
return print('EMA Error - {}'.format(e))

0 comments on commit e77ca9d

Please sign in to comment.