- 成分股名單及代碼 -

tw50_2017<-read.csv("2017Q4_code.csv", colClasses = c("證券代碼"="character"))
## Warning in read.table(file = file, header = header, sep = sep, quote =
## quote, : not all columns named in 'colClasses' exist
str(tw50_2017)
## 'data.frame':    50 obs. of  5 variables:
##  $ code    : int  1101 1102 1216 1301 1303 1326 1402 2002 2105 2207 ...
##  $ name    : Factor w/ 50 levels "大立光","中信金",..: 12 26 35 13 31 11 43 5 20 27 ...
##  $ share1  : Factor w/ 47 levels "0.30%","0.34%",..: 16 3 36 45 44 37 11 34 8 20 ...
##  $ industry: Factor w/ 18 levels "水泥工業","半導體業",..: 1 1 9 14 14 14 10 18 17 4 ...
##  $ share2  : Factor w/ 18 levels "0.30%","0.59%",..: 8 8 11 18 18 18 4 9 2 5 ...
options(repos = "https://cran.rstudio.com")
install.packages("readr")
## Installing package into 'C:/Users/USER/Documents/R/win-library/3.5'
## (as 'lib' is unspecified)
## package 'readr' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\USER\AppData\Local\Temp\RtmpOwZXxL\downloaded_packages
library(readr)
## Warning: package 'readr' was built under R version 3.5.3
tw50_2017<-read_csv("2017Q4_code.csv", locale = locale(encoding='big5'))
## Parsed with column specification:
## cols(
##   code = col_double(),
##   name = col_character(),
##   share1 = col_character(),
##   industry = col_character(),
##   share2 = col_character()
## )
head(tw50_2017)
## # A tibble: 6 x 5
##    code name     share1 industry share2
##   <dbl> <chr>    <chr>  <chr>    <chr> 
## 1  1101 台泥     0.79%  水泥工業 1.19% 
## 2  1102 亞泥     0.40%  水泥工業 1.19% 
## 3  1216 統一     1.92%  食品工業 1.92% 
## 4  1301 台塑     2.92%  塑膠工業 7.73% 
## 5  1303 南亞塑膠 2.67%  塑膠工業 7.73% 
## 6  1326 台化     2.14%  塑膠工業 7.73%

- 除權調整後日收盤價 -

install.packages("readr")
## Installing package into 'C:/Users/USER/Documents/R/win-library/3.5'
## (as 'lib' is unspecified)
## Warning: package 'readr' is in use and will not be installed
library(readr)
tw50__2017<-read.csv("tw50.csv")
head(tw50__2017)
##      年月日 Data.Field X1101.台泥 X1102.亞泥 X1216.統一 X1301.台塑
## 1  2016/1/4 收盤價(元)      21.21      23.82      46.88      62.40
## 2  2016/1/5 收盤價(元)      21.41      23.59      47.06      62.83
## 3  2016/1/6 收盤價(元)      21.13      23.54      47.06      62.92
## 4  2016/1/7 收盤價(元)      22.18      23.73      46.80      62.92
## 5  2016/1/8 收盤價(元)      21.90      23.59      46.10      61.54
## 6 2016/1/11 收盤價(元)      21.09      23.32      45.14      61.80
##   X1303.南亞 X1326.台化 X1402.遠東新 X2002.中鋼 X2105.正新 X2801.彰銀
## 1      48.33      58.10        22.40      15.96      45.32      12.34
## 2      48.41      58.35        22.40      15.82      45.93      12.42
## 3      48.41      58.44        22.35      15.77      46.37      12.51
## 4      48.50      58.78        22.62      15.91      46.02      12.30
## 5      47.91      58.01        22.40      15.87      45.23      12.26
## 6      47.91      58.52        22.26      15.82      45.58      12.22
##   X2823.中壽 X2880.華南金 X2881.富邦金 X2882.國泰金 X2883.開發金
## 1      19.48        11.56        37.86        36.39         6.69
## 2      19.44        11.52        36.90        35.61         6.69
## 3      19.29        11.48        35.64        34.96         6.62
## 4      18.74        11.29        34.47        34.36         6.43
## 5      18.74        11.29        34.47        34.62         6.44
## 6      18.28        11.10        33.90        33.79         6.21
##   X2884.玉山金 X2885.元大金 X2886.兆豐金 X2887.台新金 X2890.永豐金
## 1        13.66        10.63        17.67         8.53         7.26
## 2        13.80        10.45        17.59         8.45         7.22
## 3        13.84        10.41        17.29         8.53         7.20
## 4        13.55        10.00        16.83         8.33         6.97
## 5        13.40        10.05        17.04         8.26         7.03
## 6        12.75         9.69        16.91         7.84         6.80
##   X2891.中信金 X2892.第一金 X5880.合庫金 X5871.中租.KY X9904.寶成
## 1        13.12        11.88        10.67         46.13      36.64
## 2        13.08        11.92        10.67         45.78      37.12
## 3        12.92        11.84        10.67         45.78      37.47
## 4        12.72        11.76        10.52         44.15      36.90
## 5        12.80        11.76        10.52         44.32      37.56
## 6        12.48        11.64        10.36         44.15      36.90
##   X6505.台塑化 X2303.聯電 X2330.台積電 X2408.南亞科 X2454.聯發科
## 1        66.16      10.45       125.34        38.91       217.74
## 2        65.64      10.41       123.99        38.78       215.52
## 3        66.24      10.41       121.74        37.26       201.74
## 4        65.56      10.14       119.50        36.61       183.08
## 5        65.38      10.10       120.40        37.22       189.74
## 6        65.38       9.79       119.50        38.86       185.74
##   X2301.光寶科 X2357.華碩 X2382.廣達 X2395.研華 X4938.和碩 X2409.友達
## 1        25.26     220.25      42.70     171.34      59.36       7.81
## 2        26.13     219.83      42.53     170.09      60.36       7.59
## 3        26.09     221.93      41.98     174.68      56.93       7.50
## 4        26.13     225.29      41.14     171.34      55.08       7.49
## 5        25.63     232.44      42.45     169.26      56.17       7.53
## 6        24.60     231.60      42.36     170.92      54.16       7.44
##   X3008.大立光 X3481.群創 X2412.中華電 X3045.台灣大 X4904.遠傳
## 1      2079.61       8.73        85.73        84.16      57.27
## 2      2017.46       8.65        86.26        84.50      56.75
## 3      1874.04       8.60        86.17        83.73      56.49
## 4      1749.74       8.66        86.61        83.73      56.75
## 5      1888.38       8.65        86.78        83.73      57.09
## 6      1850.14       8.50        87.30        84.42      57.18
##   X2308.台達電 X2317.鴻海 X2354.鴻準 X2474.可成
## 1       133.56      78.10      59.61     245.01
## 2       133.11      78.20      58.73     238.26
## 3       132.66      78.10      56.19     225.67
## 4       132.66      77.41      56.10     203.20
## 5       130.87      77.11      55.93     198.25
## 6       129.98      74.54      53.47     199.60