getPeriodrtn: getPeriodrtn

Description Usage Arguments Value Note Author(s) Examples

Description

get the period return of the stocks

Usage

1
2
3
4
5
6
7
getPeriodrtn(SP, stockID, begT, endT, tradeType = c("close", "nextavg",
  "nextopen"), drop = FALSE, datasrc = defaultDataSRC())

getPeriodrtn_EI(SP, stockID, begT, endT, drop = FALSE,
  datasrc = defaultDataSRC())

getPeriodrtn_FU(SP, stockID, begT, endT, drop = FALSE, datasrc = "ts")

Arguments

SP

a SP object ('stock*period'): a data frame with cols: "stockID","begT","endT"(with class of Date).

stockID

a vector of stockID

begT

a vector of Date

endT

a vector of Date

tradeType

a character string("close","nextavg","nextopen"),indicating the trading type.

drop

a logical. If the SP shoud be exculded in the result?

Value

a data frame, with cols of SP and "periodrtn". Or a vector if drop is TRUE.

Note

param SP and combination of stockID, begT and endT should at least have one and only have one. The combination of vector stockID, begT 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
# -- with SP
getPeriodrtn(data.frame(stockID="EQ601313",begT=as.Date("2012-01-20"),endT=as.Date("2012-09-27")))
getPeriodrtn(data.frame(stockID="EQ601313",begT=as.Date("2012-01-20"),endT=as.Date("2012-09-27")),tradeType="nextopen")
TS <- getTS(getRebDates(as.Date('2007-03-17'),as.Date('2012-05-20')),'EI000300')
TS <- renameCol(TS,"date","begT")
SP <- data.frame(TS,endT=trday.offset(TS$begT,months(1)))
system.time(re <- getPeriodrtn(SP,datasrc="ts"))  # 8.40
system.time(re1 <- getPeriodrtn(SP,datasrc="local"))  # 1.94
system.time(re <- getPeriodrtn(SP,tradeType = "nextavg",datasrc="ts")) # 10.80
system.time(re1 <- getPeriodrtn(SP,tradeType = "nextavg",datasrc="local")) # 16.7

#-- with combination of vector stockID, begT and endT
getPeriodrtn(stockID="EQ000001",begT=as.Date("2012-01-01"), endT=as.Date("2012-01-01")+c(10,20,30))
getPeriodrtn(stockID=c("EQ000001","EQ000002","EQ000004"),begT=as.Date("2012-01-01"), endT=as.Date("2013-01-01"))
# -- getPeriodrtn_EI
getPeriodrtn_EI(stockID="EI000300",begT=as.Date("2012-01-01"), endT=as.Date("2012-01-01")+c(10,20,30))
# -- getPeriodrtn_FU
getPeriodrtn_FU(stockID="FUIF00",begT=as.Date("2012-01-01"), endT=as.Date("2012-01-01")+c(10,20,30))

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