Skip to content

Help with my R Code #542

Open
Open
@gabridalgo

Description

@gabridalgo

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions