MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / get_historic_data

Function get_historic_data

copilot-labs/bollinger_bands.py:12–38  ·  view source on GitHub ↗
(symbol)

Source from the content-addressed store, hash-verified

10plt.rcParams['figure.figsize'] = (20, 10)
11
12def get_historic_data(symbol):
13 ticker = symbol
14 iex_api_key = 'Tsk_30a2677082d54c7b8697675d84baf94b'
15 api_url = f'https://sandbox.iexapis.com/stable/stock/{ticker}/chart/max?token={iex_api_key}'
16 df = requests.get(api_url).json()
17
18 date = []
19 open = []
20 high = []
21 low = []
22 close = []
23
24 for i in range(len(df)):
25 date.append(df[i]['date'])
26 open.append(df[i]['open'])
27 high.append(df[i]['high'])
28 low.append(df[i]['low'])
29 close.append(df[i]['close'])
30
31 date_df = pd.DataFrame(date).rename(columns = {0:'date'})
32 open_df = pd.DataFrame(open).rename(columns = {0:'open'})
33 high_df = pd.DataFrame(high).rename(columns = {0:'high'})
34 low_df = pd.DataFrame(low).rename(columns = {0:'low'})
35 close_df = pd.DataFrame(close).rename(columns = {0:'close'})
36 frames = [date_df, open_df, high_df, low_df, close_df]
37 df = pd.concat(frames, axis = 1, join = 'inner')
38 return df
39
40tsla = pd.read_csv('tsla.csv').set_index('date')
41tsla.index = pd.to_datetime(tsla.index)

Callers 1

get_benchmarkFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected