// Example script for converting EOD options data to .t8:
// Format: underlying symbol, exchange, date MMDDYYYY, adj close, option symbol, expiry MMDDYYYY, strike, Call/Put, American/European, ask, bid, volume, open interest, close
// Sample: "TLT,NYSEArca,04/10/2015,129.62,TLT 150410C00112500,04/10/2015,112.5,C,A,17.3,16.2,0,0,129.62"
string Format = ",,%m/%d/%Y,,,i,f,s,s,f,f,f,f,f";
void main()
{
// first step: parse the CSV file into a dataset
int Records = dataParse(1,Format,FILENAME);
printf("\n%d Records parsed",Records);
// second step: convert the raw data to the final CONTRACT format
for(i=0; i<Records; i++,c++)
{
CONTRACT* C = dataAppendRow(2,9);
C->time = dataVar(1,i,0);
string PC = dataStr(1,i,3);
string EA = dataStr(1,i,4);
C->Type = ifelse(*PC == 'P',PUT,CALL) + ifelse(*EA == 'E',EUROPEAN,0);
int Expiry = dataInt(1,i,1);
C->Expiry = 10000*(Expiry%10000) + Expiry/10000; // MMDDYYYY -> YYYYMMDD
C->fStrike = dataVar(1,i,2);
C->fAsk = dataVar(1,i,5);
C->fBid = dataVar(1,i,6);
C->fVol = dataVar(1,i,7);
C->fVal = dataVar(1,i,8); // open interest
C->fUnl = dataVar(1,i,9);
if(!progress(100*i/Records,0)) break; // show a progress bar
}
dataSort(2);
dataSave(2,"History\\MyOptions.t8");
}