This report analyzes the daily adjusted prices of three Taiwan ETFs: 0050, 0052, and 0056. The data were obtained from the Taiwan Economic Journal (TEJ) database for the period from January 1, 2010 to September 22, 2026.
The objective of this assignment is to import the TEJ data into R, organize the adjusted price data, and convert the data into a time-series format.
The following R packages are used for data preparation and time-series conversion.
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(xts)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
The data were downloaded from the TEJ database using the TSE/OTC Adjusted Price (Daily) - Ex_R+D dataset.
The ETFs used in this assignment are:
The variable used is the daily adjusted closing price, represented by Close(NTD).
The downloaded TEJ data are imported into R.
data <- read.delim(
"20260924061630.csv",
fileEncoding = "UTF-16",
sep = "\t",
check.names = FALSE
)
head(data)
## CO_ID Date Close(NTD)
## 1 0050 Yuanta Taiwan Top50 20100104 8.4501
## 2 0052 FB Technology 20100104 2.9216
## 3 0056 PTD 20100104 8.4679
## 4 0050 Yuanta Taiwan Top50 20100105 8.4501
## 5 0052 FB Technology 20100105 2.9256
## 6 0056 PTD 20100105 8.4318
The original dataset contains the ETF identification information, trading date, and adjusted closing price.
The ETF code is extracted from the company identification variable. The trading date is also converted into the standard R Date format.
data2 <- data %>%
mutate(
Code = substr(CO_ID, 1, 4),
Date = as.Date(as.character(Date), format = "%Y%m%d")
) %>%
select(Date, Code, `Close(NTD)`)
head(data2)
## Date Code Close(NTD)
## 1 2010-01-04 0050 8.4501
## 2 2010-01-04 0052 2.9216
## 3 2010-01-04 0056 8.4679
## 4 2010-01-05 0050 8.4501
## 5 2010-01-05 0052 2.9256
## 6 2010-01-05 0056 8.4318
After this process, the dataset contains the trading date, ETF code, and adjusted closing price.
The original dataset is arranged in long format. To prepare the data for time-series analysis, the dataset is converted into wide format.
data_wide <- data2 %>%
pivot_wider(
names_from = Code,
values_from = `Close(NTD)`
) %>%
arrange(Date)
head(data_wide)
## # A tibble: 6 × 4
## Date `0050` `0052` `0056`
## <date> <dbl> <dbl> <dbl>
## 1 2010-01-04 8.45 2.92 8.47
## 2 2010-01-05 8.45 2.93 8.43
## 3 2010-01-06 8.61 2.99 8.56
## 4 2010-01-07 8.58 2.96 8.49
## 5 2010-01-08 8.64 2.95 8.58
## 6 2010-01-11 8.66 2.97 8.67
In the wide-format dataset, each row represents one trading date, while ETFs 0050, 0052, and 0056 are stored in separate columns.
The wide-format data are converted into an xts time-series object.
ETF_ts <- xts(
data_wide[, -1],
order.by = data_wide$Date
)
head(ETF_ts)
## 0050 0052 0056
## 2010-01-04 8.4501 2.9216 8.4679
## 2010-01-05 8.4501 2.9256 8.4318
## 2010-01-06 8.6072 2.9936 8.5579
## 2010-01-07 8.5847 2.9616 8.4859
## 2010-01-08 8.6371 2.9528 8.5760
## 2010-01-11 8.6595 2.9696 8.6660
tail(ETF_ts)
## 0050 0052 0056
## 2026-09-15 106.25 61.60 55.00
## 2026-09-16 106.90 61.95 55.55
## 2026-09-17 108.05 62.70 56.30
## 2026-09-18 109.85 63.80 56.85
## 2026-09-21 111.35 64.55 57.15
## 2026-09-22 111.85 64.75 56.85
nrow(ETF_ts)
## [1] 4099
The trading date is used as the time index, while the adjusted closing prices of the three ETFs are stored as separate variables.
The following commands are used to check whether the data have successfully been converted into a time-series object and to verify the starting and ending dates.
class(ETF_ts)
## [1] "xts" "zoo"
start(ETF_ts)
## [1] "2010-01-04"
end(ETF_ts)
## [1] "2026-09-22"
The results show that the dataset has successfully been converted into an xts and zoo time-series object.
The first available trading date is January 4, 2010, while the final observation is September 22, 2026.
Although the requested starting date was January 1, 2010, the first available observation in the TEJ dataset is January 4, 2010.
The daily adjusted prices of Taiwan ETFs 0050, 0052, and 0056 were successfully obtained from the TEJ database and imported into R.
The data were prepared by extracting the ETF codes and converting the trading dates into the appropriate R Date format. The dataset was then reorganized from long format into wide format.
Finally, the adjusted closing prices were successfully converted into an xts time-series object covering the available trading period from January 4, 2010 to September 22, 2026.