-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock-graph.py
75 lines (55 loc) · 1.96 KB
/
stock-graph.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Simple stock graph script
import datetime
from dateutil.relativedelta import relativedelta
from tiingo import TiingoClient
import matplotlib.pyplot as plt
from matplotlib import style
all_tickers = []
n = 0
k = 0
dates_string = ""
tickers_string = ""
legend_string = ""
one_year_ago = datetime.datetime.now() - relativedelta(years=1)
six_months_ago = datetime.datetime.now() - relativedelta(months=6)
one_month_ago = datetime.datetime.now() - relativedelta(months=1)
style.use("fivethirtyeight") # matlab style
config = {} # config for the TiingoClient and API
config['session'] = True
config['api_key'] = 'your_key' # Add your own api key for tiingo https://api.tiingo.com/
client = TiingoClient(config) # setting client equal to the TiingoClient with the api key in config
start = six_months_ago
end = datetime.datetime.now()
if start == six_months_ago:
dates_string = "Six Months"
elif start == one_year_ago:
dates_string = "One Year"
elif start == one_month_ago:
dates_string = "One Month"
while True:
while True:
try:
print("Type 'Exit' to leave.")
ticker = input("What Ticker would you like?: ")
ticker = ticker.upper()
all_tickers.append(ticker)
if ticker == "EXIT":
break
stock_data = client.get_dataframe(ticker,frequency = 'daily', startDate = start, endDate = end) # setting dataframe with ticker, frequency, dates
break
except:
print("Please use a valid Ticker.")
all_tickers.pop(n)
continue
if ticker == "EXIT":
break
print("\n",ticker,"Data\n",stock_data)
tickers_string = ", ".join(all_tickers)
print(tickers_string)
stock_data["high"].plot(label=ticker) # Matlab plotting of graph and showing
plt.title(tickers_string+" Stock Performance Over "+dates_string)
plt.legend()
plt.draw()
plt.show(block = False)
n = n +1
continue