-
Notifications
You must be signed in to change notification settings - Fork 391
/
intraday_data.py
82 lines (67 loc) · 1.94 KB
/
intraday_data.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
76
77
78
79
80
81
82
'''
# Import TimeSeries class
from alpha_vantage.timeseries import TimeSeries
import matplotlib.pyplot as plt
import pandas as pd
ALPHA_VANTAGE_API_KEY = ''
# Initialize the TimeSeries class with key and output format
ts = TimeSeries(key=ALPHA_VANTAGE_API_KEY, output_format='pandas')
# Get pandas dataframe with the intraday data and information of the data
intraday_data, data_info = ts.get_intraday(
'ASMB', outputsize='full', interval='1min')
# Print the information of the data
print (data_info)
# Print the intraday data
print(intraday_data.head())
intraday_data['4. close'].plot(figsize=(10, 7))
# Define the label for the title of the figure
plt.title("Close Price", fontsize=16)
# Define the labels for x-axis and y-axis
plt.ylabel('Price', fontsize=14)
plt.xlabel('Time', fontsize=14)
# Plot the grid lines
plt.grid(which="major", color='k', linestyle='-.', linewidth=0.5)
plt.show()
ohlcv_dict = {
'1. open': 'first',
'2. high': 'max',
'3. low': 'min',
'4. close': 'last',
'5. volume': 'sum'
}
intraday_data.index = pd.to_datetime(intraday_data.index)
intraday_data_10 = intraday_data.resample('10T').agg(ohlcv_dict)
print (intraday_data_10.head())
'''
import yfinance as yf
import matplotlib.pyplot as plt
stock = "NKE"
data = yf.download(tickers= stock, period="1d", interval="1m")
print (data.tail())
df = data['Close']
fig, ax = plt.subplots()
plt.plot(df)
plt.title('Price for {}'.format(stock))
plt.xlabel('Time')
plt.ylabel('Price')
plt.show()
stock1 = "TSLA"
data1 = yf.download(tickers= stock1, period="1d", interval="1m")
print (data1.tail())
df1 = data1['Close']
fig, ax = plt.subplots()
plt.plot(df1)
plt.title('Price for {}'.format(stock1))
plt.xlabel('Time')
plt.ylabel('Price')
plt.show()
stock2 = "ASMB"
data2 = yf.download(tickers= stock2, period="1d", interval="1m")
print (data2.tail())
df2 = data2['Close']
fig, ax = plt.subplots()
plt.plot(df2)
plt.title('Price for {}'.format(stock2))
plt.xlabel('Time')
plt.ylabel('Price')
plt.show()