Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
file_parser Class Reference

Utility class for reading CVS (comma separated values) record files. More...

Detailed Description

Utility class for reading CVS (comma separated values) record files.

Example

The following example shows how a RecordFile object can be used to read a CVS file line by line and immediately write each record into a series_base table via a TableWriter instance.

The text file read must contains records such as :

11/29/1990,22.64590639,22.72139274,22.46977156,22.54525791,5939980.838
11/30/1990,22.46977156,23.04850028,22.3942852,22.87236545,8963871.727
12/3/1990,23.04850028,23.04850028,22.74655486,22.82204121,7800416.419
12/4/1990,22.82204121,23.14914875,22.74655486,23.09882451,7242534.134

Database db(...);
(...)
TableWriter sw(db, "demo_table"); //table has 'OHLCV' schema
RecordFile rf(',', "c:/data/ibm.csv"); //opening the file, setting separator character to ','
DateTime t;
while(rf.ReadRecord())
{
if(rf.GetFieldCount() != 6) //time,o,h,l,c,v
throw tsa::exception("record should have 6 fields");
t.SetDateString(rf[0],"mm/dd/yyyy"); //first field contains date
sw << (double)rf[1]; //open
sw << (double)rf[2]; //high
sw << (double)rf[3]; //low
sw << (double)rf[4]; //close
sw << (double)rf[5]; //volume
sw.Append(t); //timestamp is given here
}