I want to get the investment values for each stock, but I am getting, I think, for the overall dataset.
library(tidyquant)
library(dplyr)
data(FANG)
monthly_returns_stocks <- FANG %>%
group_by(symbol) %>%
tq_transmute(adjusted, periodReturn, period = "monthly")
weights <- c(0.50, 0.25, 0.25, 0)
monthly_returns_stocks %>%
tq_portfolio(assets_col = symbol,
returns_col = monthly.returns,
weights = weights,
col_rename = "investment.growth",
wealth.index = TRUE) %>%
mutate(investment.growth = investment.growth*100)
What am I doing wrong?
I want to get the investment values over time by each symbol assuming, say, $100 investment at time 0. So the desired output would look something like...
desired_output <-
tibble::tribble(
~symbol, ~date, ~investment.growth,
"FB", "1/31/2013", 100L,
"FB", "2/28/2013", 103L,
"FB", "3/28/2013", 106L,
"FB", "4/30/2013", 101L,
"FB", "5/31/2013", 99L,
"AMZN", "1/31/2013", 100L,
"AMZN", "2/28/2013", 105L,
"AMZN", "3/28/2013", 109L,
"AMZN", "4/30/2013", 123L,
"AMZN", "5/31/2013", 112L,
"GOOG", "1/31/2013", 100L,
"GOOG", "2/28/2013", 98L,
"GOOG", "3/28/2013", 96L,
"GOOG", "4/30/2013", 102L,
"GOOG", "5/31/2013", 106L)