Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 715 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Error with CSVtoOptions #483789
07/26/21 10:01
07/26/21 10:01
Joined: Sep 2020
Posts: 7
3
3dvg Offline OP
Newbie
3dvg  Offline OP
Newbie
3

Joined: Sep 2020
Posts: 7
Hi, I'm trying to convert a sample option chain (attached) to .t8 format using the CSVtoOptions script.

I created a new script from this one and simply added 2 lines to select the .csv from the Open File Window.

The error I'm getting is: Error 013: Invalid expression

The excel has the same format outlined in the comments at the beginning of the script. It's an option chain of SPY from 2017

Here's the code:

Code
// Example script for converting CSV 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, unadj 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"

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

void main() 
{
	string InName = file_select("History","CSV file\0*.csv\0\0");
	if(!InName) return quit("No file"); 
// first step: parse the CSV file into a dataset
	int Records = dataParse(1,Format,InName);
	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);
		print("\n -- %d", O);
		if(!progress(100*i/Records,0)) break; // show a progress bar
	}
	dataSort(2);
	dataSave(2,strf("History\\%s_%1.t8",Ticker,Year));
}

Attached Files
SPY_2017.csv (134 downloads)
Re: Error with CSVtoOptions [Re: 3dvg] #483790
07/26/21 10:42
07/26/21 10:42
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
That's indeed an invalid expression. Replace %1 with %i. Or even better, get the latest Zorro version where the expression is ok.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1