Skip to content

Instantly share code, notes, and snippets.

@johnukfr
johnukfr / DevRefinitiv Q&A Python RD asynchronousTRFieldsRequests
Created June 30, 2023 12:39
Sending requests for historical (TR) LSEG-Refinitiv Fields to its Python API (Refinitiv Data Library)
import asyncio
import refinitiv.data as rd
try:
rd.open_session( # This will fail in CodeBook
name="desktop.workspace", # This (i.e.: the desktop session) nesesitates users to run Workspace or Eikon on the machine where the code is run.
config_name="C:/Example.DataLibrary.Python-main/Configuration/refinitiv-data.config.json")
except:
rd.open_session() # This sicceeds in CodeBook
fields_list =[
@johnukfr
johnukfr / DevRefinitiv Q&A Python RD equityBySubSectorScreen
Last active February 2, 2023 07:25
Can I use LSEG-Refinitiv's Screener to get a data-frame of Revenue values for companies broken down by sector in Codebook? Yes you can!
import refinitiv.data as rd
from refinitiv.data.content import search
import pandas as pd
import re
from typing import List
try: # The following libraries are not available in Codebook, thus this try loop. You can download `Example.DataLibrary.Python-main` at https://github.com/Refinitiv-API-Samples/Example.DataLibrary.Python/tree/main/Configuration
rd.open_session(config_name="C:\\Example.DataLibrary.Python-main\\Example.DataLibrary.Python-main\\Configuration\\refinitiv-data.config.json")
rd.open_session("desktop.workspace")
@johnukfr
johnukfr / Migrating from COM API - Create a StreamingPrice and register event callbacks using RDP
Created August 4, 2022 16:26
using the [RDP](https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) Example notebook present in [Codebook](cpurl://apps.cp./Apps/code-book/), you can use a StreamingPrice with events to update a Pandas DataFrame with real-time streaming data. Using a StreamingPrices that way allows your applicati…
# # Import `Refinitiv Data Platform` Library and authentify ourselves to its services.
import refinitiv.dataplatform as rdp
# ## In CodeBook:
# rdp.open_desktop_session('DEFAULT_CODE_BOOK_APP_KEY')
## Outside CodeBook:
rdp_key = open("eikon.txt", "r") # The key is placed in a text file so that it may be used in this code without showing it itself.
rdp.open_desktop_session(str(rdp_key.read()))
rdp_key.close() # It is best to close the files we opened in order to make sure that we don't stop any other services/programs from accessing them if they need to.
@johnukfr
johnukfr / Forecasting_USA_GDP_via_Expenditure_Approach_df2.csv
Last active August 3, 2020 13:19
Forecasting_USA_GDP_via_Expenditure_Approach_df2.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 22 columns, instead of 16. in line 1.
,Consumption (monthly data),Investment (quarterly data),Investment (monthly step data),Government Investment (quarterly data),Government Investment (monthly step data),Net Exports (quarterly data),Net Exports (monthly step data),GDP Component Sum (quarterly data),GDP Component Sum (monthly step data),GDP (every quarter),GDP (monthly step data),Investment fitted values (monthly step data),Investment forecasts (monthly step data),Investment fitted values' real errors (monthly step data),Government Investment fitted values (monthly step data),Government Investment forecasts (monthly step data),Government Investment fitted values' real errors (monthly step data),Net Exports (monthly step data) positive,Net Exports fitted values (monthly step data),Net Exports forecasts (monthly step data),Net Exports fitted values' real errors (monthly step data)
1950-02-01,NaN,4.472500e+10,4.472500e+10,4.895600e+10,4.895600e+10,2.203000e+09,2.203000e+09,NaN,NaN,2.808280e+11,2.808280e+11,4.473305e+10,NaN,8.046422e+06,4.874360e+10
@johnukfr
johnukfr / Forecasting_USA_GDP_via_Expenditure_Approach_Mean_of_Absolute_Values1.csv
Created August 3, 2020 13:16
Forecasting_USA_GDP_via_Expenditure_Approach_Mean_of_Absolute_Values1.csv
Mean of Absolute Values
Investment forecasts (monthly step data) 3.66466e+12
Investment fitted values' real errors (monthly step data) 7.88281e+09
@johnukfr
johnukfr / Forecasting_USA_GDP_via_Expenditure_Approach_df1.csv
Created August 3, 2020 13:09
Forecasting_USA_GDP_via_Expenditure_Approach article's data-frame 1
Consumption (monthly data) Investment (quarterly data) Investment (monthly step data) Government Investment (quarterly data) Government Investment (monthly step data) Net Exports (quarterly data) Net Exports (monthly step data) GDP Component Sum (quarterly data) GDP Component Sum (monthly step data) GDP (every quarter) GDP (monthly step data)
1950-02-01 NaN 4.472500e+10 4.472500e+10 4.895600e+10 4.895600e+10 2.203000e+09 2.203000e+09 NaN NaN 2.808280e+11 2.808280e+11
1950-03-01 NaN NaN 4.472500e+10 NaN 4.895600e+10 NaN 2.203000e+09 NaN NaN NaN 2.808280e+11
1950-04-01 NaN NaN 4.472500e+10 NaN 4.895600e+10 NaN 2.203000e+09 NaN NaN NaN 2.808280e+11
1950-05-01 NaN 4.945800e+10 4.945800e+10 4.964300e+10 4.964300e+10 1.643000e+09 1.643000e+09 NaN NaN 2.903830e+11 2.903830e+11
1950-06-01 NaN NaN 4.945800e+10 NaN 4.964300e+10 NaN 1.643000e+09 NaN NaN NaN 2.903830e+11
... ... ... ... ... ... ... ... ... ... ... ...
2020-03-01 1.390677e+13 NaN 3.669469e+12 NaN 3.850661e+12 NaN -5.261540e+11 NaN 2.090074e+13 NaN 2.1534
@johnukfr
johnukfr / test_math.ipynb
Created July 13, 2020 16:40
testing gits rendering
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@johnukfr
johnukfr / MarkdownTest.ipynb
Last active July 8, 2020 11:11
Testing Markdown from Math Python Jupyter Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@johnukfr
johnukfr / Estimating_GDP_Income_Approach_df.csv
Last active June 18, 2020 13:29
Estimating_GDP_Income_Approach
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 30 columns, instead of 29. in line 1.
,USAWP (monthly data),USAWPD (monthly data),USAWPG (monthly data),NNTC (monthly data),NNTC in trillions (monthly data),NBSOPID (quarterly data),NRTC (monthly data),NRTC in trillions (monthly data),NRTCPW (monthly data),RGDP (quarterly data),RGDP (monthly data),RGDP in trillions (quarterly data),RGDPPW (monthly data),RGDPPWTNRTCPWR (monthly data),RGDPPWTNRTCPWR regressed on months,RGDPPWTNRTCPWR regressed on months' errors,RGDPPWTNRTCPWRHW fitted values (monthly data),RGDPPWTNRTCPWRHW forecasts (monthly data),RGDPPWTNRTCPWRHW fitted values' real errors (monthly data),RGDPPWTNRTCPWRHW fitted values' real errors from 1990-01-01 (monthly data),RGDPPWTNRTCPWRHW model in sample plus one forecast,RGDPPWTNRTCPWRHW model in sample plus one forecast error,r,r_f,RGDPPW estimates,RGDPPW estimates' errors,RGDPPW estimates' proportional errors,RGDPPW estimates' errors every quarter,RGDP estimates
1950-01-01,57635000.0,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,Na
RGDP (monthly data) RGDP estimates
1990-02-01 5.872701e+12 5.805637e+12
1990-03-01 5.872701e+12 5.856728e+12
1990-04-01 5.872701e+12 5.914031e+12
1990-05-01 5.960028e+12 5.846246e+12
1990-06-01 5.960028e+12 5.925746e+12
... ... ...
2019-11-01 2.172912e+13 2.168854e+13
2019-12-01 2.172912e+13 2.174243e+13
2020-01-01 2.172912e+13 2.185292e+13