-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpha_api.py
More file actions
30 lines (22 loc) · 833 Bytes
/
Copy pathalpha_api.py
File metadata and controls
30 lines (22 loc) · 833 Bytes
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
import pandas as pd
import matplotlib.pyplot as plt
from alpha_vantage.timeseries import TimeSeries
API_key = ""
ts = TimeSeries(key=API_key, output_format='pandas')
data, meta = ts.get_intraday("AAPL", interval='5min', outputsize='full')
print(meta)
print(data.info())
print(data.head())
data['4. close'].plot(figsize=(12,8), fontsize=12)
plt.show()
#Renaming columns and add separate date and time columns
columns = ['open', 'high', 'low', 'close', 'volume']
data.columns = columns
data['TradeDate'] = data.index.date
data['Time'] = data.index.time
print(data.loc['2024-06-18'])
market = data.between_time('09:30:00', '16:00:00').copy()
market.sort_index(inplace=True)
print(market.info())
print(market.groupby('TradeDate').agg({'low':'min', 'high': 'max'}))
print(market.loc[market.groupby('TradeDate')['low'].idxmin()])