Financial data in R - Fundamentals - QuanDL
Financial data in R - Fundamentals - QuanDL
September 18, 2022
The QuanDL Package
What is QuanDl about?
While looking for financial historical data for our projects, we might be interested to gather historical fundamental data for some companies.
QuanDl is a package available in R that will help is with this task.
You can find the source code at:
How to use the QuanDl package
How to install QuanDl in RStudio
You can install QuantMod in R with the following command:
# CRAN (stable)
install.packages("quantmod")
Using QuanDl in R
Query Historical Stock Information:
You can use QuanDl to query historical stocks information in R the following way:
First log your API key: https://docs.data.nasdaq.com/v1.0/docs/getting-started
# Get your API key from quandl.com and include it on a 'config.yaml' file
vars = yaml.load_file("config.yml")
quandl_api = vars$config$quandl_api
# Add the key to the Quandl keychain
Quandl.api_key(quandl_api)
Your_Ticker <- 'KO'
df_quandl <- Quandl.datatable('SHARADAR/SF1',
ticker = Your_Ticker,
calendardate.gte='2000-12-31',
)
Now enhance the dataframe with a plotly graph:
plot_ly(df1_quandl, type = 'scatter', mode = 'lines') %>%
add_trace(x = ~calendardate, y = ~ros*100, name='ROS') %>%
layout(title = '<b>Return on Sales<b>', xaxis = list(title = 'Date'),
yaxis = list(title = 'ROS (%)'), legend = list(title=list(text='<b> Date </b>')))
Project example using QuanDl
I found PriceR really useful and have used it during the creation of this Shiny project: