library(quantmod)
Loading required package: xts
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
# Needed Internet Connection !! alike install packages
# Stock Ticker
<- c("ASII.JK","BBCA.JK")
stocks
<- lapply(stocks, function(stock) {
data_list getSymbols(stock, src = "yahoo", from = "2018-01-01", to="2022-12-31", auto.assign = FALSE)
})
Warning: ASII.JK contains missing values. Some functions will not work if
objects contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
# Daily Return
<- lapply(data_list, function(data) {
returns dailyReturn(Cl(data))
})
Warning in to_period(xx, period = on.opts[[period]], ...): missing values
removed from data
# Combine data
<- do.call(merge, returns)
combined_returns names(combined_returns) <- stocks
<- na.omit(combined_returns)
combined_returns head(combined_returns)
ASII.JK BBCA.JK
2018-01-01 0.000000000 0.000000000
2018-01-02 -0.012048193 0.000000000
2018-01-03 -0.018292683 0.000000000
2018-01-04 0.021739130 0.014840183
2018-01-05 0.009118541 0.001124859
2018-01-08 0.000000000 0.004494382