Questions icon indicating copy to clipboard operation
Questions copied to clipboard

Help with my R Code

Open gabridalgo opened this issue 1 year ago • 0 comments

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!

gabridalgo avatar Dec 17 '24 13:12 gabridalgo