-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyahoo2csv.py
More file actions
40 lines (31 loc) · 910 Bytes
/
yahoo2csv.py
File metadata and controls
40 lines (31 loc) · 910 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import random
import numpy as np
import pandas as pd
from pandas_datareader import data as pdr
import matplotlib.pyplot as plt
import fix_yahoo_finance as yf
yf.pdr_override()
fpath='C:/Users/Eric/Documents/'
ftype='.csv'
ticker = 'AAPL'
startdate = '2018-01-01'
enddate = '2019-01-31'
start = pd.to_datetime(startdate)
end = pd.to_datetime(enddate)
sdata = pdr.get_data_yahoo(ticker, start=start, end=end)
columnsTitles=['Open','High','Low','Close','Volume','Adj Close']
sdata=sdata.reindex(columns=columnsTitles)
z=np.datetime_as_string(sdata.index.values)
z=np.char.replace(z, 'T0', ' 0')
z=np.char.replace(z, '00.000000000', '00')
sdata=sdata.set_index(z)
sdata.index.names=['Date Time']
fname=fpath+ticker+ftype
sdata.to_csv(fname)
"""
#simple plot for double check of data
plt.title(ticker)
plt.plot(sdata['Close'])
plt.ylabel('Price')
plt.show()
"""