Comments (6)
This is definitely a bug with grouped data frames. The good news is it can be fixed. Look for a patch soon.
from tidyquant.
Glad it's working. I will close out. Regarding your comments, let me see what I can do. Here's my specific comments:
-
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 sayBBands
. 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. -
Yeah, this is the problem with inconsistent functions, especially with the
na.pad
offill
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.
Fixing code block output. Didn't render correctly first time. My bad.
from tidyquant.
Davis,
Good pickup. Let me check this out tomorrow AM.
Thanks, Matt
from tidyquant.
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 bothtq_mutate
andtq_transform
to ensure results are the same as usinggroup_by
withmutate
fromdplyr
(note thattq_transform
will only return the group column(s), date column and new column(s);tq_mutate
returns the same result asmutate
) - 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.
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 hasv1
as the new column name.y %>% mutate(sd = runSD(adjusted))
allows me to specifysd
as the column name, which would be efficient if more calculations were to be immediately done on the sd column through piping. Obviously the samesd =
technique is not going to work in your case, but perhaps another parameter such ascol_name =
orvar_name
would work to where the user could specify the name of the resulting column in thetq_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 withtq_mutate
. Specifically, using the groupedy
from the example above, and runningy %>% 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 thaty %>% tq_mutate(ohlc_fun = Ad, mutate_fun = rollmean, k = 10, fill = NA, align = "right")
would work. Sincetq_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 forfill
andalign
? 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)
- tq_index("SP500") Not Working Ubuntu HOT 2
- tq_get does not work HOT 3
- Unexpected result from EOMONTH function
- quantmod dependency should now rely on 0.4.20 or later HOT 1
- tq_get("SP500") not retrieving sp500 stock prices HOT 1
- Missing prereq? HOT 1
- tq_performance test fails under PerformanceAnalytics 2.0.6 HOT 2
- Getting Tiingo Data example fails HOT 1
- Typo: periodReturns should not have an "s" at end HOT 1
- tq_exchange("NASDAQ") not working HOT 7
- List of all stock symbols for tq_get(x, get = "stock.prices") HOT 1
- stock.prices.japan not working HOT 1
- Tidyquant is not available at CRAN HOT 3
- tq_mutate problem
- FB stock symbol retired, need to use META as stock symbol in all documentation
- tq_get("TICKERS", get = c("dividends", "splits)) fails if there are no dividends or splits
- tidyquant::geom_candlestick HOT 6
- tq_get() returning rows with NA
- Request to add India stock market indexs (BSE and NSE) Along with mutual fund data HOT 4
- Test fails if RobStatTM is not installed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tidyquant.