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
1
vote
1 answer

How to add a date range to ggplot in Rshiny?

I am making a shiny app to generate stock price plots. I want to generate plots given a certain date range, but I get the error "argument 1 is not a vector" whenever I try to adjust the dates. If I remove the "daterangeinput" part from my app,…
Muhammad Kamil
  • 635
  • 2
  • 15
1
vote
2 answers

R Tidyquant adding a price difference column to a tibble

I'm trying to add a column to a Tidyquant tibble. Here's the code: library(tidyquant) symbol <- 'AAPL' start_date <- as.Date('2022-01-01') end_date <- as.Date('2022-03-31') prices <- tq_get(symbol, from = start_date, …
equanimity
  • 2,371
  • 3
  • 29
  • 53
1
vote
2 answers

Why does my custom function not work while mutating a tibble?

I created an custom function to add working days to a date. The function depends on the following packages: library(tidyverse) library(lubridate) library(tidyquant) This is the function I created: add_workingdays <- function(start_date,…
Jochem
  • 3,295
  • 4
  • 30
  • 55
1
vote
2 answers

How do you count the number of api calls in tidyquant?

For example, I'm getting stock prices from yahoo finance using tidyquant in r. library(tidyquant) tq_get(c("AAPL","AMD"), from = '20222-03-01', to = '2022-03-02') This will result in 4 rows. How many api calls does this result in?
Josh Sung
  • 15
  • 4
1
vote
2 answers

donchian low in the TTR is incorrect plot

I am plotting the donchian high and low using tidy packages. the low value does not look correct. I am probably not calling the donchian function properly as the donchian_100_low is the highest value of the row. I dont know how to fix it. …
junkone
  • 1,427
  • 1
  • 20
  • 45
1
vote
0 answers

How to avoid scale_fill_discrete() changed the bar's colors of geom_candlestick

I have sample stock price data (in the end of this question) and I am trying to plot the geom_candlestick chart and add different background colors for multiple date intervals using the following…
ah bon
  • 9,293
  • 12
  • 65
  • 148
1
vote
1 answer

Handling xts objects that contain special characters

I'd like to retrieve financial data from Yahoo using the tidyquant package (or any other package). For retrieving Microsoft's (index: MSFT) closing prices, the following code works fine: #load packages library(tidyquant) #acquire monthly average…
natalieee
  • 67
  • 8
1
vote
1 answer

How to calculate investment values of multiple stocks using tidyquant?

I want to get the investment values for each stock, but I am getting, I think, for the overall dataset. library(tidyquant) library(dplyr) data(FANG) monthly_returns_stocks <- FANG %>% group_by(symbol) %>% tq_transmute(adjusted, periodReturn,…
Geet
  • 2,515
  • 2
  • 19
  • 42
1
vote
1 answer

How to get OHLC monthly high and low data using tq_transmute from tidyquant package in R

I am new to analyzing time series data and am looking for some help pull the monthly high and low prices from some OHLC data. When I try and aggregate the monthly open, high, low, and close prices, only the values from the last date of each month…
1
vote
3 answers

Convert Daily Data into Weekly Data and summarize multiple columns in R

I want to change the following data set : date A B 01/01/2018 391 585 02/01/2018 420 595 03/01/2018 455 642 04/01/2018 469 654 05/01/2018 611 900 06/01/2018 449 640 07/01/2018 335 522 08/01/2018 726 955 09/01/2018 676…
1
vote
1 answer

tidyquant with changing stocks over time and changing weightvector over time

I want to be able to make a weight vector for every period, in the example here the weight vector is fixed at the beginning and there are no changes, I want to be able to change the weights. I also have changing number of stocks, so it is possible…
gilberke
  • 45
  • 1
  • 7
1
vote
1 answer

Changing the value in a rank given a condition

I am trying to transform a table of stocks ranked by their return to a matrix of values that would be inputted to PerformanceAnalytics::ReturnPortfolio as the weights of the stocks in the portfolio. What I am specially looking to do is to transform…
1
vote
1 answer

How to use tidyquant (performance analytics) to calculate portfolio statistics in a portfolio with varying assets by period

I know there are good resources for calculating stock and portfolio returns using performance analytics in tidyquant for R. For example, assume we want to determine the annual portfolio returns (2011 through 2015) for a portfolio that contains…
Jcarl
  • 161
  • 2
  • 9
1
vote
1 answer

R: if else statement is handling column as whole vector

I have a data set where I want to calculate the 6 month return of stocks with tq_get (see example below) Dataset called top ticker 6month AKO.A BIG BGFV Function library(tidyverse) library(dplyr) library(tidyquant) library(riingo) calculate <-…
MelBourbon
  • 105
  • 1
  • 9
1
vote
0 answers

Plotting 52 week range in R

I am trying to pull stock price data using tq_get in tidyquant, then want to plot the current price against the 52 week range. Here is an example of what I am looking to create. Basically just a visual representation of where the stock is…