Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tq_mutate with periodReturn not working past a certain date ("Incompatible structures") #206

Open
tvqt opened this issue Sep 28, 2021 · 2 comments

Comments

@tvqt
Copy link

tvqt commented Sep 28, 2021

Hello,

I don't know if this is the right place to raise this, but I was trying to use tq_mutate for a uni assignment, and I found that it has an issue with the stock I was looking at.

rio_stock_prices <- tq_get("RIO.AX", get = "stock.prices", from = "2004-12-25") rio_stock_prices %>% tq_mutate(select = open, mutate_fun = periodReturn, period = "daily")
This returns a result successfully. However, go from one day earlier, and the second command fails:
rio_stock_prices <- tq_get("RIO.AX", get = "stock.prices", from = "2004-12-24") rio_stock_prices %>% tq_mutate(select = open, mutate_fun = periodReturn, period = "daily")

Error in merge_two_tibbles(tib1 = data, tib2 = ret, mutate_fun) :
Could not join. Incompatible structures.
In addition: Warning messages:
1: In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
2: type_convert() only converts columns of type 'character'.

  • df has no columns of type 'character'
@tvqt
Copy link
Author

tvqt commented Sep 28, 2021

if it helps, this is the part of the data:
image
I'm guessing it's got something to do with the NAs in the data?

@tvqt
Copy link
Author

tvqt commented Sep 28, 2021

update: removing the NAs makes it run-- maybe some kind of flag can be added to the function, so others can avoid this kind of error ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant