Questions tagged [tidyquant]

The R tidyquant package makes it easy to use common financial data analysis packages such as xts, zoo, and quantmod along with tidyverse data manipulation packages such as dplyr, tidyr, and purrr.

's tidyquant package brings financial analysis to the tidyverse. The tidyquant package provides a convenient wrapper to various , , and 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 , , , , , etc. See the tidyquant website for more information, documentation and examples.

Repositories

Detailed HTML vignettes

Other resources

Related tags

93 questions
0
votes
3 answers

Case_when dplyr

I am trying to create a buy/sell signal. I am trying to assign the signal using a case_when statement. I created several new columns using tidyquant TQ_MUTATE in a previous step. This only assigns the "possible up" and "possible down"…
Gosatron
  • 3
  • 1
0
votes
1 answer

Dynamic portfolio re-balancing if PF weights deviate by more than a threshold

It's not so hard to backtest a portfolio with given weights and a set rebalancing frequency (e.g. daily/weekly...). There are R packages doing this, for example PerformanceAnalytics, or tidyquant's tq_portfolio which uses that function. I would like…
Martin
  • 1,141
  • 14
  • 24
0
votes
1 answer

Is there a way to create a column based on a stock's return over a user-defined period?

EDIT: I've did tried changes and opted for the tidyquant package shared in the comments below. This time I've set a range with variables, but I think I'm having trouble turning it into a function or a vector. This could either be the result of me…
0
votes
1 answer

Is there a function similar to "periodReturn" in quantmod, that calculates plain differences?

I need to calculate differences of a time series (e.g. prices) for various periodicities (daily/weekly/monthly). In quantmod (and e.g. the tq_transmute wrapper in tidyquant) I can do something similar for arithmetic and logarithmic returns (using…
ds_col
  • 129
  • 10
0
votes
3 answers

Calculate multiple moving calculations in one statement

I want to calculate all moving averages in one statement rather than repeating myself. Is this possible using quantmod or does it require some clever use of tidyeval and/or purrr? library(tidyquant) library(quantmod) library(zoo) tibble(date =…
Rickard
  • 3,600
  • 2
  • 19
  • 22
0
votes
0 answers

Using tidyquant data with quantstrat

I have some futures data retrieved from Quandl via the tq_get function from tidyquant ## list of agricultural commodities agriculturals <- c("CHRIS/ICE_CC2", "CHRIS/ICE_KC2", "CHRIS/ICE_ICN2", "CHRIS/ICE_CT2", "CHRIS/CME_LB2", "CHRIS/CME_O2",…
ThallyHo
  • 2,667
  • 5
  • 22
  • 19
0
votes
1 answer

tq_mutate and a growing window width?

using tq_mutate to run a rolling window lm model with intraday data. Function works perfect when i want a rolling window of fixed size. How do i run a window that stays fixed lets say at the first data point, 9:30 AM EST then begins to add to the…
zubin
  • 5
  • 3
0
votes
0 answers

Tidyquant: How do I assign the stock type to an existing list?

I have a list of stocks in the SP500 index. How would I assign categories type to each stocks? Current output: library(tidyquant) tq_index('SP500')$symbol [1] "MSFT" "AAPL" "AMZN" "BRK.B" "FB" [...] Expected: symbol type MSFT …
Chipmunkafy
  • 566
  • 2
  • 5
  • 17
0
votes
3 answers

Warning: getSymbols, tq_get, getSymbols.yahoo does not return prices for to date

This is really more of a warning, but I do ask and answer a question. When the to date parameter is specified in getSymbols, tq_get, getSymbols, the function returns prices for the dates up to but not including the to date even though the…
rmacey
  • 599
  • 3
  • 22
0
votes
1 answer

Iterating through a list of parameters using tidyquant R

I have a dataset which I want to process using tq_mutate and rollapply with different parameter values. Currently I'm using a for loop to go over all the parameter values but I'm sure this is not the most efficient or fastest way to do this task…
GeeGee
  • 58
  • 9
0
votes
1 answer

tq_mutate() and Volume indicators in R

I am using the tidyquant package in R to calculate indicators for every symbol in the SP500. As a sample of code: stocks_w_price_indicators<- stocks2 %>% group_by(symbol)%>% tq_mutate(select=close,mutate_fun=RSI)…
Pake
  • 968
  • 9
  • 24
0
votes
0 answers

Tidyquant rolling sharpe ratio using dynamic risk free rate

I'm looking to pass the risk free rate dynamically into the PortfolioAnalytics function SharpeRatio.annualized through the mutated PA function rollapply by using tq_mutate. Edit* At the moment I am unable to roll the time period window of risk free…
0
votes
1 answer

Add label on ggplot2 based on the trend behavior

I have a time series and calculated two trends based on stock price. I am trying to add label like ˄ on the plot when SMA.15 (blue line) crossover SMA.15 (red line) AAPL %>% select(date, close, SMA.15, SMA.50) %>% gather(key = type, value =…
Ann
  • 328
  • 1
  • 4
  • 14
0
votes
1 answer

Tidyquant package and tibble financial information access

I am currently running the following code in order to extract from the quantmod package some financial information. library(quantmod) symbols <- c("HOG", "GOOG", "GE") tickers <- new.env() lapply(symbols, getFinancials, env=tickers) BS <-…
user113156
  • 6,761
  • 5
  • 35
  • 81
0
votes
1 answer

Multiple rolling correlation

The problem I am trying to solve is to calculate rolling correlation over selected columns in a data frame. I want to use column names to drive the rolling functions: my function library(tidyquant) rolling_cor <- function(df, col1, col2,…
cephalopod
  • 1,826
  • 22
  • 31