Skip to content

Help with my R Code #542

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

Open
gabridalgo opened this issue Dec 17, 2024 · 0 comments
Open

Help with my R Code #542

gabridalgo opened this issue Dec 17, 2024 · 0 comments

Comments

@gabridalgo
Copy link

Hi everyone.

I'm a beginner at coding in R and this is my first question here.

I'm working in the code above:

------------------------------------------------------------ Code ---------------------------------------------------------------------
require(tidyverse)
require(tidyfinance)

y <- function(y, x, start_date, end_date) {

d <- as_tibble(download_data(type = 'stock_prices', start_date = start_date, end_date = end_date,
symbols = c(y, x))%>%group_by(symbol)%>%mutate(return = adjusted_close / lag(adjusted_close) - 1)%>%
select(symbol, date, return)%>%pivot_wider(names_from = symbol, values_from = return)%>%drop_na())

d%>%
ggplot()+
geom_point(aes_string(y = y, x = x ))
}
-------------------------------------------------------- Running the code --------------------------------------------------------
plot(y('AAPL', '^BVSP', '2000-01-01', '2024-01-01'))

This code just take a stock price (from yahoo finance) and a benchmark (ibovespa) and plot its correlation.

The problem is that when i try running the code is doesnt recognize the '^' and return the error:

Error in parse(text = x, keep.source = FALSE) :
:1:1: '^' inesperado
1: ^
^

Is there any way to 'force' R to recognize this character or i need to remove it from the columns' name?

Thank you!

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