My aim is to get historical stock datas of different stocks from europe and us. With the function:
JavaScript
x
3
1
import pandas_datareader as web
2
print(web.DataReader('ALB', 'yahoo', '01.01.2020', '01.01.2021'))
3
Output:
JavaScript
1
14
14
1
High Low Volume Adj Close
2
Date
3
2020-01-02 73.879997 72.190002 1620838.0 70.942619
4
2020-01-03 72.389999 71.220001 1337602.0 69.926498
5
2020-01-06 72.169998 70.188698 1330518.0 69.848328
6
2020-01-07 73.489998 71.130997 1497506.0 70.766747
7
2020-01-08 71.500000 69.610001 2029494.0 69.545456
8
9
2021-12-06 252.690002 239.110001 1035976.0 248.539993
10
2021-12-07 263.190887 253.259995 888158.0 259.529999
11
2021-12-08 265.859985 258.690002 832756.0 264.640015
12
2021-12-09 266.489990 257.299988 535738.0 257.470001
13
2021-12-10 263.559998 257.220001 598893.0 262.869995
14
returns the historical stock data in USD.
Otherwise
JavaScript
1
2
1
print(web.DataReader('BMW.DE', 'yahoo', '01.01.2020', '01.01.2021'))
2
Output:
JavaScript
1
14
14
1
High Low Open Close Volume Adj Close
2
Date
3
2020-01-02 74.629997 73.059998 73.139999 74.220001 1232319.0 67.103531
4
2020-01-03 73.830002 72.330002 73.730003 73.320000 1153245.0 66.289818
5
2020-01-06 73.050003 72.040001 72.830002 73.050003 1039192.0 66.045715
6
2020-01-07 74.320000 73.339996 73.599998 74.220001 1302124.0 67.103531
7
2020-01-08 74.500000 73.750000 73.940002 74.410004 941807.0 67.275307
8
9
2021-12-06 88.800003 86.820000 88.029999 88.419998 1100120.0 88.419998
10
2021-12-07 88.419998 88.419998 88.419998 88.419998 0.0 88.419998
11
2021-12-08 91.209999 89.129997 90.849998 91.129997 1338471.0 91.129997
12
2021-12-09 91.870003 90.000000 91.489998 90.220001 1050166.0 90.220001
13
2021-12-10 90.190002 88.949997 89.529999 89.660004 1415043.0 89.660004
14
return the historical stock data in EUR.
Is there a possibility to unify the currency in both cases?
Advertisement
Answer
Download EURUSD%3DX
to convert your data from EUR
to USD
. The important part is to reindex correctly your dataframes to align dates between them.
JavaScript
1
4
1
alb = web.DataReader('ALB', 'yahoo', '01.01.2020', '01.01.2021')
2
bmw = web.DataReader('BMW.DE', 'yahoo', '01.01.2020', '01.01.2021')
3
eurusd = web.data.DataReader('EURUSD%3DX', 'yahoo', '01.01.2020', '01.01.2021')
4
JavaScript
1
38
38
1
# Euro
2
>>> bmw[['Open', 'High', 'Low', 'Close', 'Adj Close']]
3
* eurusd[['Adj Close']].reindex(bmw.index).values
4
5
Open High Low Close Adj Close
6
Date
7
2020-01-02 82.069120 83.741021 81.979351 83.280971 75.295704
8
2020-01-03 82.367012 82.478725 80.803009 81.908979 74.055256
9
2020-01-06 81.292559 81.538124 80.410763 81.538124 73.719966
10
2020-01-07 82.417241 83.223498 82.126091 83.111520 75.142500
11
2020-01-08 82.478140 83.102803 82.266198 83.002414 75.043846
12
13
2020-12-22 88.717571 89.219288 88.032307 88.228092 84.241799
14
2020-12-23 88.365411 89.766877 87.756078 89.425643 85.385245
15
2020-12-28 91.599244 92.111856 89.524372 89.695243 85.642667
16
2020-12-29 90.624622 90.820201 88.840000 89.426729 85.386284
17
2020-12-30 89.446540 89.728362 88.503067 88.503067 84.504358
18
19
[254 rows x 5 columns]
20
21
# Dollar
22
>>> bmw[['Open', 'High', 'Low', 'Close', 'Adj Close']]
23
Open High Low Close Adj Close
24
Date
25
2020-01-02 73.139999 74.629997 73.059998 74.220001 67.103531
26
2020-01-03 73.730003 73.830002 72.330002 73.320000 66.289818
27
2020-01-06 72.830002 73.050003 72.040001 73.050003 66.045715
28
2020-01-07 73.599998 74.320000 73.339996 74.220001 67.103531
29
2020-01-08 73.940002 74.500000 73.750000 74.410004 67.275307
30
31
2020-12-22 72.500000 72.910004 71.940002 72.099998 68.842400
32
2020-12-23 72.510002 73.660004 72.010002 73.379997 70.064568
33
2020-12-28 75.050003 75.470001 73.349998 73.489998 70.169601
34
2020-12-29 74.139999 74.300003 72.680000 73.160004 69.854515
35
2020-12-30 73.000000 73.230003 72.230003 72.230003 68.966537
36
37
[254 rows x 5 columns]
38