|
CSV to History Multiple Files
#472630
05/08/18 23:46
05/08/18 23:46
|
Joined: Mar 2017
Posts: 65
Ger1
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2017
Posts: 65
|
Hi,
I am trying to convert multiple csv files into t6. I coded up a loop to run through each csv files and to convert it into t6, however all created t6 files contain the history of the first csv file only.
#define SPLIT // split into separate years
string Format = "+%d/%m/%Y,f3,f1,f2,f4,f6,f5";
function convert(string InName, string OutName) { int Records = dataParse(1,Format,InName); printf("n%d lines read",Records); #ifndef SPLIT if(Records) dataSave(1,OutName); #else int i, Start = 0, Year, LastYear = 0; for(i=0; i<Records; i++) { Year = atoi(strdate("%Y",dataVar(n,i,0))); if(!LastYear) LastYear = Year; if(i == Records-1) { // end of file LastYear = Year; Year = 0; } if(Year != LastYear) { string NewName = strf("%s_%4i.t6",strxc(OutName,'.',0),LastYear); printf("n%s",NewName); dataSave(1,NewName,Start,i-Start); Start = i; LastYear = Year; } } #endif }
function main() { int x = assetList("HistorySP500AssetsSP500.csv"); int i; for(i=0; i<x; i++) { string down = Assets[i]; convert(down,down); } }
I have used the csvToExport File from Zorro and added a loop.
However, as mentioned it does not properly created the t6 files. All of them contain the history of the first csv.
Could someone explain what goes wrong here?
Cheers
Last edited by Ger1; 05/09/18 00:26.
|
|
|
Re: CSV to History Multiple Files
[Re: Ger1]
#472633
05/09/18 07:40
05/09/18 07:40
|
Joined: Mar 2017
Posts: 65
Ger1
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2017
Posts: 65
|
I was finally able to solve it myself.
The issue was that I did not change the Handle.
Below the solution that works for me:
#define SPLIT // split into separate years
string Format = "+%d/%m/%Y,f3,f1,f2,f4,f6,f5";
int n;
function convert(string InName, string OutName) { int Records = dataParse(n,Format,InName); printf("n%d lines read",Records); #ifndef SPLIT if(Records) dataSave(n,OutName); #else int i, Start = 0, Year, LastYear = 0; for(i=0; i<Records; i++) { Year = atoi(strdate("%Y",dataVar(n,i,0))); if(!LastYear) LastYear = Year; if(i == Records-1) { // end of file LastYear = Year; Year = 0; } if(Year != LastYear) { string NewName = strf("%s_%4i.t6",strxc(OutName,'.',0),LastYear); printf("n%s",NewName); dataSave(n,NewName,Start,i-Start); Start = i; LastYear = Year; } } #endif }
function main() { int x = assetList("History\SP500\AssetsSP500.csv"); int i; n=1;
for(i=0; i<x; i++) { string down = Assets[i]; convert(down,down); n++; } }
|
|
|
|