convert: Convert trade or quote data into xts object saved in the...

Description Usage Arguments Value Author(s) Examples

Description

Function converts both trade and quote data stored as "txt" or "csv" and structured as illustrated in the pdf documentation into xts-objects and stores them in the "RData" format. Subsequently, the data can be loaded into the R console by TAQLoad.

Usage

1
2
3
4
convert(from,to,datasource,datadestination,trades=TRUE,quotes=TRUE,
        ticker,dir=FALSE,extention="txt",header=FALSE,
        tradecolnames=NULL,quotecolnames=NULL,
        format="%Y%m%d %H:%M:%S",onefile=FALSE)        

Arguments

from

first date to convert e.g. "2008-01-30".

to

last date to convert e.g. "2008-01-31".

datasource

folder in which the original data is stored.

datadestination

folder in which the converted data should be stored.

trades

boolean, determines whether trades are converted.

quotes

boolean, determines whether quotes are converted.

ticker

vector with tickers to be converted.

dir

boolean, if TRUE the datadestination folder and subfolders will be created automatically.

extention

character, indicating the data format of the original data. Can be either "txt" or "csv". In case your data comes from "www.tickdata.com", set extention="tickdatacom".

header

boolean, indicating whether each data file contains a header.

tradecolnames

vector containing column names of your trade data. By default, the standard NYSE data format is taken, see pdf documentation for more details.

quotecolnames

vector containing column names of your quote data. By default, the standard NYSE data format is taken, see pdf documentation for more details.

format

character, indicates in what format TIME and DATE are recorded in the original data. By default, "%Y%M%D %H:%M:%S" is taken, which means the date is denoted by e.g. "20080130" and the time by e.g. "09:30:00".

onefile

indicates the way the source data is stored. By default FALSE, which means the function expects that the source data is saved in a folder sturcture with a folder for each date (see vignette for more info). In case the data for multiple days is stored in one file, set onefile=TRUE. The naming convention for files is, e.g. for ticker="AAPL", "AAPL_trades.extention" and "AAPL_quotes.extension" for trades and quotes respectively.

Value

For each day an xts object is saved into the folder of that date, containing the converted data. This procedure is performed for each stock in "ticker". More information can be found in the pdf documentation.

Author(s)

Jonathan Cornelissen and Kris Boudt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#In order for these examples to work, the folder datasource 
#should contain two folders named 2008-01-02 and 2008-01-03.
#These folder contain the files with the trade data,
#which are named "AAPL_trades.txt" or "AA_trades.txt".

from="2008-01-02";
to = "2008-01-03";
## Not run: datasource=datadestination="C:\data"

### txt files from NYSE:

convert(from,to,datasource,datadestination,trades=TRUE,
          quotes=FALSE,ticker=c("AA","AAPL"),dir=FALSE,extention="txt",
          header=FALSE,tradecolnames=NULL,quotecolnames=NULL,
          format="%Y%m%d %H:%M:%S");

#Now, the folder datadestination will contain two folders
#named 2008-01-02 and 2008-01-03 containing 
#the files AAPL_trades.RData and AAPL_trades.RData containing the trades.
#The data can now be loaded with the TAQLoad function.

########## Csv file from WRDS
#Suppose the datasource folder contains one csv file from WRDS 
#with data on IBM for multiple days.
#The file should be named "IBM_trades.csv" and can be easily converted into xts 
#and then saved in RData format by:

 convert(from=from, to=to, datasource=datasource, datadestination=datadestination, trades = T, 
                       quotes = T, ticker="IBM", dir = FALSE, extention = "csv", header = TRUE, 
                       tradecolnames = NULL, quotecolnames = NULL, format = format, onefile = TRUE )  

####### ASC file from www.tickdata.com
#Suppose the datasource folder contains asc files for trades and quotes 
#from "www.tickdata.com" for GLP. 
#The files "GLP_quotes.asc" and "GLP_trades.asc" should be saved in datasource folder.

 convert(from=from, to=to, datasource=datasource, datadestination=datadestination, trades = T, 
            quotes = T, ticker="GLP", dir = TRUE, extention = "tickdatacom", header = TRUE, 
            tradecolnames = NULL, quotecolnames = NULL, format = format, onefile = TRUE );  

## End(Not run)

R-Finance/RTAQ documentation built on May 8, 2019, 4:48 a.m.