GithubHelp home page GithubHelp logo

Comments (6)

mdancho84 avatar mdancho84 commented on May 20, 2024 1

This is definitely a bug with grouped data frames. The good news is it can be fixed. Look for a patch soon.

from tidyquant.

mdancho84 avatar mdancho84 commented on May 20, 2024 1

@DavisVaughan

Glad it's working. I will close out. Regarding your comments, let me see what I can do. Here's my specific comments:

  1. I will incorporate in 0.3.0. The tough part about column names is that sometimes there is more than one column being added, which is why mutate doesn't work with say BBands. I could add a generic column name field, and as long as the user enters the appropriate number of column names using a character vector, col_names = c("col_one", "col_two"), then this would work. However, if the correct number of column names is not specified I guess the user gets the default generated comments.

  2. Yeah, this is the problem with inconsistent functions, especially with the na.pad of fill arguments. I'll see what I can do, but it may be best to leave it up to the user to get it right in this instance.

from tidyquant.

DavisVaughan avatar DavisVaughan commented on May 20, 2024

Fixing code block output. Didn't render correctly first time. My bad.

from tidyquant.

mdancho84 avatar mdancho84 commented on May 20, 2024

Davis,

Good pickup. Let me check this out tomorrow AM.

Thanks, Matt

from tidyquant.

mdancho84 avatar mdancho84 commented on May 20, 2024

@DavisVaughan

I've updated the development version with a patch that enables tq_mutate and tq_transform to work seamlessly with dplyr::group_by. The tests I've run are as follows:

  • Tested using group_by with both tq_mutate and tq_transform to ensure results are the same as using group_by with mutate from dplyr (note that tq_transform will only return the group column(s), date column and new column(s); tq_mutate returns the same result as mutate)
  • Tested using your example
  • Tested with zero, one, and multiple groups

Please test it out. Make sure it works to your satisfaction. I aim to please, so let me know if there is still something that needs worked out. If it's all good, let me know and I will close out the issue.

You can download the development version with devtools:

# install.packages("devtools") # uncomment if not installed
devtools::install_github("mdancho84/tidyquant")

Also, you may need to update some of the dependencies prior to installing the dev version of tidyquant. I had to update tidyr before I ran the devtools::install_github("mdancho84/tidyquant"). If using RStudio, just "update all" packages prior to updating just to be on the safe side. Otherwise, you may get an error when downloading due to a conflict.

from tidyquant.

DavisVaughan avatar DavisVaughan commented on May 20, 2024

@mdancho84

This is great! That example works like a charm now. In terms of this specific issue, you can close it.

I did have two other ideas though, just something that I thought I might bring to your attention.

  • When running the code y %>% tq_mutate(ohlc_fun = Ad, mutate_fun = runSD), the resulting tibble has v1 as the new column name. y %>% mutate(sd = runSD(adjusted)) allows me to specify sd as the column name, which would be efficient if more calculations were to be immediately done on the sd column through piping. Obviously the same sd = technique is not going to work in your case, but perhaps another parameter such as col_name = or var_name would work to where the user could specify the name of the resulting column in the tq_mutate call. Just a thought and really a minor quirk.

  • Some functions like rollmean don't work right out of the box if you are attempting to use them with tq_mutate. Specifically, using the grouped y from the example above, and running y %>% tq_mutate(ohlc_fun = Ad, mutate_fun = rollmean, k = 10) returns an error that two tibbles can't be joined. rollmean is doing what it is supposed to do by default, by not padding with NAs so the result is shorter in length than the original tibble. However, some people might not be familiar with that, and get frustrated, unaware that y %>% tq_mutate(ohlc_fun = Ad, mutate_fun = rollmean, k = 10, fill = NA, align = "right") would work. Since tq_mutate is almost always going to be working on a tibble, and the alignment and fill would be needed, perhaps some sensible defaults could be set for fill and align? Again, it's nothing code breaking, but just a personal preference while messing around with the package.

Great work though! And thanks again.

from tidyquant.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.