3 registered members (7th_zorro, Aku_Aku, 1 invisible),
579
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: iVolatility options csv file to .t8 Zorro file
[Re: AndrewAMD]
#473106
06/13/18 23:05
06/13/18 23:05
|
Joined: May 2018
Posts: 134
SBGuy
OP
Member
|
OP
Member
Joined: May 2018
Posts: 134
|
Well, I have been going to my friendly manual before posting for help. However, it is not being cooperative, or I'm still very rusty with coding.
Anyhow, I successfully made a T8 file, verified with History.c, but only after manually changing the format of the Expiration Date field in the CSV file using Excel. Trying to be less of a hacker, I would like to massage that field in my Zorro script.
The problem is that the Expiration Date string appears as 3/24/2017, where the month and day is sometimes 1 or 2 chars. I need to transpose this into an 8 digit long - YYYYMMDD, which is what the t8 file format requires.
I'm been hacking with strdate, wdatef, ymd, strf, etc. all day and can't seem to get to YYYYMMDD.
How would you do this Master Andrew? I'm sure you probably have a 1 liner for this problem :-) Many thanks!
Last edited by SBGuy; 06/13/18 23:06.
|
|
|
Re: iVolatility options csv file to .t8 Zorro file
[Re: SBGuy]
#478502
10/30/19 22:06
10/30/19 22:06
|
Joined: May 2018
Posts: 134
SBGuy
OP
Member
|
OP
Member
Joined: May 2018
Posts: 134
|
Sorry about the delay in response. Zorro posted it to their manual a while ago. It's at the bottom of the contract manual page. https://zorro-project.com/manual/en/contract.htm
// 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");
}
|
|
|
Re: iVolatility options csv file to .t8 Zorro file
[Re: SBGuy]
#478787
12/18/19 09:24
12/18/19 09:24
|
Joined: Dec 2019
Posts: 6
interzonez
Newbie
|
Newbie
Joined: Dec 2019
Posts: 6
|
How to run this script on my CSV file of historical SPX options data? Where to point to my CSV file or does it run in the same directory somehow? Thank you. I see FILENAME - assuming I can swap out here for the CSV file?
Last edited by interzonez; 12/18/19 09:28.
|
|
|
Re: iVolatility options csv file to .t8 Zorro file
[Re: SBGuy]
#478797
12/21/19 03:11
12/21/19 03:11
|
Joined: Dec 2019
Posts: 6
interzonez
Newbie
|
Newbie
Joined: Dec 2019
Posts: 6
|
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
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.
|
|
|
|