question

Upvotes
Accepted
22 1 0 4

Return Time Series Result as a List instead of one FullyPandas DataFrame

When I query data for an American company (e.g. Google; `GOOG.O`) and a British (e.g. RaspberryPi; `RPI.L`) the data frame returned is a full merge of American and British trading days resulting in NAs in the respective time series if e.g. American markets have a non trading day as of `2024-06-19` (see example below). Is that default behavior adjustable to returning a list with a time series per ticker in order to avoid having NAs in the time series when pulling a mixed/international universe?

>>> res=rd.get_history(
...     ['GOOG.O', 'RPI.L'],
...     start = '2023-01-01',
...     end = datetime.today().strftime('%Y-%m-%d'),
...     # end = pd.to_datetime('today').strftime('%Y-%m-%d'),
...     interval='daily',
...     # fields = ['CLOSE', 'OPEN', 'HIGH', 'LOW']
...     fields = [
...         'TR.OPENPRICE',
...         'TR.HIGHPRICE', 
...         'TR.LOWPRICE' ,
...         'TR.CLOSEPRICE'
...     ]
... )
>>> res
               GOOG.O                       ...      RPI.L                      
           Open Price High Price Low Price  ... High Price Low Price Close Price
Date                                        ...                                 
2023-01-03      89.83      91.55     89.02  ...       <NA>      <NA>        <NA>
2023-01-04      91.01      91.24      87.8  ...       <NA>      <NA>        <NA>
2023-01-05      88.07      88.21     86.56  ...       <NA>      <NA>        <NA>
2023-01-06      87.36      88.47     85.57  ...       <NA>      <NA>        <NA>
2023-01-09     89.195      90.83     88.58  ...       <NA>      <NA>        <NA>
...               ...        ...       ...  ...        ...       ...         ...
2024-06-18     178.79     178.91    175.62  ...      465.0    422.05       425.0
2024-06-19       <NA>       <NA>      <NA>  ...      435.0     400.0       415.0
2024-06-20     176.71     178.74    176.46  ...      415.0     370.0       372.0
2024-06-21     178.49   182.5117    178.06  ...      389.5     365.0       373.5
2024-06-24     181.28     182.08    180.23  ...      399.0     362.0       390.0

[379 rows x 8 columns]


python apitime-series
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Upvotes
Accepted
84.6k 287 53 77

@fabian.echterling

Thank you for reaching out to us.

For the TR.xxx fields, you can try the get_data method instead.

df = rd.get_data(['GOOG.O', 'RPI.L'], 
                 ["TR.OpenPrice.Date","TR.OpenPrice", "TR.HighPrice", "TR.LowPrice","TR.ClosePrice"], 
                 {'SDate':'2023-01-01', 'EDate':'2024-06-24'})
df.dropna()

The output is:

1719306961010.png



1719306961010.png (35.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Cool, that does it! So `get_data` is the "better" function to use instead of `get_history`?!

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.