bib
July 8, 2019, 4:40pm
1
Good evening,
i have a dataset in which i have daily stock prices of three companies since 2010.
I have to calculate the daily returns of each one of them in this form:
return = [ stock price (t) - sock price (t-1) ] / [ stock price (t-1) ]
and store them each in a new column -> Retrun A, Return B, Return C.
I dont know how to use the dataset and calculate it. It is important, please help me
PLEASE HELP ME. I HAVE NO IDEA. I have never done R before
Welcome to the forum and R in general. It seems that you have some reading to do - https://r4ds.had.co.nz/ would be a good start
Pay special attention to dplyr::lag()
function, such as in this example:
library(dplyr)
frm <- data.frame(price = c(10, 20, 30, 40, 50))
frm <- frm %>%
mutate(return = (price - lag(price, 1)) / lag(price, 1))
print(frm)
system
Closed
July 29, 2019, 8:01pm
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.