getSectorID: getSectorID

Description Usage Arguments Value Note Author(s) Examples

Description

get the sectorID of the stocks on specific dates.

Usage

1
2
3
4
5
6
7
getSectorID(TS, stockID, endT = Sys.Date(),
  sectorAttr = defaultSectorAttr(), ret = c("ID", "name"), drop = FALSE,
  fillNA = FALSE, ungroup = NULL, datasrc = "memory")

gf_sector(TS, sectorAttr)

cast_sector(TSS)

Arguments

TS

a TS object

stockID

a vector of stockID

endT

a vector of Date

sectorAttr

a list(See more in defaultSectorAttr) or NULL,or "existing".

ret

a charactor string,could be one of "ID" or "name",indicating sectorID or sectorName returned.

drop

a logical. Shoud the TS be exculded in the result?

TSS

a dataframe, with cols: date,stockID,and some dummy variables of sectors.

Value

a data.frame,with the same cols of TS,added by "sector". Or a vector if drop is TRUE. You can get more sector infomation by CT_industryList

Note

param TS and combination of stockID and endT should at least have one and only have one. The combination of vector stockID and endT could be different length, which abide by the recycling rule.

Author(s)

Ruifei.Yin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# - with TS
TS <- getTS(getRebDates(as.Date('2007-03-17'),as.Date('2012-05-20')),'EI000300')
getSectorID(TS)
# - one stock, multiple dates
getSectorID(stockID="EQ000001", endT=as.Date(c("2010-01-01","2012-01-01","2013-01-01")))
# - one date, multiple stocks
getSectorID(stockID=c("EQ000001","EQ000002","EQ000004"), endT=as.Date("2010-01-01"))
# - get 'ZHONGXIN' sector
getSectorID(stockID=c("EQ000001","EQ000002","EQ000004"), endT=as.Date("2010-01-01"), sectorAttr=list(3,1), ret="name")
getSectorID(stockID=c("EQ000001","EQ000002","EQ000004"), endT=as.Date("2010-01-01"), sectorAttr=list(3,2), ret="name")
# -- combined sectorAttr
test <- getSectorID(TS, sectorAttr= defaultSectorAttr("fct",fct_level = 5))
test <- getSectorID(TS, sectorAttr= defaultSectorAttr("ind_fct",ind_std = 33,ind_level = 1,fct_level = 5))
test <- getSectorID(TS, sectorAttr= defaultSectorAttr("ind_fct",ind_std = c(336,33),ind_level = 1,fct_level = 5))
test <- getSectorID(TS, sectorAttr= defaultSectorAttr("fct",fct_std = buildFactorLists_lcfs(c("F000001","F000006"),factorRefine = refinePar_default("none",NULL)),fct_level = 5))
factorList1 <- buildFactorList(factorFun = "gf_cap",factorRefine=refinePar_default("scale",NULL))
test2 <- getSectorID(TS, sectorAttr= list(std=list(factorList1,33),level=list(5,1)))
# - speed compares (20 VS. 200)
microbenchmark::microbenchmark(re <- getSectorID(TS,datasrc="memory"),re1 <- getSectorID(TS,datasrc = "local"),times = 10)

QuantAndrew/QDataGet documentation built on May 14, 2019, 7:35 a.m.