Please help with this code, since I am unable to make this code work "OLS Regression[3]" from RDP wi

leogabriel.banas01
LSEG
The chart table is not returning any values for OLS regression. Full code below and I have highlighted in bold for the code on "OLS Regression[3]".
import getpass
import refinitiv.dataplatform as rdp # the RDP library for Python
import pandas as pd
import numpy as np
import cufflinks as cf # to plot graph by pandas data frame APP_KEY = getpass.getpass("Enter the app key: ") rdp.open_desktop_session(APP_KEY) RICs = ["USCPI=ECI","JPCPI=ECI","PHCPI=ECI"] # the list of RICs
s_date = "2018-01-02" # start date
e_date = "2018-12-30" # end date
#TBD - remove later pd.set_option('display.max_columns', None)
lastPriceField = "VALUE" # the last price field of these RICs
data = pd.DataFrame() # define data is a DataFrame
for aRIC in RICs: # request daily last price for each RIC
df= rdp.get_historical_price_summaries(aRIC,start=s_date,end=e_date,interval = rdp.Intervals.MONTHLY,fields=[lastPriceField])
if df is None: # check if there is any error
print("Error for RIC " + aRIC + ":" + str(rdp.get_last_status()['error'])) # print the error
else:
df[lastPriceField] = df[lastPriceField].astype(float) # convert string type to float
data[aRIC] = df[lastPriceField] # create the RIC's last price column
data # display daily last price of the RICs
data.dropna(inplace=True) # deletes rows with NaN values
data.index.names = ['DATE'] # set index name to be 'DATE'
data.sort_values(by=['DATE'], inplace=True, ascending=True) # sort prices according to the 'DATE' column in ascending order
data #display sorted prices
logReturns = np.log(data / data.shift(1)) # calculate the Log Returns logReturns # display the result
cf.set_config_file(offline=True)
logReturns.iplot(kind='line', subplots=True)
data.corr() # calculate the Correlation Matrix.
data.corr().iplot(kind='line') #No chart is returning
def add_lags(data, ric, lags):
cols = []
df = pd.DataFrame(data[ric]) #create data frame of the RIC
for lag in range(1, lags + 1):
col = 'lag_{}'.format(lag) # defines the column name
df[col] = df[ric].shift(lag) # creates the lagged data column
cols.append(col) # stores the column name
df.dropna(inplace=True) # gets rid of incomplete data rows
return df, cols
dfs = {}
for ric in RICs:
df, cols = add_lags(data, ric, 5) # create the lagged data of a RIC
dfs[ric] = df # create the RIC's logged data column
print(dfs[ric]) # print the lagged data of the RIC
regs = {}
for ric in RICs:
df = dfs[ric] # getting logged data of the RIC
reg = np.linalg.lstsq(df[cols], df[ric], rcond=-1)[0] # the OLS regression
regs[ric] = reg # storing the results
print('{:10} | {}'.format(ric, regs[ric])) # print the results
for ric in RICs:
res = pd.DataFrame(dfs[ric][ric]) # pick the data frame of the original time series
res['PRED'] = np.dot(dfs[ric][cols], regs[ric]) # creates the "prediction" values
layout1 = cf.Layout(height=450,width=1000)# Define a Layout with desired height and width
res.iloc[-50:].iplot(layout=layout1) # plot the graph
Thanks!
Tagged:
0
Answers
-
Hi @leogabriel.banas01 ,
The moderators of this forum are experts in LSEG APIs and I am afraid we can't help with general coding related issues. If you are having any issues with your rdp request/response, please kindly detail it here and we will be happy to help.
Best regards,
Haykaz
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 556 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 652 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛