Performance of Portfolio stock 
TKIM.JK = Pabrik Kertas Tjiwi Kimia Tbk. (TKIM)
INKP.JK = Indah Kiat Pulp & Paper Tbk
AGRO.JK = (AGRO) Bank Rakyat Indonesia Agroniaga Tbk.
KAEF.JK =  Kimia Farma Tbk. (KAEF)
scraping from yahoo.finance start from  2018-01-01 to 2021-07-01

1 Load Libraries

1.1 Library(ask author)

2 Get Stock Data

stocks <- c("TKIM.JK","INKP.JK","AGRO.JK","KAEF.JK")
stock_data <- tq_get(stocks
                     , get  = "stock.prices"
                     , from = "2018-01-01"
                     , to = "2021-07-01")
stock_data %>% head(10)
## # A tibble: 10 x 8
##    symbol  date        open  high   low close  volume adjusted
##    <chr>   <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>
##  1 TKIM.JK 2018-01-01  2920  2920  2920  2920       0    2890.
##  2 TKIM.JK 2018-01-02  2950  3020  2920  2970  892600    2940.
##  3 TKIM.JK 2018-01-03  2980  2980  2920  2980  723100    2950.
##  4 TKIM.JK 2018-01-04  2990  2990  2930  2980  618800    2950.
##  5 TKIM.JK 2018-01-05  2980  3140  2980  3040 6512600    3009.
##  6 TKIM.JK 2018-01-08  3040  3080  2980  3020 1113700    2989.
##  7 TKIM.JK 2018-01-09  3030  3030  2980  3000 1733400    2970.
##  8 TKIM.JK 2018-01-10  3000  3040  2980  3040 3220300    3009.
##  9 TKIM.JK 2018-01-11  3050  3200  3050  3130 8465400    3098.
## 10 TKIM.JK 2018-01-12  3150  3260  3120  3160 9060600    3128.

3 Visualize Stock Prices

Kept only 4 symbols in order to fit Will include all in dashboard via interactive filtering

# using ggplot2
stock_data %>%
    filter(symbol %in% c("TKIM.JK","INKP.JK","AGRO.JK","KAEF.JK")) %>%
    ggplot(aes(x = date, y = adjusted, color = symbol)) +
    geom_line(size = 1) +
    geom_bbands(aes(high = high, low = low, close = close), ma_fun = SMA, 
                n = 5,show.legend=TRUE) + 
    labs(title = "Daily Stock Prices",
         x = "", y = "Adjusted Prices", color = "") +
    facet_wrap(~ symbol, ncol = 2, scales = "free") +
    scale_y_continuous(labels = scales::dollar) +
    theme_tq() + 
    scale_color_tq() 

4.Calculate Returns

4.1 Simple return

mo_returns <- stock_data %>% 
  group_by(symbol) %>%
  tq_transmute(select = adjusted, 
                 mutate_fun = periodReturn, 
                 period     = "monthly", #"monthly"
                 col_rename = "returns") 
## Warning: Problem with `mutate()` input `nested.col`.
## i missing values removed from data
## i Input `nested.col` is `purrr::map(...)`.
## i The error occurred in group 1: symbol = "AGRO.JK".
## Warning in to_period(xx, period = on.opts[[period]], ...): missing values
## removed from data
## Warning: Problem with `mutate()` input `nested.col`.
## i missing values removed from data
## i Input `nested.col` is `purrr::map(...)`.
## i The error occurred in group 2: symbol = "INKP.JK".
## Warning in to_period(xx, period = on.opts[[period]], ...): missing values
## removed from data
## Warning: Problem with `mutate()` input `nested.col`.
## i missing values removed from data
## i Input `nested.col` is `purrr::map(...)`.
## i The error occurred in group 3: symbol = "KAEF.JK".
## Warning in to_period(xx, period = on.opts[[period]], ...): missing values
## removed from data
## Warning: Problem with `mutate()` input `nested.col`.
## i missing values removed from data
## i Input `nested.col` is `purrr::map(...)`.
## i The error occurred in group 4: symbol = "TKIM.JK".
## Warning in to_period(xx, period = on.opts[[period]], ...): missing values
## removed from data
mo_returns %>% 
  mutate(returns = round(returns, 12)) %>% 
  arrange(desc(symbol), desc(date)) %>% 
  datatable(class="compact", 
options = list(scrollX = TRUE, dom = "tp"))

###4.2 Chart return

mo_returns %>% 
  filter(symbol %in% c("TKIM.JK","INKP.JK","AGRO.JK","KAEF.JK")) %>%
    ggplot(aes(x = date, y = returns, fill = symbol)) +
    geom_line(aes(color=symbol)) +
    geom_hline(yintercept = 0, color = palette_light()[[1]]) +
    scale_y_continuous(labels = scales::percent) +
    labs(title = " Monthly Returns",
         subtitle = "stocks limited to fit",
         y = "Monthly Returns", x = "") + 
    facet_wrap(~ symbol, ncol = 2,scales = "free") +
    theme_tq() + 
    scale_fill_tq()

4.3 Chart smooth return

mo_returns %>% 
  filter(symbol %in% c("TKIM.JK","INKP.JK","AGRO.JK","KAEF.JK")) %>%
    ggplot(aes(x = date, y = returns, fill = symbol)) +
    geom_smooth(aes(color=symbol),method = 'loess' , 
                formula = y ~ x, se=FALSE) +
    geom_hline(yintercept = 0, color = palette_light()[[1]]) +
    scale_y_continuous(labels = scales::percent) +
    labs(title = " Monthly Returns",
         subtitle = "stocks limited to fit",
         y = "Monthly Returns", x = "") + 
    facet_wrap(~ symbol, ncol = 2,scales = "free") +
    theme_tq() + 
    scale_fill_tq()

5. Invest 10000/6bl

5.1 Data table

init.investment <- 10000
growth <- mo_returns %>% arrange(date) %>%
  mutate(final_value = init.investment * cumprod(1 + returns)) %>%
  arrange(desc(final_value)) 
growth %>% filter(date == max(date)) %>% select(-date)
## # A tibble: 4 x 3
## # Groups:   symbol [4]
##   symbol  returns final_value
##   <chr>     <dbl>       <dbl>
## 1 AGRO.JK   1.11       37532.
## 2 TKIM.JK  -0.154      26985.
## 3 INKP.JK  -0.124      14123.
## 4 KAEF.JK   0.208      11782.

5.2 Portfolio visualization

growth %>% ggplot(aes(x = date, y = final_value, color = symbol)) +
    geom_line() +
    # geom_smooth(method = "loess") +
    labs(title = "Portfolio: Growth comparison invest 10000",
         subtitle = "Performance tenor 6 bl",
         x = "", y = "Investment Value") +
    theme_tq() + theme(legend.position = "right") +
    scale_y_continuous(labels = scales::dollar)