Thanks, yep using the script from the latest distro. Going around and around trying to match the format string to the CSV.

script and one line of my csv. probably I am missing something very simple and fundamental!

It parses 340648 SPX records. Then the error is: Error 013 invalid parameter 0

Date Expiry Under Strike Bid Ask OI Imp. vol fwd price Type
05/28/2019 12/20/2019 SPX C 100 2672.20 2675.80 533 1.696005 2810.23 E

Code

int Year = 2019;
string Ticker = "SPX"; // File name: SPX_2019.csv
string Format = "%m/%d/%Y,i,s,s,f,f,f,f,f,f,s"; // from the sample above

void main() 
{
// first step: parse the CSV file into a dataset
	int Records = dataParse(1,Format,strf("History\\%s_%i.csv",Ticker,Year));
	printf("\n%d %s Records parsed",Records,Ticker);
	if(!Records) return;
// second step: convert the raw data to the final CONTRACT format
	int i;
	for(i=0; i<Records; i++) {
		CONTRACT* O = dataAppendRow(2,9);
		O->time = dataVar(1,i,0);
		string PC = dataStr(1,i,3);
		string EA = dataStr(1,i,4);
		O->Type = ifelse(*PC == 'P',PUT,CALL) + ifelse(*EA == 'E',EUROPEAN,0);
		int Expiry = dataInt(1,i,1); 
		O->Expiry = 10000*(Expiry%10000) + Expiry/10000; // MMDDYYYY -> YYYYMMDD
		O->fStrike = dataVar(1,i,2);
		O->fAsk = dataVar(1,i,5);
		O->fBid = dataVar(1,i,6);
		O->fVol = dataVar(1,i,7);
		O->fVal = dataVar(1,i,8); // open interest
                O->fUnl = dataVar(1,i,9);
		if(!progress(100*i/Records,0)) break; // show a progress bar
	}
	dataSort(2);
	dataSave(2,strf("History\\%s_%1.t8",Ticker,Year));
}

Last edited by interzonez; 12/21/19 05:55.