-
Notifications
You must be signed in to change notification settings - Fork 5
/
technicalindicators.py
51 lines (46 loc) · 1.77 KB
/
technicalindicators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from alpha_vantage.techindicators import TechIndicators
import matplotlib.pyplot as plt
from click._compat import raw_input
from alpha_vantage.timeseries import TimeSeries
import pandas as pd
class TechnicalIndicators:
def __init__(self):
self.api_key= 'KMOA5YH5JT2Z2A1B'
self.stock_name=self.question()
self.macd_data=self.macd()
self.rsi_data=self.rsi()
self.bbands_data=self.bbands()
self.close_data=self.close()
self.sma_data=self.sma()
def question(self):
stock_name=raw_input("Enter stock name:")
return stock_name
def macd(self):
a = TechIndicators(key=self.api_key, output_format='pandas')
data, meta_data = a.get_macd(symbol=self.stock_name,interval='daily')
return data
def rsi(self):
b=TechIndicators(key=self.api_key,output_format='pandas')
data,meta_data = b.get_rsi(symbol=self.stock_name,interval='daily',time_period=14)
return data
def bbands (self):
c=TechIndicators(key=self.api_key,output_format='pandas')
data,meta_data=c.get_bbands(symbol=self.stock_name)
return data
def sma(self):
d= TechIndicators(key=self.api_key, output_format='pandas')
data, meta_data = d.get_sma(symbol=self.stock_name,time_period=30)
return data
def close(self):
d=TimeSeries(key=self.api_key,output_format='pandas')
data,meta_data=d.get_daily(symbol=self.stock_name,outputsize='full')
return data
if __name__ == "__main__":
TI=TechnicalIndicators()
close_data = TI.close_data
macd_data = TI.macd_data
rsi_data=TI.rsi_data
bbands_data=TI.bbands_data
sma_data = TI.sma_data
plt.plot(macd_data)
plt.show()