Problem with Date in .t8 files

Posted By: pieran

Problem with Date in .t8 files - 01/22/21 18:14

Hello,

I am new in this forum and I hope there is someone who can help. This might be a silly question but I cannot figure out, how to create a vaild .t8 file from a csv file.
Did a copy of CSVtoOptions.c and adjusted it to the csv format.

The csv format is:

optionkey,Symbol,ExpirationDate,AskPrice,AskSize,BidPrice,BidSize,LastPrice,PutCall,StrikePrice,Volume,openinterest,UnderlyingPrice,DataDate
SPY2019-01-02c100.002019-01-02,SPY,2019-01-02,151.45,10,149.02,310,0.00,call,100.00,0,0,250.24,2019-01-02
SPY2019-01-02c105.002019-01-02,SPY,2019-01-02,146.45,10,143.58,2,0.00,call,105.00,0,0,250.24,2019-01-02

and this is the code I am using


int Year = 2019;
string Ticker = "SPY";
string Format = ",,%Y-%m-%d,f,,f,,f,s,f,f,f,f,%Y-%m-%d";

void main()
{
int Records = dataParse(1,Format,strf("History\\%i_%s.csv",Year,Ticker));
printf("\n%d %s Records parsed",Records,Ticker);
if(!Records) return;

int i;
for(i=0; i<Records; i++) {
CONTRACT* O = dataAppendRow(2,9);
O->time = dataVar(1,i,9);
string PC = dataStr(1,i,4);
string EA = "A";
O->Type = ifelse(*PC == 'put',PUT,CALL) + ifelse(*EA == 'E',EUROPEAN,0);
O->Expiry = dataVar(1,i,0);
O->fStrike = dataVar(1,i,5);
O->fAsk = dataVar(1,i,1);
O->fBid = dataVar(1,i,2);
O->fVol = dataVar(1,i,6);
O->fVal = dataVar(1,i,7); // open interest
O->fUnl = dataVar(1,i,8);
if(!progress(100*i/Records,0)) break; // show a progress bar
//watch(O->time);
}

dataSort(2);
dataSave(2,strf("History\\%s_%i.t8",Ticker,Year));




It works fine except for the date fields "Date" and "Expiry".

[Linked Image]


Could anybody please suggest what I am doing wrong?
Thank you!
Posted By: pieran

Re: Problem with Date in .t8 files - 01/23/21 14:14

I reformatted the input file to match the date format of the original CSVtoOptions.c
Then I made sure that the Date was in Column 0. Than it worked. Kind of strange but luckily it worked :-)
Posted By: strimp099

Re: Problem with Date in .t8 files - 01/26/21 07:21

Have a look at the trading.h file and find the CONTRACT struct which defines what each field in the .t8 file needs to look like. Quote datetime field DataDate in your file is of DATE format so your '%Y-%m-%d' string format will work. However the Expiry is a type Long of format YYYYMMDD so you need to use an "%i" string format. Also note that only those fields in the struct are necessary for the parser as those are the only ones that end up in your .t8 file.
© 2024 lite-C Forums