title: “Taiwan Stock Market Daily Prices” author: “Delgermaa” date: “r Sys.Date()” output: html_document: toc: true toc_float: true knitr::opts_chunk$set( echo = TRUE, warning = FALSE, message = FALSE —

title: “Taiwan Stock Market Daily Prices” author: “Delgermaa” date: “2026-10-06” output: html_document: toc: true toc_float: true —————

1. Import Data

stock_data <- read.csv(
  "hw3.csv",
  stringsAsFactors = FALSE
)

head(stock_data)
##                      CO_ID      Date     Open     High      Low    Close
## 1                 0053 PTE 10/4/2024  95.4244  95.4244  94.4654  94.4654
## 2 0050 Yuanta Taiwan Top50 10/4/2024  44.1573  44.4692  43.9173  44.0613
## 3                 0056 PTD 10/4/2024  31.0855  31.1824  30.8513  30.9644
## 4                 0051 TMT 10/4/2024  76.4016  76.4016  74.9954  75.2767
## 5      0057 FB MSCI Taiwan 10/4/2024 136.2000 136.9500 135.7000 135.7000
## 6       0052 FB Technology 10/4/2024  24.5660  24.7366  24.3681  24.4636
str(stock_data)
## 'data.frame':    2838 obs. of  6 variables:
##  $ CO_ID: chr  "0053 PTE" "0050 Yuanta Taiwan Top50" "0056 PTD" "0051 TMT" ...
##  $ Date : chr  "10/4/2024" "10/4/2024" "10/4/2024" "10/4/2024" ...
##  $ Open : num  95.4 44.2 31.1 76.4 136.2 ...
##  $ High : num  95.4 44.5 31.2 76.4 136.9 ...
##  $ Low  : num  94.5 43.9 30.9 75 135.7 ...
##  $ Close: num  94.5 44.1 31 75.3 135.7 ...

2. Data Preparation

# Convert Date to Date format
stock_data$Date <- as.Date(
  stock_data$Date,
  format = "%m/%d/%Y"
)

# Convert price columns to numeric
stock_data$Open <- as.numeric(stock_data$Open)
stock_data$High <- as.numeric(stock_data$High)
stock_data$Low <- as.numeric(stock_data$Low)
stock_data$Close <- as.numeric(stock_data$Close)

# Remove rows with missing important values
stock_data <- stock_data %>%
  filter(
    !is.na(CO_ID),
    !is.na(Date)
  )

str(stock_data)
## 'data.frame':    2838 obs. of  6 variables:
##  $ CO_ID: chr  "0053 PTE" "0050 Yuanta Taiwan Top50" "0056 PTD" "0051 TMT" ...
##  $ Date : Date, format: "2024-10-04" "2024-10-04" ...
##  $ Open : num  95.4 44.2 31.1 76.4 136.2 ...
##  $ High : num  95.4 44.5 31.2 76.4 136.9 ...
##  $ Low  : num  94.5 43.9 30.9 75 135.7 ...
##  $ Close: num  94.5 44.1 31 75.3 135.7 ...

3. Data Overview

# Number of rows and columns
dim(stock_data)
## [1] 2838    6
# Column names
names(stock_data)
## [1] "CO_ID" "Date"  "Open"  "High"  "Low"   "Close"
# First date
min(stock_data$Date, na.rm = TRUE)
## [1] "2024-10-04"
# Last date
max(stock_data$Date, na.rm = TRUE)
## [1] "2024-10-04"
# Number of unique companies
length(unique(stock_data$CO_ID))
## [1] 2838

4. Company Summary

company_summary <- stock_data %>%
  group_by(CO_ID) %>%
  summarise(
    Observations = n(),
    First_Date = min(Date, na.rm = TRUE),
    Last_Date = max(Date, na.rm = TRUE),
    Average_Close = mean(Close, na.rm = TRUE),
    Min_Close = min(Close, na.rm = TRUE),
    Max_Close = max(Close, na.rm = TRUE),
    .groups = "drop"
  )

head(company_summary, 20)
## # A tibble: 20 × 7
##    CO_ID    Observations First_Date Last_Date  Average_Close Min_Close Max_Close
##    <chr>           <int> <date>     <date>             <dbl>     <dbl>     <dbl>
##  1 0050 Yu…            1 2024-10-04 2024-10-04         44.1      44.1      44.1 
##  2 0051 TMT            1 2024-10-04 2024-10-04         75.3      75.3      75.3 
##  3 0052 FB…            1 2024-10-04 2024-10-04         24.5      24.5      24.5 
##  4 0053 PTE            1 2024-10-04 2024-10-04         94.5      94.5      94.5 
##  5 0055 PTF            1 2024-10-04 2024-10-04         26.7      26.7      26.7 
##  6 0056 PTD            1 2024-10-04 2024-10-04         31.0      31.0      31.0 
##  7 0057 FB…            1 2024-10-04 2024-10-04        136.      136.      136.  
##  8 0061 PW…            1 2024-10-04 2024-10-04         24.5      24.5      24.5 
##  9 006201 …            1 2024-10-04 2024-10-04         22.7      22.7      22.7 
## 10 006203 …            1 2024-10-04 2024-10-04         83.2      83.2      83.2 
## 11 006204 …            1 2024-10-04 2024-10-04        109.      109.      109.  
## 12 006205 …            1 2024-10-04 2024-10-04         38.1      38.1      38.1 
## 13 006206 …            1 2024-10-04 2024-10-04         37.0      37.0      37.0 
## 14 006207 …            1 2024-10-04 2024-10-04         29        29        29   
## 15 006208 …            1 2024-10-04 2024-10-04        101.      101.      101.  
## 16 00625K …            1 2024-10-04 2024-10-04          7.62      7.62      7.62
## 17 00631L …            1 2024-10-04 2024-10-04         10.4      10.4      10.4 
## 18 00632R …            1 2024-10-04 2024-10-04         23.9      23.9      23.9 
## 19 00633L …            1 2024-10-04 2024-10-04         53.5      53.5      53.5 
## 20 00634R …            1 2024-10-04 2024-10-04          3.63      3.63      3.63

5. Descriptive Statistics

summary(
  stock_data[, c("Open", "High", "Low", "Close")]
)
##       Open               High               Low               Close         
##  Min.   :    1.46   Min.   :    1.46   Min.   :    1.46   Min.   :    1.46  
##  1st Qu.:   24.89   1st Qu.:   25.15   1st Qu.:   24.55   1st Qu.:   24.85  
##  Median :   43.82   Median :   44.30   Median :   42.98   Median :   43.42  
##  Mean   :   85.64   Mean   :   86.63   Mean   :   84.24   Mean   :   85.18  
##  3rd Qu.:   99.42   3rd Qu.:   99.61   3rd Qu.:   98.10   3rd Qu.:   98.74  
##  Max.   :10121.60   Max.   :10313.70   Max.   :10254.50   Max.   :10293.10

6. Daily Closing Price Visualization

# Select the first five companies
selected_companies <- unique(stock_data$CO_ID)[1:5]

sample_data <- stock_data %>%
  filter(
    CO_ID %in% selected_companies
  )

ggplot(
  sample_data,
  aes(
    x = Date,
    y = Close,
    color = as.factor(CO_ID)
  )
) +
  geom_line(linewidth = 0.7) +
  labs(
    title = "Daily Closing Prices of Selected Taiwan Stocks",
    x = "Date",
    y = "Closing Price",
    color = "Stock"
  ) +
  theme_minimal()

7. Daily Returns

stock_return <- stock_data %>%
  arrange(CO_ID, Date) %>%
  group_by(CO_ID) %>%
  mutate(
    Daily_Return = Close / lag(Close) - 1
  ) %>%
  ungroup()

head(stock_return)
## # A tibble: 6 × 7
##   CO_ID                    Date        Open  High   Low Close Daily_Return
##   <chr>                    <date>     <dbl> <dbl> <dbl> <dbl>        <dbl>
## 1 0050 Yuanta Taiwan Top50 2024-10-04  44.2  44.5  43.9  44.1           NA
## 2 0051 TMT                 2024-10-04  76.4  76.4  75.0  75.3           NA
## 3 0052 FB Technology       2024-10-04  24.6  24.7  24.4  24.5           NA
## 4 0053 PTE                 2024-10-04  95.4  95.4  94.5  94.5           NA
## 5 0055 PTF                 2024-10-04  26.8  26.9  26.7  26.7           NA
## 6 0056 PTD                 2024-10-04  31.1  31.2  30.9  31.0           NA

Return Summary

return_summary <- stock_return %>%
  group_by(CO_ID) %>%
  summarise(
    Average_Return = mean(
      Daily_Return,
      na.rm = TRUE
    ),
    Volatility = sd(
      Daily_Return,
      na.rm = TRUE
    ),
    .groups = "drop"
  )

head(return_summary, 20)
## # A tibble: 20 × 3
##    CO_ID                       Average_Return Volatility
##    <chr>                                <dbl>      <dbl>
##  1 0050 Yuanta Taiwan Top50               NaN         NA
##  2 0051 TMT                               NaN         NA
##  3 0052 FB Technology                     NaN         NA
##  4 0053 PTE                               NaN         NA
##  5 0055 PTF                               NaN         NA
##  6 0056 PTD                               NaN         NA
##  7 0057 FB MSCI Taiwan                    NaN         NA
##  8 0061 PWC300                            NaN         NA
##  9 006201 Yuanta TW TPEx 50               NaN         NA
## 10 006203 Yuanta MSCI TW ETF              NaN         NA
## 11 006204 SinoPac TAIEX ETF               NaN         NA
## 12 006205 FB SSE180                       NaN         NA
## 13 006206 YT SSE50                        NaN         NA
## 14 006207 Fuh Hwa CSI 300                 NaN         NA
## 15 006208 FB TW50                         NaN         NA
## 16 00625K FB SSE180+R                     NaN         NA
## 17 00631L T50Bull2X                       NaN         NA
## 18 00632R T50Bear1X                       NaN         NA
## 19 00633L Fubon SSE180 L2X ETF            NaN         NA
## 20 00634R FubonSSE180 INVR.ETF            NaN         NA

8. Conclusion

This report analyzes daily stock prices of companies listed in the Taiwan stock market.

The dataset contains daily Open, High, Low, and Close prices for many listed companies. The data were imported, cleaned, and converted into appropriate formats in R.

Descriptive statistics were calculated for the stock prices, including the minimum, maximum, mean, and other summary measures. Daily closing price trends were also visualized for selected stocks.

In addition, daily returns and volatility were calculated to provide further information about stock price movements and the risk associated with individual stocks.

Overall, the analysis provides an overview of Taiwan stock market daily price movements and demonstrates how R can be used to clean, summarize, analyze, and visualize financial market data.