TS.getFactor.db: TS.getFactor.db

Description Usage Arguments Value Note Author(s) Examples

Description

get factors throug a SQL qurey from a database

Usage

1
TS.getFactor.db(TS, subfun, ...)

Arguments

TS

a TS object

subfun

a function object,which get the factors of a subset of TS from the database.

...

other parametres of subfun

Value

A TSF object

Note

Note that the subfun must contain subset of TS as the first argument. and the subset must be a subset of TS on a certain "date".

Author(s)

Ruifei.Yin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
TS <- getTS(getRebDates(as.Date('2011-03-17'),as.Date('2012-04-17')),'EI000300')
subfun <- function(subTS,con_type){ # con_type indicate the consensus type
  dt <- subTS[1,"date"]
  qr_char <- paste("SELECT stock_code,con_date,con_type,c80
      FROM CON_FORECAST_STK a
        where a.con_date=",QT(dt),"and year(a.con_date)=a.rpt_date and a.stock_type=1 and con_type=",con_type,"and a.rpt_type=4")
  tmpdat <- queryAndClose.odbc(db.cs(),qr_char,as.is=1)
  subTS$stock_code <- stockID2tradeCode(subTS$stockID)
  re <- merge(subTS,tmpdat,by="stock_code",all.x=TRUE)
  re <- re[,c(names(TS),"c80")]
  re <- renameCol(re,"c80","factorscore")
  return(re)
}
 TSF <- TS.getFactor.db(TS,subfun,con_type=1)

QuantAndrew/QFactorGet documentation built on May 14, 2019, 7:36 a.m.