Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: pandas_datareader import historical stock data in euro

My aim is to get historical stock datas of different stocks from europe and us. With the function:

import pandas_datareader as web
print(web.DataReader('ALB', 'yahoo', '01.01.2020', '01.01.2021'))

Output:

                  High         Low  ...     Volume   Adj Close
Date                                ...                       
2020-01-02   73.879997   72.190002  ...  1620838.0   70.942619
2020-01-03   72.389999   71.220001  ...  1337602.0   69.926498
2020-01-06   72.169998   70.188698  ...  1330518.0   69.848328
2020-01-07   73.489998   71.130997  ...  1497506.0   70.766747
2020-01-08   71.500000   69.610001  ...  2029494.0   69.545456
...                ...         ...  ...        ...         ...
2021-12-06  252.690002  239.110001  ...  1035976.0  248.539993
2021-12-07  263.190887  253.259995  ...   888158.0  259.529999
2021-12-08  265.859985  258.690002  ...   832756.0  264.640015
2021-12-09  266.489990  257.299988  ...   535738.0  257.470001
2021-12-10  263.559998  257.220001  ...   598893.0  262.869995

returns the historical stock data in USD.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Otherwise

print(web.DataReader('BMW.DE', 'yahoo', '01.01.2020', '01.01.2021'))

Output:

                 High        Low       Open      Close     Volume  Adj Close
Date                                                                        
2020-01-02  74.629997  73.059998  73.139999  74.220001  1232319.0  67.103531
2020-01-03  73.830002  72.330002  73.730003  73.320000  1153245.0  66.289818
2020-01-06  73.050003  72.040001  72.830002  73.050003  1039192.0  66.045715
2020-01-07  74.320000  73.339996  73.599998  74.220001  1302124.0  67.103531
2020-01-08  74.500000  73.750000  73.940002  74.410004   941807.0  67.275307
...               ...        ...        ...        ...        ...        ...
2021-12-06  88.800003  86.820000  88.029999  88.419998  1100120.0  88.419998
2021-12-07  88.419998  88.419998  88.419998  88.419998        0.0  88.419998
2021-12-08  91.209999  89.129997  90.849998  91.129997  1338471.0  91.129997
2021-12-09  91.870003  90.000000  91.489998  90.220001  1050166.0  90.220001
2021-12-10  90.190002  88.949997  89.529999  89.660004  1415043.0  89.660004

return the historical stock data in EUR.

Is there a possibility to unify the currency in both cases?

>Solution :

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.

alb = web.DataReader('ALB', 'yahoo', '01.01.2020', '01.01.2021')
bmw = web.DataReader('BMW.DE', 'yahoo', '01.01.2020', '01.01.2021')
eurusd = web.data.DataReader('EURUSD%3DX', 'yahoo', '01.01.2020', '01.01.2021')
# Euro
>>> bmw[['Open', 'High', 'Low', 'Close', 'Adj Close']] \
        * eurusd[['Adj Close']].reindex(bmw.index).values

                 Open       High        Low      Close  Adj Close
Date                                                             
2020-01-02  82.069120  83.741021  81.979351  83.280971  75.295704
2020-01-03  82.367012  82.478725  80.803009  81.908979  74.055256
2020-01-06  81.292559  81.538124  80.410763  81.538124  73.719966
2020-01-07  82.417241  83.223498  82.126091  83.111520  75.142500
2020-01-08  82.478140  83.102803  82.266198  83.002414  75.043846
...               ...        ...        ...        ...        ...
2020-12-22  88.717571  89.219288  88.032307  88.228092  84.241799
2020-12-23  88.365411  89.766877  87.756078  89.425643  85.385245
2020-12-28  91.599244  92.111856  89.524372  89.695243  85.642667
2020-12-29  90.624622  90.820201  88.840000  89.426729  85.386284
2020-12-30  89.446540  89.728362  88.503067  88.503067  84.504358

[254 rows x 5 columns]

# Dollar
>>> bmw[['Open', 'High', 'Low', 'Close', 'Adj Close']]
                 Open       High        Low      Close  Adj Close
Date                                                             
2020-01-02  73.139999  74.629997  73.059998  74.220001  67.103531
2020-01-03  73.730003  73.830002  72.330002  73.320000  66.289818
2020-01-06  72.830002  73.050003  72.040001  73.050003  66.045715
2020-01-07  73.599998  74.320000  73.339996  74.220001  67.103531
2020-01-08  73.940002  74.500000  73.750000  74.410004  67.275307
...               ...        ...        ...        ...        ...
2020-12-22  72.500000  72.910004  71.940002  72.099998  68.842400
2020-12-23  72.510002  73.660004  72.010002  73.379997  70.064568
2020-12-28  75.050003  75.470001  73.349998  73.489998  70.169601
2020-12-29  74.139999  74.300003  72.680000  73.160004  69.854515
2020-12-30  73.000000  73.230003  72.230003  72.230003  68.966537

[254 rows x 5 columns]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading