2
$\begingroup$

I'm having a little trouble early on using the convert() function in RTAQ to convert .csv taq intraday trade data into an .RData format. I type this:

> from <- "2012-02-01"
> to <- "2012-02-29"

> ###convert data to .RData format
> convert(from, to, datasource = "/home/taylor/Desktop/trading", 
datadestination = "/home/taylor/Desktop/trading", trades = T, quotes = F, 
ticker = "AAPL", dir = F, extention = "csv", header = F)

and get this error:

[1] "no trades for stock AAPL"
There were 42 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In file(file, "rt") :
cannot open file '/home/taylor/Desktop/trading/2012-02-01 
AAPL_trades.csv':     
No such file or directory

or i type this:

> convert(from, to, datasource = "/home/taylor/Desktop/trading/aapl 
2012-02.csv", datadestination = "/home/taylor/Desktop/trading", trades = T,
quotes = F, ticker = "AAPL", dir = F, extention = "csv", header = F)

and get this error

Error in setwd(datasource) : cannot change working directory

My hunch is that the raw data isn't in the anticipated format. In the documentation for RTAQ it mentions that the raw trade data has 9 columns (with no sample picture), however my data has 15 columns. An example row:

20120201,40000,793,AAPL,P,T...,100,457,,00,1,N,,AAPL,

The columns are Date, Time (HHMMSS), MS, Symbol, Exchange, Sale Condition, Trade Volume, Trade Price, Trade Stop Stock Indicator, Trade Correction Indicator, Trade Sequence Number, Source of Trade, Trade Reporting Facility, Symbol Root, and Symbol Suffix, respectively. If I have to change the format of the raw data, which columns do i drop/combine?

Thanks in advance for any help.

$\endgroup$
1
$\begingroup$

RTAQ::convert expects each day's data to be in its own folder, in a file named "[ticker]_trades.csv". Your file, aapl2012-02.csv, isn't in its own folder and isn't named appropriately.

You need to create a "2012-02-01" directory, put your file in it, and rename it to "AAPL_trades.csv".

I don't think your file is in the correct format anyway. Your example row shows numerical and character columns, which can't be combined in an xts object. xts/zoo objects can only contain one data type because they're a matrix underneath.

It would probably be easier to read your data with read.csv. Then create an xts object using the numerical data you want, and include the categorical data by creating a numerical mapping to the categorical data (e.g. Y/N -> 1/0). Then save that as a .RData file.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.