Skip to content

Commit 087d731

Browse files
authored
Add files via upload
1 parent 0c379b7 commit 087d731

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from tkinter import *
2+
from tkcalendar import DateEntry
3+
import datetime as dt
4+
5+
import pandas_datareader as web
6+
import matplotlib.pyplot as plt
7+
import matplotlib.dates as mdates
8+
from mpl_finance import candlestick_ohlc
9+
10+
'''
11+
Function for visualizing stock data
12+
Using Candlestick Charts
13+
'''
14+
def visualize():
15+
16+
# Get Dates From DateEntry and Convert It To Datetime
17+
from_date = cal_from.get_date()
18+
to_date = cal_to.get_date()
19+
20+
start = dt.datetime(from_date.year, from_date.month, from_date.day)
21+
end = dt.datetime(to_date.year, to_date.month, to_date.day)
22+
23+
# Load Ticker From Entry And Download Data
24+
ticker = text_ticker.get()
25+
data = web.DataReader(ticker, 'yahoo', start, end)
26+
27+
# Restructure Data Into OHLC Format
28+
data = data[['Open', 'High', 'Low', 'Close']]
29+
30+
# Reset Index And Convert Dates Into Numerical Format
31+
data.reset_index(inplace=True)
32+
data['Date'] = data['Date'].map(mdates.date2num)
33+
34+
# Adjust Style Of The Plot
35+
ax = plt.subplot()
36+
ax.grid(True)
37+
ax.set_axisbelow(True)
38+
ax.set_title('{} Share Price'.format(ticker), color='white')
39+
ax.figure.canvas.set_window_title('Stock Visualizer ')
40+
ax.set_facecolor('black')
41+
ax.figure.set_facecolor('#121212')
42+
ax.tick_params(axis='x', colors='white')
43+
ax.tick_params(axis='y', colors='white')
44+
ax.xaxis_date()
45+
46+
# Plot The Candlestick Chart
47+
candlestick_ohlc(ax, data.values, width=0.5, colorup='#00ff00')
48+
plt.show()
49+
50+
# Define Main Window
51+
root = Tk()
52+
root.title(" Stock Visualizer ")
53+
54+
# Add Components And Link Function
55+
label_from = Label(root, text="From:")
56+
label_from.pack()
57+
cal_from = DateEntry(root, width=50, year=2015, month=1, day=1)
58+
cal_from.pack(padx=10, pady=10)
59+
60+
label_to = Label(root, text="To:")
61+
label_to.pack()
62+
cal_to = DateEntry(root, width=50)
63+
cal_to.pack(padx=10, pady=10)
64+
65+
label_ticker = Label(root, text="Ticker Symbol:")
66+
label_ticker.pack()
67+
text_ticker = Entry(root)
68+
text_ticker.pack()
69+
70+
btn_visualize = Button(root, text="Visualize", command=visualize)
71+
btn_visualize.pack()
72+
73+
root.mainloop()

0 commit comments

Comments
 (0)