Fetching index prices¶
Show code cell content
import refinitiv.data as rd
rd.open_session()
/home/runner/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/_access_layer/session.py:71:FutureWarning:
You open a platform session using the default value of the signon_control parameter (signon_control=True).
In future library version v2.0, this default will be changed to False.
If you want to keep the same behavior as today, you will need to set the signon_control parameter to True either in the library configuration file
({'sessions':{'platform':{'your_session_name':{'signon_control':true}}}}) or in your code where you create the Platform Session.
These alternative options are already supported in the current version of the library.
<refinitiv.data.session.Definition object at 0x7f7b2cb0cfd0 {name='rdp'}>
You can use the Refinitiv Data Library for Python to retrieve the latest value of a stock index by passing its Refinitiv Instrument Code to the get_data
function. They are typically prefixed with a period. Here’s the Dow Jones Industrial Average:
rd.get_data(".DJI")
The get_data
query requires that you account have access to real-time trading data, which is not available to all users. If you don’t, you can request the latest "1min"
intervals from the get_history
method.
rd.get_history(
".DJI",
interval="1min",
).tail(1)
.DJI | HIGH_1 | LOW_1 | OPEN_PRC | TRDPRC_1 | NUM_MOVES | ACVOL_UNS | BID_HIGH_1 | BID_LOW_1 | OPEN_BID | BID | BID_NUMMOV | ASK_HIGH_1 | ASK_LOW_1 | OPEN_ASK | ASK | ASK_NUMMOV |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Timestamp | ||||||||||||||||
2024-04-26 15:03:00 | 38246.26 | 38239.64 | 38239.88 | 38245.7 | 22 | 262810 | 38237.29 | 38232.3 | 38232.3 | 38236.83 | 22 | 38253.58 | 38247.21 | 38247.28 | 38251.61 | 22 |
Historical data¶
You can retrieve historical stock prices by passing a Refinitiv Instrument Code to the get_history
function. By default it returns the closing price for the last 30 days.
rd.get_history('.DJI')
.DJI | TRDPRC_1 | OPEN_PRC | HIGH_1 | LOW_1 | ACVOL_UNS | ASK | THEO_OPEN | BID | NUM_MOVES |
---|---|---|---|---|---|---|---|---|---|
Date | |||||||||
2024-03-28 | 39807.37 | 39763.74 | 39868.59 | 39717.25 | 367240209 | 40779.19 | 39793.75 | 39596.11 | 24602 |
2024-04-01 | 39566.85 | 39807.93 | 39815.0 | 39491.22 | 279113853 | 39461.01 | 39797.31 | 39366.21 | 24602 |
2024-04-02 | 39170.24 | 39256.27 | 39256.27 | 39051.7 | 325610999 | 39383.88 | 39209.33 | 39131.41 | 24602 |
2024-04-03 | 39127.14 | 39139.59 | 39305.76 | 39017.13 | 372218331 | 39341.51 | 39148.76 | 39091.4 | 24602 |
2024-04-04 | 38596.98 | 39343.6 | 39421.35 | 38559.42 | 359292455 | 38732.24 | 39398.4 | 38583.18 | 24602 |
2024-04-05 | 38904.04 | 38664.98 | 39040.17 | 38602.18 | 322017508 | 38969.73 | 38622.93 | 38840.05 | 24602 |
2024-04-08 | 38892.8 | 38916.42 | 39013.2 | 38857.7 | 295063861 | 38985.3 | 38897.8 | 38866.92 | 24602 |
2024-04-09 | 38883.67 | 38983.66 | 38992.89 | 38572.09 | 330758240 | 38959.68 | 38951.01 | 38859.04 | 24602 |
2024-04-10 | 38461.51 | 38662.28 | 38662.28 | 38304.66 | 320961420 | 38466.44 | 38482.2 | 38372.56 | 24602 |
2024-04-11 | 38459.08 | 38523.26 | 38598.98 | 38197.28 | 356640369 | 38543.89 | 38542.84 | 38351.27 | 24602 |
2024-04-12 | 37983.24 | 38319.14 | 38319.14 | 37877.3 | 444253128 | 38081.33 | 38219.75 | 37899.15 | 24602 |
2024-04-15 | 37735.11 | 38075.38 | 38386.81 | 37657.79 | 391709962 | 37857.57 | 38336.16 | 37572.71 | 24602 |
2024-04-16 | 37798.97 | 37992.22 | 37992.22 | 37713.7 | 341958657 | 37903.69 | 37972.08 | 37772.36 | 24602 |
2024-04-17 | 37753.31 | 37949.67 | 38036.7 | 37611.56 | 318711769 | 37793.91 | 37927.07 | 37687.55 | 24602 |
2024-04-18 | 37775.38 | 37847.21 | 38083.76 | 37681.52 | 305520632 | 37887.33 | 37879.97 | 37680.19 | 24602 |
2024-04-19 | 37986.4 | 37801.98 | 38102.57 | 37781.61 | 426211596 | 38040.14 | 37878.2 | 37903.82 | 24602 |
2024-04-22 | 38239.98 | 38116.89 | 38447.16 | 37985.07 | 360163052 | 38342.93 | 38166.73 | 38128.96 | 24602 |
2024-04-23 | 38503.69 | 38356.07 | 38561.5 | 38297.72 | 329423565 | 38662.34 | 38373.87 | 38464.8 | 24602 |
2024-04-24 | 38460.92 | 38552.79 | 38552.79 | 38310.55 | 342887798 | 38374.66 | 38493.37 | 38258.05 | 24602 |
2024-04-25 | 38085.8 | 38052.09 | 38157.22 | 37754.38 | 417160039 | 38254.96 | 37967.67 | 38112.47 | 24602 |
Multiple instruments¶
You can retrieve data for multiple instruments by passing a list of Refinitiv Instrument Codes to the get_data
and get_history
functions.
rd.get_history(['.DJI', '.FTSE'])
/home/runner/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/_tools/_dataframe.py:177:FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
.DJI | .FTSE | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
TRDPRC_1 | OPEN_PRC | HIGH_1 | LOW_1 | ACVOL_UNS | ASK | THEO_OPEN | BID | NUM_MOVES | TRDPRC_1 | OPEN_PRC | HIGH_1 | LOW_1 | ACVOL_UNS | TRNOVR_UNS | TRDVOL_1 | |
Date | ||||||||||||||||
2024-03-27 | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | 7931.98 | 7930.96 | 7938.14 | 7893.0 | 891541286 | 508651.14 | 3129868 |
2024-03-28 | 39807.37 | 39763.74 | 39868.59 | 39717.25 | 367240209 | 40779.19 | 39793.75 | 39596.11 | 24602 | 7952.62 | 7931.98 | 7975.38 | 7931.36 | 906583822 | 482471.92 | 1901875 |
2024-04-01 | 39566.85 | 39807.93 | 39815.0 | 39491.22 | 279113853 | 39461.01 | 39797.31 | 39366.21 | 24602 | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
2024-04-02 | 39170.24 | 39256.27 | 39256.27 | 39051.7 | 325610999 | 39383.88 | 39209.33 | 39131.41 | 24602 | 7935.09 | 7952.62 | 8015.63 | 7928.59 | 984935307 | 564805.05 | 4307448 |
2024-04-03 | 39127.14 | 39139.59 | 39305.76 | 39017.13 | 372218331 | 39341.51 | 39148.76 | 39091.4 | 24602 | 7937.44 | 7935.09 | 7937.44 | 7882.68 | 1043300361 | 615858.38 | 3033171 |
2024-04-04 | 38596.98 | 39343.6 | 39421.35 | 38559.42 | 359292455 | 38732.24 | 39398.4 | 38583.18 | 24602 | 7975.89 | 7937.44 | 7990.41 | 7937.37 | 1068172085 | 569087.44 | 2247560 |
2024-04-05 | 38904.04 | 38664.98 | 39040.17 | 38602.18 | 322017508 | 38969.73 | 38622.93 | 38840.05 | 24602 | 7911.16 | 7975.89 | 7975.89 | 7884.45 | 874083676 | 598847.71 | 9176940 |
2024-04-08 | 38892.8 | 38916.42 | 39013.2 | 38857.7 | 295063861 | 38985.3 | 38897.8 | 38866.92 | 24602 | 7943.47 | 7911.16 | 7953.16 | 7887.92 | 781287842 | 448852.43 | 7805969 |
2024-04-09 | 38883.67 | 38983.66 | 38992.89 | 38572.09 | 330758240 | 38959.68 | 38951.01 | 38859.04 | 24602 | 7934.79 | 7943.47 | 7962.78 | 7917.47 | 919538950 | 611224.01 | 2291077 |
2024-04-10 | 38461.51 | 38662.28 | 38662.28 | 38304.66 | 320961420 | 38466.44 | 38482.2 | 38372.56 | 24602 | 7961.21 | 7934.79 | 7999.84 | 7916.53 | 1122680252 | 672940.76 | 1932212 |
2024-04-11 | 38459.08 | 38523.26 | 38598.98 | 38197.28 | 356640369 | 38543.89 | 38542.84 | 38351.27 | 24602 | 7923.8 | 7961.21 | 7970.09 | 7886.89 | 1062305591 | 519472.4 | 9464412 |
2024-04-12 | 37983.24 | 38319.14 | 38319.14 | 37877.3 | 444253128 | 38081.33 | 38219.75 | 37899.15 | 24602 | 7995.58 | 7923.8 | 8044.98 | 7923.8 | 838701922 | 486915.65 | 2461197 |
2024-04-15 | 37735.11 | 38075.38 | 38386.81 | 37657.79 | 391709962 | 37857.57 | 38336.16 | 37572.71 | 24602 | 7965.53 | 7995.58 | 8009.52 | 7952.14 | 710694134 | 407155.57 | 2082716 |
2024-04-16 | 37798.97 | 37992.22 | 37992.22 | 37713.7 | 341958657 | 37903.69 | 37972.08 | 37772.36 | 24602 | 7820.36 | 7965.53 | 7965.53 | 7793.91 | 973749843 | 530645.94 | 1377906 |
2024-04-17 | 37753.31 | 37949.67 | 38036.7 | 37611.56 | 318711769 | 37793.91 | 37927.07 | 37687.55 | 24602 | 7847.99 | 7820.36 | 7893.62 | 7798.57 | 860486648 | 516675.13 | 39115047 |
2024-04-18 | 37775.38 | 37847.21 | 38083.76 | 37681.52 | 305520632 | 37887.33 | 37879.97 | 37680.19 | 24602 | 7877.05 | 7847.99 | 7898.77 | 7845.89 | 1153366743 | 707628.95 | 948983 |
2024-04-19 | 37986.4 | 37801.98 | 38102.57 | 37781.61 | 426211596 | 38040.14 | 37878.2 | 37903.82 | 24602 | 7895.85 | 7877.05 | 7900.51 | 7809.68 | 898819913 | 569760.77 | 1361576 |
2024-04-22 | 38239.98 | 38116.89 | 38447.16 | 37985.07 | 360163052 | 38342.93 | 38166.73 | 38128.96 | 24602 | 8023.87 | 7895.85 | 8042.81 | 7895.85 | 990457687 | 495852.64 | 1536524 |
2024-04-23 | 38503.69 | 38356.07 | 38561.5 | 38297.72 | 329423565 | 38662.34 | 38373.87 | 38464.8 | 24602 | 8044.81 | 8023.87 | 8076.52 | 8021.67 | 933435805 | 569695.61 | 5079585 |
2024-04-24 | 38460.92 | 38552.79 | 38552.79 | 38310.55 | 342887798 | 38374.66 | 38493.37 | 38258.05 | 24602 | 8040.38 | 8044.81 | 8092.2 | 8031.79 | 1244103334 | 639313.95 | 3310211 |
2024-04-25 | 38085.8 | 38052.09 | 38157.22 | 37754.38 | 417160039 | 38254.96 | 37967.67 | 38112.47 | 24602 | 8078.86 | 8040.38 | 8105.59 | 8030.05 | 1119019380 | 719631.11 | 4881494 |
Show code cell content
rd.close_session()