Skip to content

Commit 09ad4c3

Browse files
Merge pull request prathimacode-hub#469 from neelshah2409/main
Stock Visualiser
2 parents 8a65b3c + 087d731 commit 09ad4c3

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed
2.78 KB
Loading
33 KB
Loading
47.5 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Stock Visualiser
2+
3+
## Short description of package/script
4+
5+
-Here firstly using the mpl finance lib we get the stock growth and then read the data through pandas and plotting the graph using matplotlib .Here we also give one feature for user that they can choose the duration for stock analysis we give them this option using tkcalendar.
6+
- List out the libraries imported: matplotlib ,pandas, tkcalendar,tkinter, date,mpl_finance
7+
8+
## Setup instructions
9+
10+
Here after running the program we need to choose the date from which we need to see the graph then we need to press visualise button and we have to give token/stock number so they graph will be shown for that stock
11+
12+
13+
14+
## Output
15+
16+
![image](Images/outut_1(stock).png)
17+
![image](Images/output_2(stock).png)
18+
![image](Images/output_3(stock).png)
19+
20+
## Author(s)
21+
22+
Neel Shah
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Libraries used:
2+
- matplotlib
3+
- pandas
4+
- mpl_finance
5+
- tkinter
6+
- date
7+
- tkcalendar
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)