Use this to convert t8 options data to CSV

Posted By: Kaga

Use this to convert t8 options data to CSV - 11/05/20 21:54

Select "CSVfromHistory" in Zorro and click "Edit". Then do the following steps

1) Comment out the `#define MAX_RECORDS 10000` line, since options data has many more lines than that.
2) Find the line with the `string Source` definition and replace it by
Code
string Source = file_select("History","T1,T6,T8\0*.t1;*.t6;*.t8\0\0");

3) Just before the line `printf("\nDone!");` insert the following code
Code
else if(strstr(Source,".t8")) {
		CONTRACT *Ticks = file_content(Source);
		int Records = file_length(Source)/sizeof(CONTRACT);
		printf("\n%d records..",Records);
#ifdef MAX_RECORDS
		Records = min(Records,MAX_RECORDS);
#endif
#ifdef ASCENDING
		int nTicks = Records;
		while(--nTicks) 
#else
		int nTicks = -1;
		while(++nTicks < Records) 
#endif
		{
			CONTRACT *t = Ticks+nTicks;
			string otype,otype2;
			switch(t->Type){  
				case PUT:    
					otype="P";otype2="A";   
					break;  
				case CALL:    
					otype="C";otype2="A";   
					break;  
				case PUT+EUROPEAN:    
					otype="P";otype2="E";
					break;  
				case CALL+EUROPEAN:    
					otype="C";otype2="E";    
					break;
				default:    
					printf("None of them! ");
			}
//format: date, put/call, american/european, expiry date, strike, ask, bid, volume, open interest, underlying closing price
			file_append(Target,strf("%s,%s,%s,%d,%.2f,%.2f,%.2f,%d,%d,%.2f\n",
				strdate("%Y-%m-%d",t->time),
				otype,otype2,(int)t->Expiry,(var)t->fStrike,(var)t->fAsk,(var)t->fBid,(int)t->fVol,(int)t->fVal,(var)t->fUnl));
			if(!point(nTicks)) return;
		}
	}

Congratulations, now your CSVfromHistory script can handle t8 options data files!
But beware, the conversion takes some time. For example, the most recent SPY.t8 took about 30 min to convert.
Posted By: kalmar

Re: Use this to convert t8 options data to CSV - 11/05/20 23:29

Thank you, Kaga!
Posted By: strimp099

Re: Use this to convert t8 options data to CSV - 02/18/21 13:00

contractPrint () too
© 2024 lite-C Forums