Bringing financial analysis to the 'tidyverse'. The 'tidyquant' package provides a convenient wrapper to various 'xts', 'zoo', 'quantmod', 'TTR' and 'PerformanceAnalytics' package functions and returns the objects in the tidy 'tibble' format. The main advantage is being able to use quantitative functions with the 'tidyverse' functions including 'purrr', 'dplyr', 'tidyr', 'ggplot2', 'lubridate', etc. See the 'tidyquant' website for more information, documentation and examples.
tidyquant integrates the best resources for collecting and analyzing
PerformanceAnalytics, with the tidy data infrastructure of the
tidyverse allowing for seamless interaction between each. You can now
perform complete financial analyses in the
Our short introduction to
Check out our entire Software Intro Series on YouTube!
TTR, and now
tidyversetools in R for Data Science
ggplot2functionality for beautiful and meaningful financial visualizations
tidyquant all the benefits add up to one thing: a one-stop shop
for serious financial analysis!
Getting Financial Data from the web:
tq_get(). This is a
one-stop shop for getting web-based financial data in a “tidy” data
frame format. Get data for daily stock prices (historical), key
statistics (real-time), key ratios (historical), financial
statements, dividends, splits, economic data from the FRED, FOREX
rates from Oanda.
Manipulating Financial Data:
Integration for many financial functions from
is used to add a column to the data frame, and
used to return a new data frame which is necessary for periodicity
Performance Analysis and Portfolio Analysis:
tq_portfolio(). The newest additions to the
tq_performance() converts investment returns into performance
tq_portfolio() aggregates a group (or multiple groups) of
asset returns into one or more portfolios.
Visualizing the stock price volatility of four stocks side-by-side is quick and easy…
What about stock performance? Quickly visualize how a $10,000 investment in various stocks would perform.
Ok, stocks are too easy. What about portfolios? With the
PerformanceAnalytics integration, visualizing blended portfolios are
This just scratches the surface of
tidyquant. Here’s how to install to
Development Version with Latest Features:
CRAN Approved Version:
tidyquant package includes several vignettes to help users get up
to speed quickly:
vignettes for further
details on the package.
get = "financials" now returns a warning and
as Google Finance no longer provides data. We are actively looking for
alternative data sources.
get = "stock.prices.google" now returns a warning and
as Google Finance no longer provides data. Use
get = "stock.prices" instead
to use Yahoo Finance, or use the
riingo package to download from Tiingo.
Catch duplicate names in
col_rename when you are renaming more than 1 column.
Duplicate names are not allowed and return an error.
Fix duplicate name collision issue when the original name already includes
.. Duplicate names now get a
..2, etc. as opposed to
alphavantager, a lightweight API to the Alpha Vantage financial data provider.
Rblpapi, R interface to "Bloomberg". You must have a Bloomberg account to use this.
tq_get(get = "stock.prices.google")
tq_get(get = "key.stats"). Yahoo Finance no longer supports the Key Statistics CSV API.
tibbletimesupport was added so that all
tidyquantfunctions play nicely with
XLConnectwas removed. This should ease the use of the package, especially for Mac users.
testthat2.0. They have been updated.
timetkcoercion functions. Deprecated
tq_index()no longer pulls from marketvolume. Instead, 9 indices are available from SPDR. These indices are more reliable, and include weights for each stock in the index.
tq_get(get = "stock.prices")were 1 or 2 rows off of what the tests expected. This likely has to do with the new yahoo finance API.
quantmodversion 0.4-8 to fix Oanda and Yahoo bugs.
tq_get()data, it now returns oldest to newest.
weights = NULLwould not execute an equal weighting scheme.
tq_get(get = "quandl")is a wrapper for
Quandl::Quandl()that pulls multiple Quandl Codes in a "tidy" fashion.
tq_get(get = "quandl.datatable")is a wrapper for
Quandl::Quandl.datable()that pulls Quandl datatables.
quandl_api_key()is a wrapper for
quandl_searchis a wrapper for
tq_get(get = "stock.prices.japan")is a wrapper for
quantmod::getSymbols(src = "yahooj")that enables getting stocks from Yahoo Finance Japan.
Improvements and Fixes:
tq_transmute()now accept non-OHLC data through the
selectargument. They also now work with
PerformanceAnalyticsfunctions that work to clean and transform asset returns.
ohlc_funargument to instead use
tq_transmute_xy(). Move the sign post functions to deprecated.R
tq_mutatereturning rows incorrectly sorted
tq_getreturning data frames as nested
tq_geterror to return full error when issues are present.
tq_transform()for consistency with
tq_performance()which integrates the performance analysis functions of
tq_portfolio()which enables aggregating portfolios from individual stock returns.
tq_tranform(): Added the NA-handling functions from
zooto the list of compatible, which provide a number of useful methods for handling
NAvalues in data sets. Added
Return.excessfor calculating returns and returns in excess of the risk-free rate, respectively.
tq_transmute()help pages have been combined.
tq_exchange()gets the stock list for NASDAQ, NYSE, and AMEX exchanges. Use
tq_exchange_options()to exchange options.
FANGdata set that can be loaded with
palette_()functions used to create scales are exported.
theme_tq()creates light, dark, and green themes for tidyquant visualizations.
scale_fill_tq()add color/fill scales for the data used in tidyquant visualizations.
tq_transmute()has been replaced with
mutate_funfor consistency with
get = key.ratiosfailing with HTTP 500 error on download. Use httr RETRY in case of failure.
get = "key.ratios"where stocks listed on AMEX exchange were not able to return key ratios.
get = "key.stats"where NA's in multiple
c("AAPL", "GOOG")) cause call to fail during coercion.
tq_get("AAPL", get = c("stock.prices", "financials"))).
tq_index()function to return a stock index.
tq_get(get = "stock.index")is deprecated and will be removed during the next version after 0.4.0. Use
tq_index_options()for index options.
get = "key.stats", which retrieves the current key statistics (55 total) from www.finance.yahoo.com/. These include various current data such as Ask, Bid, Day's High, Day's Low, Last Trade Price, current P/E Ratio, EPS, Current Market Cap, EPS Projected Current Year, EPS Projected Next Year and many more. Example:
tq_get("AAPL", get = "key.stats").
geom_barchart) and candlestick charts (
geom_candlestick) can be quickly created with the new geoms.
geom_ma. The geom wraps the
geom_bbands. The same seven moving averages are compatible with the geom.
coord_x_datetime) were added to enable zooming into chart sections using dates with no out-of-bounds data loss (e.g. out-of-bounds data loss with the
tq_getcan now accept character vectors and data frames for the
xarg, in addition to a single character input. This streamlines the getting of data for multiple inputs (e.g. stock symbols, stock indexes, etc).
tq_transform, which enables fast and easy renaming during the operation.
tq_transform(). The transform and mutate functions now work properly with grouped data frames.
get = "key.ratios", where key ratios for stocks from the NYSE returned
.yin the respective transform and mutate functions.
get = "key.ratios"option for
tq_get(), which retrieves 10-years of key performance ratios (89 total) from www.morningstar.com. These include various historical measures of financial performance including profitability, growth, cash flow, financial health, efficiency, and valuation ratios. Example:
tq_get("AAPL", get = "key.ratios").
rollapply()functions to list of compatible / integrated functions used with
tq_transform_fun_options()for the full list.
tq_transform_xy()arguments to be more obvious:
tq_mutate. Names are now sequentually indexed with duplicate names starting at
tidyquant, for seamless quantitative financial analysis (
TTR) package integration with the