rm(list=ls())
library(tidyquant)
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
## == Need to Learn tidyquant? ====================================================
## Business Science offers a 1-hour course - Learning Lab #9: Performance Analysis & Portfolio Optimization with tidyquant!
## </> Learn more at: https://university.business-science.io/p/learning-labs-pro </>
library(timetk)
##
## Attaching package: 'timetk'
## The following objects are masked from 'package:tidyquant':
##
## summarise_by_time, summarize_by_time
library(quantmod)
#因為跑不出來,所以只好這樣子了,我也不知道為甚麼讀不進資料,導至下方的一律無發操作。
# Q1<- read.tsv("tej_day_price_2017_2018.txt")
#Q2<- Q1[“證券代碼”="id", “簡稱”="name", “年月日”="date", “收盤價(元)”="price", “市值(百萬元)”="cap"]
#id<- as.character(dbl)
#date<- as.date(dbl)
#Q3<- spread(Q2, id, date, price)
#Q4_1<- tk_xts(Q3)
#Q4<- Return.calculate(Q4_1 , method="Daily rate of return")
#head(Q4,5)
#Q5_1<- to.period(Q2,period = 'months')
#Q5<- Return.calculate(Q5_1 , merhod="Monthly rate of return")
#head(Q5,10)
#Q6_1<- filter(Q2,head(price,20))
#Q6_2<- arrange(Q6_1)
#Q6<- slice(Q6_2,20)
#Q7<- hist(xlab = "id",
# ylab = "weight",
# main = "Capitalization weight 20 largest firms in 2017")
#Q8_1<- tk_tbl(Q4)
#Q8<- gather(Q8_1)
#Q9<- filter(Q6,head(price,20))