library(DatastreamR) #logger::log_threshold(level=loglevel('ERROR')) # Login using Wrong Username or Password ds = DataClient$new("C:\\Vidya\\dsws\\sami\\DswsRUtilities\\DevR6\\Config.ini") # Login using Configuration # ds = DataClient("Config.ini") # Example 1: To retrieve data for tickers VOD and BARC for dattypes PH and PL # with start and end date as given. The retrived data is captured in a # dataframe and further the values are displayed in a Chart. # df = tryCatch ({ print("Retrieving data into dataframe and plot the values") ds$getDataframe(tickers = "VOD,BARC", fields= list("PH", "PL"), start ='2022-01-12',end = '2022-07-13', kind = 1) }, error = function(e) { stop (message(e))}) print(df) # Plotting of all the values # plotting VOD|PH|£ plot(x = df[[1]], y = df[[2]], type = 'o', xlab = "Dates", ylab = "Values", col = "blue", ylim = c(100, 250)) # (provide the highest y-axis limit in ylim parameter to plot all # the data) # add second data series to the same chart using points() and lines() # plotting BARC|PH|£ points(x = df[[1]], y = df[[3]], col="red", pch="+") lines(x = df[[1]], y = df[[3]], type = 'o', col="red",lty=2) # #add third data series to the same chart using points() and lines() # plotting VOD|PL|£ points(x = df[[1]], y = df[[4]], col="dark blue",pch="o") lines(x = df[[1]], df[[4]], col="dark blue", lty=3) # add third data series to the same chart using points() and lines() # plotting BARC|PL|£ points(x = df[[1]], y = df[[5]], col="dark red",pch="+") lines(x = df[[1]], df[[5]], col="dark red", lty=4) readline("Press Enter to continue...") # Example 2: To retrieve data for tickers VOD and BARC for dattypes PH and PL # with start and end date as given. The retrieved data is in the # form of Response class # dataResp = tryCatch ({ print("Retrieve data in Response class") ds$getData(tickers = "VOD,BARC", fields= list("PH", "PL"), start ='2022-07-12',end = '2022-07-13', kind = 1) }, error = function(e) { stop (message(e))}) print (dataResp) readline("Press Enter to continue...") # PYD and DD datatype test for nulls dataResp = tryCatch ({ print("Retrieve data in Response class") ds$getDataframe(tickers = "VOD", fields= list("DD", "PYD"), start ='-1Y', freq = "M") }, error = function(e) { stop (message(e))}) print (dataResp) readline("Press Enter to continue...") # Example 3: Symbol substitution df = tryCatch ({ print("Retreiving data for Symbol substitution") ds$getDataframe('507175', list ('DCRE', 'UP', 'UPO', 'PHP', 'PLP', 'DPL#(X(VP),3)', 'DPL#(X(MV),5)', 'DPL#(X(MTBV),5)', 'DPL#(X(DY),5)', 'DPL#(X(PC),5)', 'DPL#(X(MSGSFE),5)'), kind=0) }, error = function(e) { stop (message(e)) }) print(df) readline("Press Enter to continue...") # Example 4: Get data of Lists df = tryCatch ({ print("Data retrieved for long lists") ds$getDataframe('LS&PCOMP', list('NAME', 'ISIN'), kind=0) }, error = function(e) { stop (message(e)) } ) print(df) readline("Press Enter to continue...") # Short Lists df = tryCatch ({ print("Short lists") ds$getDataframe('L#A48783', list('NAME', 'BDATE'), kind=0) }, error = function(e) { stop (message(e)) } ) print (df) readline("Press Enter to continue...") # Example 5: Retrieve data for Expressions df = tryCatch ({ print("Retrieve Expressions") ds$getDataframe('MAV#(IN:CYD,20D)|E', NULL, kind=1) }, error = function(e) { stop (message(e)) } ) print (df) readline("Press Enter to continue...") # Example 6: Get data for Economics Changes and corrections df = tryCatch ({ print("Retrieving data for Economics Changes and Corrections") ds$getDataframe('ECON', list('DS.ECONCC(startdate=2023-07-31)'), kind=0) }, error = function(e){ stop (message(e)) } ) print(df) readline("Press Enter to continue...") df = tryCatch ({ ds$getData('ECON', list('DS.ECONCC(sequence=300688798)'), kind=0) }, error = function(e){ stop (message(e)) } ) print(df) readline("Press Enter to continue...") # # GET DATA BUNDLE dataReq1 = ds$formatDataRequest("VOD",fields= list("PH", "PL"), start ='2022-12-01', end = '2022-12-05', kind = 1) dataReq2 = ds$formatDataRequest("BARC",fields= list("PH", "PL"), start ='2022-12-01', end = '2022-12-05', kind = 1) dataBundleResp = ds$getDataBundle(list(dataReq1, dataReq2)) print(dataBundleResp)